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 (eConnectionType type)
static conn_id_t getNewConnectionId (void)
static void dumpErrorInfo (const char *msg)
static void verify (bool isOK, const char *msg)
static void verifyThrow (bool isOK, const char *msg)
static conn_rec_t * getConnectionRecord (conn_id_t conn_id)
static bool readBuffer (conn_rec_t *rec)
static void parseHeaderLine (conn_rec_t *rec)
static bool handleData (conn_rec_t *rec, envelope_t &envelope, smart_ptr< MessageBuffer > &msgbuf)
static conn_id_t addConnectionRecord (eConnectionType type, int socket, const address_t &address)
static conn_id_t handleConnection (conn_rec_t *rec)
static void writeMessage (conn_rec_t *rec)
static void handleWrites (ws_set_t writeable)
static bool handleRead (ws_set_t readers, envelope_t &envelope, smart_ptr< MessageBuffer > &msgbuf)
std::string getServerFromIP (const ip_addr_t &ip)
conn_id_t createTcpListener (const address_t &address,int maxBacklog)
 create a listener (if clients connect, you'll see their messages show up)
conn_id_t createTcpConnection (const address_t &address)
 create a connection to a remote peer (connection ID is returned)
conn_id_t createUdpLocal (const address_t &localUdp)
 create a local UDP connection for sending/receiving datagrams.
conn_id_t createUdpRemote (conn_id_t localUdp,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 (const address_t &broadcastAddress)
 create a local UDP sending point for datagram broadcasts to a specific port.
bool enqueueMessage (conn_id_t connId,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 (long wait_microseconds,netlib::envelope_t &envelope,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 (conn_id_t conn_id)
 is this a valid connection?
bool getConnectionInfo (conn_id_t conn_id,connection_info_t &info)
 given a connection, retrieve information about it
void closeConnection (conn_id_t conn_id)
 terminate a particular connection
void dumpMessage (std::ostream &stream,const char *title,const envelope_t &envelope,const MessageBuffer *buffer)
 for debugging
void dumpStats (void)
 info only
static void setNonBlocking (int s)
static void getAddressFromSockaddr (const struct sockaddr_storage *psa, address_t &address) throw ()
static void getSockaddrFromAddress (const address_t &address, struct sockaddr_in &sa) throw ()
bool getLocalInterfaces (map_ip_addr_t &interfaces)
 get set of local interfaces
static bool tryInterface (const map_ip_addr_t &map, const char *name, ip_addr_t &ip) throw ()
bool wsIsValidSocket (int s) throw ()
 is the given socket identifier valid?
eWSError wsGetError (void) throw ()
 gets the current error (0 means no error).
void wsGetErrorMessage (char *buffer,int bufferSize) throw ()
 returns the most recent error message
int wsCreateTcpSocket (void) throw ()
 creates a socket that can be used for TCP
int wsCreateUdpSocket (bool broadcast) throw ()
 creates a socket that can be used for UDP
int wsBindToPort (int s,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 (int s,int maxBacklog) throw ()
 usually used for TCP listening sockets.
int wsConnect (int s,const address_t &server) throw ()
 makes a connection to the specified server
int wsReceive (int s,char *buffer,int bufferSize) throw ()
 receives data (typically from TCP).
int wsReceiveFrom (int s,char *buffer,int bufferSize,address_t &from) throw ()
 receives data (typically from UPD).
int wsSend (int s,const char *buffer,int bufferSize) throw ()
 sends data (typically for TCP).
int wsSendTo (int s,const char *buffer,int bufferSize,const address_t &to) throw ()
 sends data (typically for UDP).
int wsAccept (int s,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 (ws_set_t set) throw ()
 clears the given set
void wsAddSocketToSet (ws_set_t set,int s) throw ()
 adds the given socket to the given set
bool wsIsSocketInSet (ws_set_t set,int s) throw ()
 is the given socket in the set?
void wsDestroySet (ws_set_t set) throw ()
 destroys the given set
int wsSelect (int maxSocket,ws_set_t readers,ws_set_t writers,long wait_microseconds) throw ()
 waits until a socket is ready for read/write.
void wsCloseSocket (int s) throw ()
 closes a socket

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 78 of file netlib.cpp.

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

Definition at line 137 of file netlib.cpp.

typedef socklen_t netlib::socket_length_t

Definition at line 78 of file wavesock.cpp.


Function Documentation

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

Definition at line 161 of file netlib.cpp.

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

Definition at line 189 of file netlib.cpp.

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

Definition at line 122 of file wavesock.cpp.

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

Definition at line 140 of file wavesock.cpp.

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

Definition at line 242 of file netlib.cpp.

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

Definition at line 266 of file netlib.cpp.

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

Definition at line 285 of file netlib.cpp.

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

Definition at line 352 of file netlib.cpp.

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

Definition at line 395 of file netlib.cpp.

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

Definition at line 539 of file netlib.cpp.

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

Definition at line 578 of file netlib.cpp.

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

Definition at line 604 of file netlib.cpp.

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

Definition at line 721 of file netlib.cpp.

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

Definition at line 752 of file netlib.cpp.

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

Definition at line 158 of file wavesock.cpp.

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

Definition at line 178 of file wavesock.cpp.

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

Definition at line 197 of file wavesock.cpp.

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

Definition at line 462 of file wavesock.cpp.


Variable Documentation

const int netlib::s_chunkSize = 8192 [static]

Definition at line 55 of file netlib.cpp.

const int netlib::s_maxHeaderLine = 64 [static]

Definition at line 57 of file netlib.cpp.

Definition at line 139 of file netlib.cpp.

Definition at line 144 of file netlib.cpp.

Definition at line 145 of file netlib.cpp.

Definition at line 146 of file netlib.cpp.

Definition at line 147 of file netlib.cpp.