localsocket.hh
Go to the documentation of this file.
/*
** localsocket.hh
** Login : Julien Lemoine <speedblue@happycoders.org>
** Started on Sun Mar 2 00:53:36 2003 Julien Lemoine
** $Id: localsocket.hh,v 1.3 2004/11/14 19:37:46 speedblue Exp $
**
** Copyright (C) 2003,2004 Julien Lemoine
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "socket.hh"
#ifndef LIBSOCKET_WIN
#ifndef LOCAL_SOCKET_HH_
# define LOCAL_SOCKET_HH_
namespace Network
{
class LocalSocket : public Socket
{
public:
LocalSocket() :
Socket(LOCAL), _filename("")
{}
LocalSocket(PROTO_KIND pkind) :
Socket(LOCAL, pkind), _filename("")
{}
virtual ~LocalSocket()
{
close();
}
public:
void writeto(const std::string& str,
const std::string& filename);
std::string read();
std::string read(int timeout);
std::string read(std::string& filename);
std::string read(std::string& filename, int timeout);
std::string readn(unsigned int size);
std::string readn(int timeout, unsigned int size);
std::string readn(std::string& filename, unsigned int size);
std::string readn(std::string& filename, int timeout, unsigned int size);
void init(const std::string& filename);
void close();
protected:
int _bind(const std::string& filename);
std::string _read_line(int socket);
std::string _read_line(int socket, std::string& filename);
std::string _read_line_bin(int socket, unsigned int size);
std::string _read_line_bin(int socket, std::string& filename,
unsigned int pkg_size);
void _write_str(int socket, const std::string& str,
const std::string& filename) const;
void _write_str_bin(int socket, const std::string& str,
const std::string& filename) const;
protected:
std::string _filename;
};
}
#endif /* !LOCAL_SOCKET_HH_ */
#endif
Network::LOCAL
@ LOCAL
Definition: socket.hh:82
Network::LocalSocket::_read_line_bin
std::string _read_line_bin(int socket, unsigned int size)
Get a line from socket (when used with binary protocol)
Definition: localsocket.cc:157
socket.hh
Network::LocalSocket
This class represent a local connection (client and server)
Definition: localsocket.hh:34
Network
Network namespace represent all networks connection.
Definition: localsocket.cc:32
Network::LocalSocket::_filename
std::string _filename
Definition: localsocket.hh:224
Network::LocalSocket::_read_line
std::string _read_line(int socket)
Get a line from socket (when used with textual protocol)
Definition: localsocket.cc:212
Network::LocalSocket::writeto
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
Network::LocalSocket::init
void init(const std::string &filename)
Here is an example of named server server using libsocket :
Definition: localsocket.cc:34
Network::PROTO_KIND
enum Network::e_pkind PROTO_KIND
Network::LocalSocket::_write_str
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
Network::LocalSocket::read
std::string read()
function used by >> operator (read a string on current socket)
Definition: localsocket.cc:352
Network::LocalSocket::close
void close()
connect to a local socket (client)
Definition: localsocket.cc:40
Network::Socket
This class represent an abstract socket connection (udp | tcp server | tcp client)
Definition: socket.hh:100
Network::LocalSocket::LocalSocket
LocalSocket()
Definition: localsocket.hh:37
Network::LocalSocket::readn
std::string readn(unsigned int size)
read a string from socket
Definition: localsocket.cc:315
Network::LocalSocket::~LocalSocket
virtual ~LocalSocket()
Definition: localsocket.hh:44
Network::LocalSocket::LocalSocket
LocalSocket(PROTO_KIND pkind)
Definition: localsocket.hh:40
Network::LocalSocket::_write_str_bin
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
Network::LocalSocket::_bind
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