Logo
~Sockets~
~Examples~
~Contact~


BaseSocket Class Reference

#include <BaseSocket.h>

Inheritance diagram for BaseSocket:

Inheritance graph
[legend]
List of all members.

Public Member Functions

 BaseSocket (ISocketHandler &)
 ~BaseSocket ()
void SendCmd (unsigned short id, mastercmd_t, short=0)
void SendCmd (unsigned short id, slavecmd_t, short=0)
void printmsg (unsigned short id, mastercmd_t, short len)
void printmsg (unsigned short id, slavecmd_t, short len)
std::string GetText (mastercmd_t)
std::string GetText (slavecmd_t)

Protected Member Functions

 BaseSocket (const BaseSocket &s)
BaseSocketoperator= (const BaseSocket &)

Detailed Description

Definition at line 29 of file BaseSocket.h.


Constructor & Destructor Documentation

BaseSocket::BaseSocket ( ISocketHandler &   ) 

Definition at line 8 of file BaseSocket.cpp.

00009 :TcpSocket(h)
00010 {
00011 }

BaseSocket::~BaseSocket (  ) 

Definition at line 14 of file BaseSocket.cpp.

00015 {
00016 }

BaseSocket::BaseSocket ( const BaseSocket s  )  [inline, protected]

Definition at line 45 of file BaseSocket.h.

00045 : TcpSocket(s) {} // copy constructor


Member Function Documentation

void BaseSocket::SendCmd ( unsigned short  id,
mastercmd_t  ,
short  = 0 
)

Definition at line 19 of file BaseSocket.cpp.

References GetText().

00020 {
00021         char buffer[6];
00022 printf(">Send Id %5u  Command %s  Length %d\n", id, GetText(cmd).c_str(), len);
00023         unsigned short l = htons(id);
00024         memcpy(buffer, &l, 2);
00025         short s = htons(cmd);
00026         memcpy(buffer + 2, &s, 2);
00027         s = htons(len);
00028         memcpy(buffer + 4, &s, 2);
00029         SendBuf(buffer, 6);
00030 }

void BaseSocket::SendCmd ( unsigned short  id,
slavecmd_t  ,
short  = 0 
)

Definition at line 33 of file BaseSocket.cpp.

References GetText().

00034 {
00035         char buffer[6];
00036 printf(">Send Id %5u  Command %s  Length %d\n", id, GetText(cmd).c_str(), len);
00037         unsigned short l = htons(id);
00038         memcpy(buffer, &l, 2);
00039         short s = htons(cmd);
00040         memcpy(buffer + 2, &s, 2);
00041         s = htons(len);
00042         memcpy(buffer + 4, &s, 2);
00043         SendBuf(buffer, 6);
00044 }

void BaseSocket::printmsg ( unsigned short  id,
mastercmd_t  ,
short  len 
)

Definition at line 47 of file BaseSocket.cpp.

References GetText().

Referenced by SlaveSocket::OnRead(), and MasterSocket::OnRead().

00048 {
00049         printf("<Recv Id %5u  Command %s  Length %d\n", id, GetText(cmd).c_str(), len);
00050 }

void BaseSocket::printmsg ( unsigned short  id,
slavecmd_t  ,
short  len 
)

Definition at line 53 of file BaseSocket.cpp.

References GetText().

00054 {
00055         printf("<Recv Id %5u  Command %s  Length %d\n", id, GetText(cmd).c_str(), len);
00056 }

std::string BaseSocket::GetText ( mastercmd_t   ) 

Definition at line 59 of file BaseSocket.cpp.

References M2S_CLOSE, M2S_DATA, and M2S_OPEN.

Referenced by printmsg(), and SendCmd().

00060 {
00061         switch (cmd)
00062         {
00063         case M2S_OPEN: // payload: host:port
00064                 return "M2S_OPEN         " + Utility::l2string(cmd);
00065         case M2S_CLOSE:
00066                 return "M2S_CLOSE        " + Utility::l2string(cmd);
00067         case M2S_DATA: // payload: data
00068                 return "M2S_DATA         " + Utility::l2string(cmd);
00069 /*
00070         case M2S_PROXY_HEADER: // payload: http header to remote server
00071                 return "M2S_PROXY_HEADER " + Utility::l2string(cmd);
00072         case M2S_PROXY_BODY: // payload: data
00073                 return "M2S_PROXY_BODY   " + Utility::l2string(cmd);
00074         case M2S_PROXY_CONNECT: // payload: http proxy header w/ connection info
00075                 return "M2S_PROXY_CONNECT" + Utility::l2string(cmd);
00076 */
00077         }
00078         return         "M2S_BAD COMMAND  " + Utility::l2string(cmd);
00079 }

std::string BaseSocket::GetText ( slavecmd_t   ) 

Definition at line 82 of file BaseSocket.cpp.

References S2M_CONNECT, S2M_DATA, and S2M_DISCONNECTED.

00083 {
00084         switch (cmd)
00085         {
00086         case S2M_CONNECT:
00087                 return "S2M_CONNECT      " + Utility::l2string(cmd);
00088         case S2M_DISCONNECTED:
00089                 return "S2M_DISCONNECTED " + Utility::l2string(cmd);
00090         case S2M_DATA:
00091                 return "S2M_DATA         " + Utility::l2string(cmd);
00092 /*
00093         case S2M_PROXY_HEADER:
00094                 return "S2M_PROXY_HEADER " + Utility::l2string(cmd);
00095         case S2M_PROXY_DATA:
00096                 return "S2M_PROXY_DATA   " + Utility::l2string(cmd);
00097         case S2M_PROXY_CONNECT:
00098                 return "S2M_PROXY_CONNECT" + Utility::l2string(cmd);
00099         case S2M_PROXY_CONNECT_FAILED:
00100                 return "S2M_PROXY_CONNECT_FAILED" + Utility::l2string(cmd);
00101         case S2M_PROXY_CLOSE:
00102                 return "S2M_PROXY_CLOSE  " + Utility::l2string(cmd);
00103 */
00104         }
00105         return         "S2M_BAD COMMAND  " + Utility::l2string(cmd);
00106 }

BaseSocket& BaseSocket::operator= ( const BaseSocket  )  [inline, protected]

Definition at line 46 of file BaseSocket.h.

00046 { return *this; } // assignment operator


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4