Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

sock::Socket_basic Class Reference

Basic nonblocking UNIX socket support (opening/closing). More...

#include <sock.h>

List of all members.

Public Methods

 ~Socket_basic ()
 Closes the socket, if this instance did open it itself.

 Socket_basic (const Socket_basic &s)
 Socket_basic (int desc=-1)
 Construct an empty descriptor or copy a descriptor from a file decriptor. More...

void Listen (const std::string &file_name)
 Open and create a socket UNIX socket and listen to it. More...

void Connect (const std::string &file_name)
 Connect to a UNIX socket. More...

void Accept (int server_sock)
 Get a connection via accepting it form a listening socket. More...

void Close ()
 Close the socket, if this instance did open it itself.

int GetFD ()
 Get the file descriptor and make the instance empty. More...

 operator int () const
 Get the file descriptor. More...

bool IsOpen () const
 Check if the socket is connected/you are listening.


Detailed Description

Basic nonblocking UNIX socket support (opening/closing).

This class can just "open" and close a UNIX socket or a connection to a UNIX socket. It abstracts all the unix specific stuff.


Constructor & Destructor Documentation

sock::Socket_basic::Socket_basic const Socket_basic &    s
 

Warning:
The Copy constructor is not implemented.

sock::Socket_basic::Socket_basic int    desc = -1 [inline]
 

Construct an empty descriptor or copy a descriptor from a file decriptor.

Usually you construct a empty object and open a socket with the Listen(const std::string&), Connect(const std::string&) or Accept(int). But if you have for some reason an open file descriptor, you can just attach it to this class. Indeed, you can not do anything with it in this class, since you will not open anything and Close() will not close it, since you opened, neither will ~Socket_basic(). But it provides an general interfase.

Parameters:
desc  file descriptor (-1 to construct empty object, this is default)


Member Function Documentation

void sock::Socket_basic::Listen const std::string &    file_name
 

Open and create a socket UNIX socket and listen to it.

Listening means, you waiting for client connections. If a clients connects, you may create a new instance of Socket_basic and accept it with a call like client_con.Accept(server_sock). Usually you need this only, if writing a server.

Parameters:
file_name  The file name of the socket. It must not exist and will be created.

void sock::Socket_basic::Connect const std::string &    file_name
 

Connect to a UNIX socket.

This is the method to connect to a server. If the server is accepting the connection, you are ready to communicate with write() and read().

Parameters:
file_name  The file name of the socket. It must exist and a server shuold listen to it.

void sock::Socket_basic::Accept int    server_sock
 

Get a connection via accepting it form a listening socket.

Use this to get an file descriptor to a incomming connection on a listening socket server_sock. You may create such a socket with the Listen(const std::string&) command.

Parameters:
server_sock  File descriptor whith a connection waiting for accept

int sock::Socket_basic::GetFD   [inline]
 

Get the file descriptor and make the instance empty.

In some rare cases (e.g. forking), you do not want, that the destruction of the instance closes the socket. This is when you will use this method.

sock::Socket_basic::operator int   const [inline]
 

Get the file descriptor.

You need the file descriptor for all basic i/o operation, e.g. read() or write().


The documentation for this class was generated from the following file:
Generated on Sun Apr 14 17:37:03 2002 for libvtql by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002