libsocket  1.5
localsocket.hh
Go to the documentation of this file.
1 /*
2 ** localsocket.hh
3 ** Login : Julien Lemoine <speedblue@happycoders.org>
4 ** Started on Sun Mar 2 00:53:36 2003 Julien Lemoine
5 ** $Id: localsocket.hh,v 1.3 2004/11/14 19:37:46 speedblue Exp $
6 **
7 ** Copyright (C) 2003,2004 Julien Lemoine
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU Lesser General Public License as published by
10 ** the Free Software Foundation; either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU Lesser General Public License for more details.
17 **
18 ** You should have received a copy of the GNU Lesser General Public License
19 ** along with this program; if not, write to the Free Software
20 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 
23 #include "socket.hh"
24 
25 #ifndef LIBSOCKET_WIN
26 
27 #ifndef LOCAL_SOCKET_HH_
28 # define LOCAL_SOCKET_HH_
29 
30 namespace Network
31 {
34  class LocalSocket : public Socket
35  {
36  public:
38  Socket(LOCAL), _filename("")
39  {}
41  Socket(LOCAL, pkind), _filename("")
42  {}
43 
44  virtual ~LocalSocket()
45  {
46  close();
47  }
48 
49  public:
51  void writeto(const std::string& str,
52  const std::string& filename);
53 
56  std::string read();
58  std::string read(int timeout);
60  std::string read(std::string& filename);
63  std::string read(std::string& filename, int timeout);
66  std::string readn(unsigned int size);
69  std::string readn(int timeout, unsigned int size);
72  std::string readn(std::string& filename, unsigned int size);
76  std::string readn(std::string& filename, int timeout, unsigned int size);
77 
179  void init(const std::string& filename);
182  void close();
183 
184  protected:
190  int _bind(const std::string& filename);
194  std::string _read_line(int socket);
199  std::string _read_line(int socket, std::string& filename);
203  std::string _read_line_bin(int socket, unsigned int size);
208  std::string _read_line_bin(int socket, std::string& filename,
209  unsigned int pkg_size);
214  void _write_str(int socket, const std::string& str,
215  const std::string& filename) const;
220  void _write_str_bin(int socket, const std::string& str,
221  const std::string& filename) const;
222 
223  protected:
224  std::string _filename;
225  };
226 }
227 
228 #endif /* !LOCAL_SOCKET_HH_ */
229 #endif
This class represent an abstract socket connection (udp | tcp server | tcp client) ...
Definition: socket.hh:100
LocalSocket(PROTO_KIND pkind)
Definition: localsocket.hh:40
std::string _filename
Definition: localsocket.hh:224
Network namespace represent all networks connection.
Definition: localsocket.cc:32
void init(const std::string &filename)
Here is an example of named server server using libsocket :
Definition: localsocket.cc:34
void writeto(const std::string &str, const std::string &filename)
function used to send a msg to a specific named socket
Definition: localsocket.cc:306
std::string _read_line_bin(int socket, unsigned int size)
Get a line from socket (when used with binary protocol)
Definition: localsocket.cc:157
void _write_str(int socket, const std::string &str, const std::string &filename) const
Write a string to a socket to a particular named socket (when used with textual protocol) ...
Definition: localsocket.cc:68
void _write_str_bin(int socket, const std::string &str, const std::string &filename) const
Write a string to a socket to a particular named socket (when used with binary protocol) ...
Definition: localsocket.cc:93
std::string _read_line(int socket)
Get a line from socket (when used with textual protocol)
Definition: localsocket.cc:212
virtual ~LocalSocket()
Definition: localsocket.hh:44
This class represent a local connection (client and server)
Definition: localsocket.hh:34
std::string read()
function used by >> operator (read a string on current socket)
Definition: localsocket.cc:352
enum Network::e_pkind PROTO_KIND
int _bind(const std::string &filename)
Initialize a local socket connection (server in UDP) create a named socket with name filename...
Definition: localsocket.cc:49
std::string readn(unsigned int size)
read a string from socket
Definition: localsocket.cc:315
void close()
connect to a local socket (client)
Definition: localsocket.cc:40