Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

TcpSocket Class Reference

#include <TcpSocket.hpp>

Inheritance diagram for TcpSocket::

Socket List of all members.

Public Methods

 TcpSocket (int port=0) throw (int)
 TcpSocket (Socket &original) throw (int)
 TcpSocket (InetAddress &address, int port=0) throw (int)
 TcpSocket (InetAddress &remoteAddr, int remotePort, InetAddress &localAddress, int localPort) throw (int)
 TcpSocket (char *host, int port) throw (int)
 TcpSocket (char *remoteHost, int remotePort, InetAddress &localHost, int localPort) throw (int)
const char * getLocalHost () const
const char * getHost () const
InetAddress getLocalAddress () const
InetAddress getInetAddress () const
int getLocalPort () const
int getPort () const
int setTcpNoDelay (bool on)
int setSoLinger (bool on, int linger)
int setSoTimeout (int timeout)
int setSendBufferSize (int size)
int setRecieveBufferSize (int size)
int setKeepAlive (bool on)
bool getTcpNoDelay ()
int getSoLinger ()
int getSoTimeout ()
int getSendBufferSize ()
int getRecieveBufferSize ()
bool getKeepAlive ()
int read (char *buffer, size_t len, int flags=0)
int send (char *buffer, size_t len, int flags=0)

Protected Attributes

InetAddressremoteAddress
int remotePort
int localPort

Constructor & Destructor Documentation

TcpSocket::TcpSocket int    port = 0 throw (int)
 

Definition at line 15 of file TcpSocket.cpp.

00016   : Socket((struct sockaddr *)NULL, PF_INET, SOCK_STREAM, 0)
00017 {
00018   struct sockaddr_in *s_in = (struct sockaddr_in *)lsa;
00019   remoteAddress = NULL;
00020   remotePort = 0;
00021   localPort = port;
00022   s_in->sin_family = AF_INET;
00023   s_in->sin_port = htons(localPort);
00024   s_in->sin_addr.s_addr = htonl(INADDR_ANY);
00025   memset(&(s_in->sin_zero), '\0', 8);
00026   bind();
00027 }

TcpSocket::TcpSocket Socket   original throw (int)
 

Definition at line 29 of file TcpSocket.cpp.

00030   : Socket( original.getSocket(), PF_INET, SOCK_STREAM, 0 )
00031 {
00032   
00033 }

TcpSocket::TcpSocket InetAddress   address,
int    port = 0
throw (int)
 

Definition at line 35 of file TcpSocket.cpp.

00036   : Socket((struct sockaddr *)NULL, PF_INET, SOCK_STREAM, 0)
00037 {
00038   struct sockaddr_in *s_in = (struct sockaddr_in *)lsa;
00039   remoteAddress = NULL;
00040   remotePort = 0;
00041   localPort = port;
00042   s_in->sin_family = AF_INET;
00043   s_in->sin_port = htons(localPort);
00044   s_in->sin_addr.s_addr = address.getAddress2();
00045   memset(&(s_in->sin_zero), '\0', 8);
00046   bind();
00047 }

TcpSocket::TcpSocket InetAddress   remoteAddr,
int    remotePort,
InetAddress   localAddress,
int    localPort
throw (int)
 

Definition at line 49 of file TcpSocket.cpp.

00050   : Socket((struct sockaddr *)NULL, PF_INET, SOCK_STREAM, 0)
00051 {
00052   struct sockaddr_in *ls_in = (struct sockaddr_in *)lsa, *rs_in = (struct sockaddr_in *)rsa;
00053   this->localPort = localPort;
00054   ls_in->sin_family = AF_INET;
00055   ls_in->sin_port = htons(this->localPort);
00056   ls_in->sin_addr.s_addr = localAddress.getAddress2();
00057   memset(&(ls_in->sin_zero), '\0', 8);
00058   bind();
00059   remoteAddress = new InetAddress(remoteAddr);
00060   this->remotePort = remotePort;
00061    ls_in->sin_family = AF_INET;
00062   ls_in->sin_port = htons(this->remotePort);
00063   ls_in->sin_addr.s_addr = remoteAddress->getAddress2();
00064   memset(&(ls_in->sin_zero), '\0', 8);
00065   connect();
00066 }

TcpSocket::TcpSocket char *    host,
int    port
throw (int)
 

Definition at line 105 of file TcpSocket.cpp.

00106   : Socket((struct sockaddr *)NULL, PF_INET, SOCK_STREAM, 0)
00107 {
00108   struct sockaddr_in *s_in = (struct sockaddr_in *)lsa;
00109   InetAddress *I = new InetAddress(host);
00110   remoteAddress = NULL;
00111   remotePort = 0;
00112   localPort = port;
00113   s_in->sin_family = AF_INET;
00114   s_in->sin_port = htons(localPort);
00115   s_in->sin_addr.s_addr = I->getAddress2();
00116   memset(&(s_in->sin_zero), '\0', 8);
00117   bind();
00118   delete I;
00119 }

TcpSocket::TcpSocket char *    remoteHost,
int    remotePort,
InetAddress   localAddress,
int    localPort
throw (int)
 

Definition at line 121 of file TcpSocket.cpp.

00122   : Socket((struct sockaddr *)NULL, PF_INET, SOCK_STREAM, 0)
00123 {
00124   struct sockaddr_in *ls_in = (struct sockaddr_in *)lsa, *rs_in = (struct sockaddr_in *)rsa;
00125   InetAddress *remoteAddr = new InetAddress(remoteHost);
00126   this->localPort = localPort;
00127   ls_in->sin_family = AF_INET;
00128   ls_in->sin_port = htons(this->localPort);
00129   ls_in->sin_addr.s_addr = localAddress.getAddress2();
00130   memset(&(ls_in->sin_zero), '\0', 8);
00131   bind();
00132   this->remotePort = remotePort;
00133   ls_in->sin_family = AF_INET;
00134   ls_in->sin_port = htons(this->remotePort);
00135   ls_in->sin_addr.s_addr = remoteAddress->getAddress2();
00136   memset(&(ls_in->sin_zero), '\0', 8);
00137   connect();
00138   delete remoteAddr;
00139 }


Member Function Documentation

__inline const char * TcpSocket::getHost   const
 

Definition at line 174 of file TcpSocket.cpp.

00175 {
00176   return remoteAddress->getHostName();
00177 }

InetAddress TcpSocket::getInetAddress   const
 

Definition at line 152 of file TcpSocket.cpp.

00153 {  
00154   return *remoteAddress;
00155 }

bool TcpSocket::getKeepAlive  
 

Definition at line 316 of file TcpSocket.cpp.

00317 {
00318   int ret = 0;
00319   int rets = sizeof(int);
00320   if(getSockOpt(SOL_SOCKET,SO_KEEPALIVE,(void *)&ret,(socklen_t *) &rets) != 0) {
00321 //    perror("TcpSocket::setTcpNoDelay() FAIL");
00322      return -1;
00323   }
00324   return ret;   
00325 }

InetAddress TcpSocket::getLocalAddress   const
 

Definition at line 146 of file TcpSocket.cpp.

00147 {  
00148   InetAddress I(inet_ntoa(((struct sockaddr_in*)lsa)->sin_addr));
00149   return I;
00150 }

const char * TcpSocket::getLocalHost   const
 

Definition at line 169 of file TcpSocket.cpp.

00170 {
00171   return inet_ntoa(((struct sockaddr_in*)lsa)->sin_addr);
00172 }

__inline int TcpSocket::getLocalPort   const
 

Definition at line 180 of file TcpSocket.cpp.

00181 {
00182   return localPort;
00183 }

__inline int TcpSocket::getPort   const
 

Definition at line 185 of file TcpSocket.cpp.

00186 {
00187   return remotePort;
00188 }

int TcpSocket::getRecieveBufferSize  
 

Definition at line 305 of file TcpSocket.cpp.

00306 {
00307   int ret = 0;
00308   int rets = sizeof(int);
00309   if(getSockOpt(SOL_SOCKET,SO_RCVBUF,(void *)&ret,(socklen_t *) &rets) != 0) {
00310 //    perror("TcpSocket::setTcpNoDelay() FAIL");
00311      return -1;
00312   }
00313   return ret;   
00314 }

int TcpSocket::getSendBufferSize  
 

Definition at line 294 of file TcpSocket.cpp.

00295 {
00296   int ret = 0;
00297   int rets = sizeof(int);
00298   if(getSockOpt(SOL_SOCKET,SO_SNDBUF,(void *)&ret,(socklen_t *) &rets) != 0) {
00299 //    perror("TcpSocket::setTcpNoDelay() FAIL");
00300      return -1;
00301   }
00302   return ret;   
00303 }

int TcpSocket::getSoLinger  
 

Definition at line 273 of file TcpSocket.cpp.

00274 {
00275   struct linger ret;
00276   ret.l_onoff = 0;
00277   ret.l_linger = 0;
00278   int rets =  sizeof(int);
00279   if(setSockOpt(SOL_SOCKET,SO_LINGER,(void *)&ret,rets) != 0)
00280     return -1;
00281 //     perror("TcpSocket::setSoLinger() FAIL");
00282   if(rets != sizeof(struct linger))
00283     return 0;
00284   if((BOOL)ret.l_onoff == false)
00285      return 0;
00286   return ret.l_linger;;
00287 }

int TcpSocket::getSoTimeout  
 

Definition at line 289 of file TcpSocket.cpp.

00290 {
00291    return -1;
00292 }

bool TcpSocket::getTcpNoDelay  
 

Definition at line 259 of file TcpSocket.cpp.

00260 {
00261   struct protoent *pe;
00262   BOOL ret = false;
00263   int rets = sizeof(int);
00264    
00265   pe = getprotobyname("TCP");
00266   if(getSockOpt(pe->p_proto,TCP_NODELAY,(void *)&ret,(socklen_t*)&rets) != 0) {
00267 //    perror("TcpSocket::setTcpNoDelay() FAIL");
00268      return false; 
00269   }
00270   return ret;
00271 }

int TcpSocket::read char *    buffer,
size_t    len,
int    flags = 0
 

Definition at line 327 of file TcpSocket.cpp.

Referenced by main().

00328 {
00329    int l  = len;
00330    l = recv(sck,(void  *)buffer, len, flags);
00331    return l;
00332 }

int TcpSocket::send char *    buffer,
size_t    len,
int    flags = 0
 

Definition at line 335 of file TcpSocket.cpp.

Referenced by main().

00336 {
00337    int l  = len;
00338    l = ::send(sck,(void  *)buffer, len, flags);
00339    return l;
00340 }

int TcpSocket::setKeepAlive bool    on
 

Definition at line 248 of file TcpSocket.cpp.

00249 {
00250   if(setSockOpt(SOL_SOCKET,SO_KEEPALIVE,(void *)&on,sizeof(int)) != 0) {
00251 //    perror("TcpSocket::setTcpNoDelay() FAIL");
00252      return -1;
00253   }
00254   return 0;
00255 }

int TcpSocket::setRecieveBufferSize int    size
 

Definition at line 239 of file TcpSocket.cpp.

00240 {
00241   if(setSockOpt(SOL_SOCKET,SO_RCVBUF,(void *)&size,sizeof(int)) != 0) {
00242 //    perror("TcpSocket::setTcpNoDelay() FAIL");
00243      return -1;
00244   }
00245   return 0;
00246 }

int TcpSocket::setSendBufferSize int    size
 

Definition at line 230 of file TcpSocket.cpp.

00231 {
00232   if(setSockOpt(SOL_SOCKET,SO_SNDBUF,(void *)&size,sizeof(int)) != 0) {
00233 //    perror("TcpSocket::setTcpNoDelay() FAIL");
00234      return -1;
00235   }
00236   return 0;
00237 }

int TcpSocket::setSoLinger bool    on,
int    linger
 

Definition at line 203 of file TcpSocket.cpp.

00204 {
00205   struct linger lin;
00206   lin.l_onoff = on;
00207   lin.l_linger = linger;
00208   if(setSockOpt(SOL_SOCKET,SO_LINGER,(void *)&lin,sizeof(struct linger)) != 0)
00209      return -1;
00210 //     perror("TcpSocket::setSoLinger() FAIL");
00211   
00212   return 0;
00213 }  

int TcpSocket::setSoTimeout int    timeout
 

Definition at line 215 of file TcpSocket.cpp.

00216 {
00217 #if 0
00218   if(setSockOpt(SOL_SOCKET,SO_TIMEOUT,(void *)&timeout,sizeof(int)) != 0)
00219      return -1;
00220 //     perror("TcpSocket::setSoTimeout() FAIL");
00221   
00222   return 0;
00223 #else
00224    errno = EBADF;
00225    return -1;
00226 #endif
00227    
00228 }

int TcpSocket::setTcpNoDelay bool    on
 

Definition at line 191 of file TcpSocket.cpp.

00192 {
00193   struct protoent *pe;
00194    
00195   pe = getprotobyname("TCP");
00196   if(setSockOpt(pe->p_proto,TCP_NODELAY,(void *)&on,sizeof(int)) != 0) {
00197 //    perror("TcpSocket::setTcpNoDelay() FAIL");
00198      return -1;
00199   }
00200   return 0;
00201 }


Member Data Documentation

int TcpSocket::localPort [protected]
 

Definition at line 72 of file TcpSocket.hpp.

InetAddress* TcpSocket::remoteAddress [protected]
 

Definition at line 70 of file TcpSocket.hpp.

int TcpSocket::remotePort [protected]
 

Definition at line 71 of file TcpSocket.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:49:57 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001