Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes

Socket Class Reference

Represents an end point of a TCP/IP connection. More...

List of all members.

Public Member Functions

 Socket (socket_t *)
 Socket (const char *hostAddr, int port)
virtual ~Socket ()
int readdata (void *buf, int bufsz)
 returns nrbytes read
bool writedata (void const *buf, int nrbytes)
bool read (BufferString &)
bool read (IOPar &)
bool read (SeparString &)
bool read (int &)
bool read (bool &)
bool read (BufferStringSet &)
bool write (const char *)
bool write (const BufferStringSet &)
bool write (const BufferString &)
bool write (const IOPar &)
bool write (const SeparString &)
bool write (int)
bool write (bool)
bool readtag (char &)
bool readtag (char &, BufferString &)
bool readtag (char &, SeparString &)
bool readtag (char &, bool &)
bool readtag (char &, int &)
bool readtag2 (char &, int &, int &)
bool writetag (char)
bool writetag (char, const char *)
bool writetag (char, const BufferString &)
bool writetag (char, const SeparString &)
bool writetag (char, const IOPar &)
bool writetag (char, int)
bool writetag (char, int, int)
bool writetag (char, bool)
bool readtags (char &, char &)
bool readtags (char &, char &, BufferString &)
bool readtags (char &, char &, bool &)
bool readtags (char &, char &, int &)
bool writetags (char, char)
bool writetags (char, char, const char *)
bool writetags (char, char, const BufferString &)
bool writetags (char, char, const IOPar &)
bool writetags (char, char, int)
bool writetags (char, char, bool)
bool ok () const
bool writeErrorMsg (const char *)
const char * peekMsg () const
void fetchMsg (BufferString &)
int timeOut ()
void setTimeOut (int t)

Static Public Member Functions

static int defaultTimout ()
static void setDefaultTimout (int t)

Protected Member Functions

int readbuf_ (void *buf, int bufsz, BufferString *bs=0)
 if buf==bs->buf(), bs->bufSize is incrsd if needed
int rawread_ (void *buf, int minbytes, int maxbytes)
bool writebuf_ (const void *buf, int nrbytes)
bool rawwrite_ (const void *buf, int nrbytes)

Protected Attributes

int time_out

Private Attributes

socket_tsock_

Detailed Description

Represents an end point of a TCP/IP connection.

A client program creates a socket that connects to a server at a given port.

A server program gets a socket from a SocketProvider object

Simultaneous reads and simultaneous writes are prohibited trough a mutex. It is possible to perform one read and one write simultaneously, though.


Constructor & Destructor Documentation

Socket::Socket ( socket_t  ) 
Socket::Socket ( const char *  hostAddr,
int  port 
)
virtual Socket::~Socket (  )  [virtual]

Member Function Documentation

static int Socket::defaultTimout (  )  [static]
void Socket::fetchMsg ( BufferString  ) 
bool Socket::ok (  )  const
const char* Socket::peekMsg (  )  const
int Socket::rawread_ ( void *  buf,
int  minbytes,
int  maxbytes 
) [protected]
bool Socket::rawwrite_ ( const void *  buf,
int  nrbytes 
) [protected]
bool Socket::read ( BufferStringSet  ) 
bool Socket::read ( BufferString  ) 
bool Socket::read ( IOPar  ) 
bool Socket::read ( SeparString  ) 
bool Socket::read ( int &   ) 
bool Socket::read ( bool &   ) 
int Socket::readbuf_ ( void *  buf,
int  bufsz,
BufferString bs = 0 
) [protected]

if buf==bs->buf(), bs->bufSize is incrsd if needed

int Socket::readdata ( void *  buf,
int  bufsz 
)

returns nrbytes read

bool Socket::readtag ( char &   ) 
bool Socket::readtag ( char &  ,
BufferString  
)
bool Socket::readtag ( char &  ,
SeparString  
)
bool Socket::readtag ( char &  ,
bool &   
)
bool Socket::readtag ( char &  ,
int &   
)
bool Socket::readtag2 ( char &  ,
int &  ,
int &   
)
bool Socket::readtags ( char &  ,
char &  ,
bool &   
)
bool Socket::readtags ( char &  ,
char &  ,
int &   
)
bool Socket::readtags ( char &  ,
char &   
)
bool Socket::readtags ( char &  ,
char &  ,
BufferString  
)
static void Socket::setDefaultTimout ( int  t  )  [static]
void Socket::setTimeOut ( int  t  )  [inline]
int Socket::timeOut (  )  [inline]
bool Socket::write ( const IOPar  ) 
bool Socket::write ( const char *   ) 
bool Socket::write ( const BufferString  ) 
bool Socket::write ( const BufferStringSet  ) 
bool Socket::write ( const SeparString  ) 
bool Socket::write ( int   ) 
bool Socket::write ( bool   ) 
bool Socket::writebuf_ ( const void *  buf,
int  nrbytes 
) [protected]
bool Socket::writedata ( void const *  buf,
int  nrbytes 
)
bool Socket::writeErrorMsg ( const char *   ) 

The Socket class supports error handling. You can write an error message to the socket, which is put in the error buffer of the peer.

Since there is no look-ahead, it is not possible to write an error message by itself, unless the receiving side is continuesly polling for data, like in the multithreaded IOHandler in "jobman.h".

In a normal communication protocol, you would transfer f.e. a boolean to signal failure or success anyway, so if you write the error message on the sending side just before transmitting fail/success, the message will be available on the receiving site at the moment the bool has been read.

bool Socket::writetag ( char   ) 
bool Socket::writetag ( char  ,
const BufferString  
)
bool Socket::writetag ( char  ,
const SeparString  
)
bool Socket::writetag ( char  ,
const IOPar  
)
bool Socket::writetag ( char  ,
int   
)
bool Socket::writetag ( char  ,
const char *   
)
bool Socket::writetag ( char  ,
bool   
)
bool Socket::writetag ( char  ,
int  ,
int   
)
bool Socket::writetags ( char  ,
char  ,
const char *   
)
bool Socket::writetags ( char  ,
char  ,
const IOPar  
)
bool Socket::writetags ( char  ,
char  ,
bool   
)
bool Socket::writetags ( char  ,
char  ,
int   
)
bool Socket::writetags ( char  ,
char  ,
const BufferString  
)
bool Socket::writetags ( char  ,
char   
)

Member Data Documentation

socket_t* Socket::sock_ [private]
int Socket::time_out [protected]