Classes | Typedefs | Enumerations | Functions | Variables

netlib Namespace Reference

Classes

class  MessageBuffer
struct  connection_info_t
struct  envelope_t
 An envelope describes from where and how a remote message arrived. More...
struct  ip_addr_t
 representation of IP address (abstracts IPv4 and IPv6) More...
struct  address_t
 holds the IP address and port of a remote host More...

Typedefs

typedef std::vector< char > buffer_t
typedef std::deque< request_t > message_queue_t
typedef std::map< conn_id_t,
smart_ptr< conn_rec_t > > 
conn_map_t
typedef dword_t conn_id_t
 connection ID type. Will never be null for a valid connection.
typedef socklen_t socket_length_t
typedef std::map< std::string,
ip_addr_t
map_ip_addr_t
 a map of IP addresses (typically interface name --> IP address)
typedef void * ws_set_t

Enumerations

enum  eConnectionType {
  eType_TCP = 0x0001,
  eType_SecureTCP = 0x0002,
  eType_UDPLocal = 0x0010,
  eType_UDPRemote = 0x0020,
  eType_UDPBroadcast = 0x0040,
  eType_TCPListener = 0x0100,
  eType_Invalid = 0
}
 

the type of connection

More...
enum  eWSError {
  eWS_Okay = 0,
  eWS_Again = 1,
  eWS_Denied = 2,
  eWS_InUse = 3,
  eWS_ConnectionRefused = 4,
  eWS_Unknown = 0x100,
  eWS_Invalid = 0x7ff
}
 

these are error codes.

More...

Functions

static const char * getTypeName (IN eConnectionType type)
static conn_id_t getNewConnectionId (void)
static void dumpErrorInfo (IN const char *msg)
static void verify (IN bool isOK, IN const char *msg)
static void verifyThrow (IN bool isOK, IN const char *msg)
static conn_rec_t * getConnectionRecord (IN conn_id_t conn_id)
static bool readBuffer (IN conn_rec_t *rec)
static void parseHeaderLine (IN conn_rec_t *rec)
static bool handleData (IN conn_rec_t *rec, IO envelope_t &envelope, IO smart_ptr< MessageBuffer > &msgbuf)
static conn_id_t addConnectionRecord (IN eConnectionType type, IN int socket, IN const address_t &address)
static conn_id_t handleConnection (IN conn_rec_t *rec)
static void writeMessage (IN conn_rec_t *rec)
static void handleWrites (IN ws_set_t writeable)
static bool handleRead (IN ws_set_t readers, IO envelope_t &envelope, IO smart_ptr< MessageBuffer > &msgbuf)
std::string getServerFromIP (IN const ip_addr_t &ip)
conn_id_t createTcpListener (IN const address_t &address, IN int maxBacklog)
 create a listener (if clients connect, you'll see their messages show up)
conn_id_t createTcpConnection (IN const address_t &address)
 create a connection to a remote peer (connection ID is returned)
conn_id_t createUdpLocal (IN const address_t &localUdp)
 create a local UDP connection for sending/receiving datagrams.
conn_id_t createUdpRemote (IN conn_id_t localUdp, IN const address_t &address)
 create a logical connection to represent a remote UDP sender/receiver

  • caller must specify the local UDP connection that will communicate this is used for sending to remote UDP listeners

conn_id_t createUdpBroadcast (IN const address_t &broadcastAddress)
 create a local UDP sending point for datagram broadcasts to a specific port.
bool enqueueMessage (IN conn_id_t connId, IN smart_ptr< MessageBuffer > &message)
 asynchronously send data to a particular connection

  • conn_id specifies the (remote) receiver
  • queued messages are actually sent via getNextMessage() calls

bool getNextMessage (IN long wait_microseconds, OUT netlib::envelope_t &envelope, OUT smart_ptr< MessageBuffer > &buffer)
 get next message from all open connections (empty if no messages waiting)

  • this is the main message pump so applications should keep calling it

bool isValidConnection (IN conn_id_t conn_id)
 is this a valid connection?
bool getConnectionInfo (IN conn_id_t conn_id, OUT connection_info_t &info)
 given a connection, retrieve information about it
void closeConnection (IN conn_id_t conn_id)
 terminate a particular connection
void dumpMessage (IO std::ostream &stream, IN const char *title, IN const envelope_t &envelope, IN const MessageBuffer *buffer)
 for debugging
void dumpStats (void)
 info only
static void setNonBlocking (IN int s)
static void getAddressFromSockaddr (IN const struct sockaddr_storage *psa, OUT address_t &address) throw ()
static void getSockaddrFromAddress (IN const address_t &address, OUT struct sockaddr_in &sa) throw ()
bool getLocalInterfaces (OUT map_ip_addr_t &interfaces)
 get set of local interfaces
static bool tryInterface (IN const map_ip_addr_t &map, IN const char *name, OUT ip_addr_t &ip) throw ()
bool wsIsValidSocket (IN int s) throw ()
 is the given socket identifier valid?
eWSError wsGetError (void) throw ()
 gets the current error (0 means no error).
void wsGetErrorMessage (IO char *buffer, IN int bufferSize) throw ()
int wsCreateTcpSocket (void) throw ()
 creates a socket that can be used for TCP
int wsCreateUdpSocket (IN bool broadcast) throw ()
 creates a socket that can be used for UDP
int wsBindToPort (IN int s, IN int port) throw ()
 binds the given socket to a specific local port for UDP or TCP returns 0 on success, -1 for error.
int wsListen (IN int s, IN int maxBacklog) throw ()
 usually used for TCP listening sockets.
int wsConnect (IN int s, IN const address_t &server) throw ()
 makes a connection to the specified server
int wsReceive (IN int s, IN char *buffer, IN int bufferSize) throw ()
 receives data (typically from TCP).
int wsReceiveFrom (IN int s, IN char *buffer, IN int bufferSize, OUT address_t &from) throw ()
 receives data (typically from UPD).
int wsSend (IN int s, IN const char *buffer, IN int bufferSize) throw ()
 sends data (typically for TCP).
int wsSendTo (IN int s, IN const char *buffer, IN int bufferSize, IN const address_t &to) throw ()
 sends data (typically for UDP).
int wsAccept (IN int s, OUT address_t &address) throw ()
 accepts an incoming request.
ws_set_t wsCreateSet (void)
 creates an object that you can clear, and then populate with sockets.
void wsClearSet (IN ws_set_t set) throw ()
 clears the given set
void wsAddSocketToSet (IN ws_set_t set, IN int s) throw ()
 adds the given socket to the given set
bool wsIsSocketInSet (IN ws_set_t set, IN int s) throw ()
 is the given socket in the set?
void wsDestroySet (IN ws_set_t set) throw ()
 destroys the given set
int wsSelect (IN int maxSocket,IN ws_set_t readers, IN ws_set_t writers, IN long wait_microseconds) throw ()
 waits until a socket is ready for read/write.
void wsCloseSocket (IN int s) throw ()
 closes a socket
void wsGetErrorMessage (IN char *buffer, IN int bufferSize) throw ()
 returns the most recent error message

Variables

static const int s_chunkSize = 8192
static const int s_maxHeaderLine = 64
static conn_map_t s_connection_map
static dword_t s_messagesSent = 0
static dword_t s_messagesReceived = 0
static qword_t s_bytesWritten = 0
static qword_t s_bytesRead = 0

Typedef Documentation

typedef std::vector<char> netlib::buffer_t

Definition at line 38 of file message-buffer.cpp.

typedef std::deque<request_t> netlib::message_queue_t

Definition at line 82 of file netlib.cpp.

typedef std::map<conn_id_t, smart_ptr<conn_rec_t> > netlib::conn_map_t

Definition at line 141 of file netlib.cpp.

typedef socklen_t netlib::socket_length_t

Definition at line 74 of file wavesock.cpp.


Function Documentation

static const char* netlib::getTypeName ( IN eConnectionType  type  )  [static]

Definition at line 165 of file netlib.cpp.

static conn_id_t netlib::getNewConnectionId ( void   )  [static]

Definition at line 193 of file netlib.cpp.

static void netlib::dumpErrorInfo ( IN const char *  msg  )  [static]

Definition at line 118 of file wavesock.cpp.

static void netlib::verify ( IN bool  isOK,
IN const char *  msg 
) [static]

Definition at line 136 of file wavesock.cpp.

static void netlib::verifyThrow ( IN bool  isOK,
IN const char *  msg 
) [static]

Definition at line 246 of file netlib.cpp.

static conn_rec_t* netlib::getConnectionRecord ( IN conn_id_t  conn_id  )  [static]

Definition at line 270 of file netlib.cpp.

static bool netlib::readBuffer ( IN conn_rec_t *  rec  )  [static]

Definition at line 289 of file netlib.cpp.

static void netlib::parseHeaderLine ( IN conn_rec_t *  rec  )  [static]

Definition at line 356 of file netlib.cpp.

static bool netlib::handleData ( IN conn_rec_t *  rec,
IO envelope_t &  envelope,
IO smart_ptr< MessageBuffer > &  msgbuf 
) [static]

Definition at line 399 of file netlib.cpp.

static conn_id_t netlib::addConnectionRecord ( IN eConnectionType  type,
IN int  socket,
IN const address_t &  address 
) [static]

Definition at line 543 of file netlib.cpp.

static conn_id_t netlib::handleConnection ( IN conn_rec_t *  rec  )  [static]

Definition at line 582 of file netlib.cpp.

static void netlib::writeMessage ( IN conn_rec_t *  rec  )  [static]

Definition at line 608 of file netlib.cpp.

static void netlib::handleWrites ( IN ws_set_t  writeable  )  [static]

Definition at line 725 of file netlib.cpp.

static bool netlib::handleRead ( IN ws_set_t  readers,
IO envelope_t &  envelope,
IO smart_ptr< MessageBuffer > &  msgbuf 
) [static]

Definition at line 756 of file netlib.cpp.

static void netlib::setNonBlocking ( IN int  s  )  [static]

Definition at line 154 of file wavesock.cpp.

static void netlib::getAddressFromSockaddr ( IN const struct sockaddr_storage *  psa,
OUT address_t &  address 
) throw () [static]

Definition at line 174 of file wavesock.cpp.

static void netlib::getSockaddrFromAddress ( IN const address_t &  address,
OUT struct sockaddr_in &  sa 
) throw () [static]

Definition at line 193 of file wavesock.cpp.

static bool netlib::tryInterface ( IN const map_ip_addr_t &  map,
IN const char *  name,
OUT ip_addr_t &  ip 
) throw () [static]

Definition at line 481 of file wavesock.cpp.

void netlib::wsGetErrorMessage ( IO char *  buffer,
IN int  bufferSize 
) throw ()

Definition at line 602 of file wavesock.cpp.


Variable Documentation

const int netlib::s_chunkSize = 8192 [static]

Definition at line 59 of file netlib.cpp.

const int netlib::s_maxHeaderLine = 64 [static]

Definition at line 61 of file netlib.cpp.

Definition at line 143 of file netlib.cpp.

dword_t netlib::s_messagesSent = 0 [static]

Definition at line 148 of file netlib.cpp.

dword_t netlib::s_messagesReceived = 0 [static]

Definition at line 149 of file netlib.cpp.

qword_t netlib::s_bytesWritten = 0 [static]

Definition at line 150 of file netlib.cpp.

qword_t netlib::s_bytesRead = 0 [static]

Definition at line 151 of file netlib.cpp.