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

dsSocket Class Reference

Convenience shell to socket operations. More...

#include <dsSocket.h>

Inheritance diagram for dsSocket:

dsSocketBase dsServerSocket dsSSLSocket List of all members.

Public Methods

 dsSocket (const char *host, const int port, const int proto=IPPROTO_TCP)
 dsSocket ()
virtual ~dsSocket ()
void Open (const int proto=IPPROTO_UDP, const int fcntl_flags=0)
virtual void Connect (const char *host, const int port, const int proto=IPPROTO_TCP)
virtual void Close ()
virtual size_t __read (char *buf, size_t bytes)
virtual size_t __write (const char *ptr, size_t bytes)
virtual size_t __sendto (const char *buf, size_t bytes, const sockaddr *to, socklen_t len)
size_t Sendto (const char *ptr, size_t bytes, const char *host, const int port)
unsigned long getip ()
unsigned long getpeerip ()
unsigned int getport ()
char * getpeer_aip ()
char * get_aip ()
int fd () const
size_t Read (char *buffer, size_t bytes, int sec=10, int usec=0)
size_t Read (std::ostream &os, int sec=10, int usec=0)
size_t Write (const char *buffer, size_t bytes, int sec=10, int usec=0)
size_t Write (std::istream &is, int sec=10, int usec=0)
size_t Write (const char *str, int sec=10, int usec=0)
size_t Printf (const char *format,...)
size_t ReadLine (std::ostream &os, int sec=10)
size_t ReadLine (char *buf, size_t size, int sec=10)
size_t WriteLine (std::istream &is, int sec=10)
size_t WriteLine (const char *str, int sec=10)

Protected Attributes

sockaddr_in _sockAddr
hostent * _pHostEnt
int _sock

Detailed Description

This class provide C++ shell for basic socket operation, virtual read and write operation allow to implement different transport (e.g SSL) without changing uplevel code

See also:
: dsSSLSocket


Constructor & Destructor Documentation

dsSocket::dsSocket (  const char *    host,
const int    port,
const int    proto = IPPROTO_TCP
) 
 

dsSocket::dsSocket (    ) 
 

dsSocket::~dsSocket (    )  [virtual]
 


Member Function Documentation

size_t dsSocket::__read (  char *    buf,
size_t    bytes
)  [virtual]
 

Implements dsSocketBase.

Reimplemented in dsSSLSocket.

size_t dsSocket::__sendto (  const char *    buf,
size_t    bytes,
const sockaddr *    to,
socklen_t    len
)  [virtual]
 

size_t dsSocket::__write (  const char *    ptr,
size_t    bytes
)  [virtual]
 

Implements dsSocketBase.

Reimplemented in dsSSLSocket.

void dsSocket::Close (    )  [virtual]
 

Implements dsSocketBase.

Reimplemented in dsServerSocket, and dsSSLSocket.

void dsSocket::Connect (  const char *    host,
const int    port,
const int    proto = IPPROTO_TCP
)  [virtual]
 

Don't add O_NONBLOCK by default because it require another way of error * and timeout handling

If I chouse to set O_NONBLOCK by default, code should looks like this:

#ifdef POSIX_OS int fl = fcntl(_sock, F_GETFL, 0); fcntl(_sock, F_SETFL, fl | O_NONBLOCK); #endif

Implements dsSocketBase.

int dsSocketBase::fd (    )  const [inline, inherited]
 

char * dsSocket::get_aip (    ) 
 

unsigned long dsSocket::getip (    ) 
 

char * dsSocket::getpeer_aip (    ) 
 

unsigned long dsSocket::getpeerip (    ) 
 

unsigned int dsSocket::getport (    ) 
 

void dsSocket::Open (  const int    proto = IPPROTO_UDP,
const int    fcntl_flags = 0
) 
 

size_t dsSocketBase::Printf (  const char *    format,
...   
)  [inherited]
 

size_t dsSocketBase::Read (  std::ostream &    os,
int    sec = 10,
int    usec = 0
)  [inherited]
 

size_t dsSocketBase::Read (  char *    buffer,
size_t    bytes,
int    sec = 10,
int    usec = 0
)  [inherited]
 

Read/Write data from network

The main difference from raw read/write, that socket covered by select and as result, these functions doesn't block for more than timeout.

size_t dsSocketBase::ReadLine (  char *    buf,
size_t    size,
int    sec = 10
)  [inherited]
 

size_t dsSocketBase::ReadLine (  std::ostream &    os,
int    sec = 10
)  [inherited]
 

ReadLine

Parameters:
os stream to store data
sec maximal wait time

size_t dsSocket::Sendto (  const char *    ptr,
size_t    bytes,
const char *    host,
const int    port
) 
 

size_t dsSocketBase::Write (  const char *    str,
int    sec = 10,
int    usec = 0
)  [inline, inherited]
 

size_t dsSocketBase::Write (  std::istream &    is,
int    sec = 10,
int    usec = 0
)  [inherited]
 

size_t dsSocketBase::Write (  const char *    buffer,
size_t    bytes,
int    sec = 10,
int    usec = 0
)  [inherited]
 

size_t dsSocketBase::WriteLine (  const char *    str,
int    sec = 10
)  [inherited]
 

size_t dsSocketBase::WriteLine (  std::istream &    is,
int    sec = 10
)  [inherited]
 


Member Data Documentation

struct hostent* dsSocket::_pHostEnt [protected]
 

int dsSocketBase::_sock [protected, inherited]
 

struct sockaddr_in dsSocket::_sockAddr [protected]
 


The documentation for this class was generated from the following files:
Generated on Mon May 16 18:27:00 2005 for libdms4 by doxygen1.3-rc2