ClientServer

Metrics


toc >>

class CONNECTION : public STREAM_SOCK, public C_ITEM

#include "connection.H"

This is for HP; what about others?

Public Interface

CONNECTION ~CONNECTION NumQueuedMsgs
closeConnection enqueueSend getConnGroup
getConsecutiveTempErrors getMsg getMsg_blk
getNextSend getPartialRecv getPartialSend
getRecvBuffsize getSendBuffsize get_host_name
havePartialRecv_p havePartialWrite_p incrementConsecutiveTempErrors
markSocketAsOtherHungUp outMsgsWaiting_p readMsg
readMsgIntoBuff readMsgIntoBuff_blk readMsg_blk
resetConsecutiveTempErrors resumePartialSend resumePartialWrite
resumePartialWrite_blk scheduleSend scheduleWrite
scheduleWriteNoCopy sendMessage sendMessage_blk
sendQueuedMsgs sendQueuedMsgs_blk setConnGroup
setMaxUnixBuffers setNoPartialRecv setPartialRecv
setPartialSend setRecvBuffsize setSendBuffsize
writeMsg writeMsgNoCopy writeMsgNoCopy_blk
writeMsg_blk

Public Interface

CONNECTION( int fd = BOGUS_FD , int port = BOGUS_PORT , int idnum = BOGUS_ID , SERVICE_GROUP* cgrp = ( ( void* ) 0 ) ) ;
Method: CONNECTION constructor Summary: Create CONNECTION object to mediate comms on connected socket. Description: After making or accepting a connection, use this to build a CONNECTION object. Arg fd is the file des- criptor of the TCP/IP connection; port is the port number; idnum is an arbitrary int with which to identify this connection, and cgrp points to the SERVICE_GROUP that this obj belongs to (there need not be any). Return: None.
~CONNECTION( ) ;
Method: CONNECTION destructor Summary: Destruct the CONNECTION. Description: Returns some allocated storage. Return: None.
int NumQueuedMsgs( ) ;
void closeConnection( ) ;
void enqueueSend( SockMsgType* msg ) ;
SERVICE_GROUP* getConnGroup( ) ;
int getConsecutiveTempErrors( ) ;
int getMsg( SockMsgType* msg , int flags = 0 ) ;
Read next message from this connection and return thru arg, msg, if able to read whole thing. The returned val indicates the status of the call: WHOLE_MSG_OK : read entire msg; PARTIAL_MSG_OK: read part of msg (rest will be read in subsequent getMsg call(s); NO_MSG_AVAIL : couldn't even get whole internal header (usually means 0 bytes ready at socket so it may indicate a problem if msg expected) CLOSED_CONN : other side has closed the connection.
int getMsg_blk( SockMsgType* msg , int flags = 0 ) ;
Blocking version of getMsg:
SockMsgType* getNextSend( ) ;
SockMsgType* getPartialRecv( ) ;
msghdr* getPartialSend( ) ;
int getRecvBuffsize( ) ;
int getSendBuffsize( ) ;
const char* get_host_name( ) const;
int havePartialRecv_p( ) ;
int havePartialWrite_p( ) ;
int incrementConsecutiveTempErrors( ) ;
void markSocketAsOtherHungUp( ) ;
int outMsgsWaiting_p( ) ;
Method: outMsgsWaiting_p Summary: Return true if any queued msgs waiting or if there is a partial write pending; otherwise return false. Description: Return true if any queued msgs waiting or if there is a partial write pending; otherwise return false. Return: true or false.
int readMsg( SockMsgType* msg , int flags = 0 ) ;
6/98 NOTE I've created a bunch of new methods whose names begin with "read" or "write" for receiving or sending messages, respectively. These are the new, PREFERRED methods for reading/writing messages and are intended to replace getMsg, getMsg_blk, sendMessage, sendMessage_blk, (which remain for backward compatibility). The main difference is that they return more informative status/error codes (see enum Socket_Status_Code in streamSock.H for status codes).

Basically, what you want to do with a CONNECTION is read or write msgs. Because of the various options available (explained below), there are several permutations: Blocking/Non-blocking: does method stop (block) until read/write completes, or immediately return a result? Copy/NoCopy: (for writing msgs) if we can write only part of your msg, should we copy the remaining portion or just keep a ptr into your msg storage? Buffer Provided/Not: some read methods will allocate buffers with "new char[msgLen]"; alternately, you can pass in a buffer to hold the recvd msg.

int readMsgIntoBuff( char* permanentMsgBuff , int buffLen , long* msgBytes ) ;
Read msg into user-provided buffer, permanentMsgBuff, return the usual status codes (see readMsg), and set *msgBytes to be #bytes stored in permanentMsgBuff. The provided buffer is called "permanentMsgBuff" because it should be non-stack storage (in case we only get a partial read and have to finish later). Arg buffLen is the size of permanentMsgBuff (in bytes); if the incoming msg is too big, return STREAM_SOCK::USER_BUFF_TOO_SMALL, and set *msgBytes equal to the size of the incoming msg. Then, the user can retrieve this msg by passing in a bigger buffer, or else by calling readMsg (which will allocate a new char[N] buffer). If this returns PARTIAL_MSG_OK, 1 or more additional calls will complete the operation (and return WHOLE_MSG_OK).
int readMsgIntoBuff_blk( char* permanentMsgBuff , int buffLen , long* msgBytes ) ;
Method: readMsgIntoBuff_blk Summary: Read next message (blocking) from connection into user-provided buffer; return status code. Description: Read msg (blocking) into user-provided buffer, permanentMsgBuff, and set *msgBytes to be the number of bytes stored in permanentMsgBuff; return a status code. Arg buffLen is the size of permanentMsgBuff (in bytes); if the incoming msg is too big, return STREAM_SOCK::USER_BUFF_TOO_SMALL, and set *msgBytes equal to the size of the incoming msg. Then, the user can retrieve this msg by passing in a bigger buffer, or else by calling readMsg (which will allocate a new char[N] buffer). If this returns PARTIAL_MSG_OK, do 1 or more additional calls until you've got the entire msg (return == WHOLE_MSG_OK). The provided buffer is called "permanentMsgBuff" because it must remain intact in case there is a partial receive that will be completed later; this means it should NOT be stack storage (unless you're certain you'll complete the read before exiting the function). Return: returns one of the following STREAM_SOCK:: enums (see streamSock.H): WHOLE_MSG_OK : entire msg read; everything is OK USER_BUFF_TOO_SMALL: buffer is too small to hold in- coming msg; redo the call with a bigger buffer or call readMsg (which will allocate one for you). ZERO_BYTES_READ: read 0 bytes; if select says sock is readable but we get 0 bytes, this means that the connection has been closed by the peer. MSG_TOO_BIG: incoming msg bigger than MAX_MSG_BYTES (100 MEG!); probably a mangled msg. TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed conn) BAD_PTR_OR_ARG: Bad msg buff pointer NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what is wrong; better bail out.
int readMsg_blk( SockMsgType* msg , int flags = 0 ) ;
Method: readMsg_blk
Summary: Block until next msg read from connection; return status
         code.
Description: Does a blocking read of the next msg 
             from the connection into the SockMsgType pointed to
             by arg, msg (basically just a char* and #bytes).
             Returns a status code indicating what happened. 
             Will either get the entire message, or else
             return an error code.
Return: returns one of the following STREAM_SOCK:: enums
        (see streamSock.H):
        WHOLE_MSG_OK  :   entire msg read;  everything is OK
        MSG_TOO_BIG: incoming msg bigger than MAX_MSG_BYTES 
          (100 MEG!);  probably a mangled msg.
        TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, 
          interupted call) that _may_ fix itself
        BAD_SOCK:  Bad file descriptor for connection (probably
          closed conn)
        BAD_PTR_OR_ARG:  Bad internal pointer
        NOT_YET_CONNECTED: Possibly socket is ok, but still 
          doing connection internal work
        CLOSED_CONN: Connection is closed
        UNKNOWN_SOCK_ERROR:  Don't know what is wrong;  better 
          bail out.
void resetConsecutiveTempErrors( ) ;
int resumePartialSend( ) ;
Try to complete sending of last partial send. Return true if rest of msg has been sent; false otherwise. Use this fcn repeatedly until entire msg is sent.
int resumePartialWrite( ) ;
Method: resumePartialWrite Summary: Try to finish writing the last message (which resulted in a partial write); return status code. Description: resumePartialWrite attempts to complete the last partial write operation, and returns a status code. A call to this method may itself result in a part- ial send, so it may take more than 1 call to get the whole message out. Since the state of a partial send is recorded internally, no args are needed. Note the asymmetry between the reads and the writes in that there is NO analogous "resumeRead" method. This method was necessary to avoid compli- cations resulting from trying to write a new msg when there is a pending partial write. Return: returns one of the following STREAM_SOCK:: enums (see streamSock.H): WHOLE_MSG_OK : entire msg sent; everything is OK PARTIAL_MSG_OK: part msg sent; everything OK. Complete this operation with calls to resumePartialwrite. TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed connection) BAD_PTR_OR_ARG: Bad pointer or msg length arg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what is wrong; better quit.
int resumePartialWrite_blk( ) ;
Method: resumePartialWrite_blk
Summary: Block until finished writing the last, partially-sent
         message;  return status code.
Description: resumePartialWrite_blk attempts to complete the last
             partial write operation, and returns a status code.
             Since the state of a partial
             send is recorded internally, no args are needed.
Return: returns one of the following STREAM_SOCK:: enums
        (see streamSock.H):
WHOLE_MSG_OK  :  entire msg sent;  everything is OK
TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted 
                   call) that _may_ fix itself
BAD_SOCK:  Bad file descriptor for connection (probably closed 
           connection)
BAD_PTR_OR_ARG:  Bad pointer or msg length arg
NOT_YET_CONNECTED: Possibly socket is ok, but still doing 
                   connection internal work
CLOSED_CONN: Connection is closed
UNKNOWN_SOCK_ERROR:  Don't know what is wrong;  better quit
void scheduleSend( char* msg , int len ) ;
Method: scheduleSend
Summary: Same as scheduleWrite
Description: Old name for scheduleWrite (kept around for back-
             wards compatibility).
Return: None
void scheduleWrite( char* msg , int len ) ;
Method: scheduleWrite Summary: Put msg on a queue to be sent out later using method sendQueuedMsgs; if nothing waiting, send immediately. Description: Use this method to queue-up outgoing messages until it is convenient to send them with sendQueuedMsgs. If the queue is empty and there is no pending partial write, just send msg immediately. Queued msgs are COPIED so you may delete msg right after the call. To avoid copying, see scheduleWriteNoCopy. Return: None.
void scheduleWriteNoCopy( char* permMsgBuff , int len , int deleteMsg_p ) ;
Method: scheduleWriteNoCopy Summary: Put msg on a queue to be sent out later using method sendQueuedMsgs; if nothing waiting, send immediately. Description: Use this method to queue-up outgoing messages until it is convenient to send them with sendQueuedMsgs. If the queue is empty and there is no pending partial write, just send msg immediately. Queued msgs are NOT COPIED so make sure permMsgBuff points to "permanent" storage (ie will not get trashed before sendQueuedMsgs is called). The arg, deleteMsg_p, when true, means that your msg will be deleted when we're done with it (so make sure permMsgBuff was allocated as permMsgBuff = new char[len]). Otherwise, you must delete it yourself. Return: None.
int sendMessage( char* msg , int len ) ;
Method: 
Summary: 
Description: 
Return: 
int sendMessage_blk( char* msg , int len ) ;
Blocking version of sendMessage:
int sendQueuedMsgs( ) ;
Method: sendQueuedMsgs Summary: Finish partial write (if nec) and try to send all queued msgs (non-blocking); return status code. Description: First tries to complete a partial write, if there is one, and then attempts to write all enqueued msgs. Since this is non-blocking, it will return immediately if a resource is blocked (eg full unix buffer), and therefore not necessarily send out all queued msgs. Return: returns one of the following STREAM_SOCK:: enums (see streamSock.H): WHOLE_MSG_OK : entire _queue_ sent; everything is OK PARTIAL_MSG_OK: part of _queue_ sent; everything OK. TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed connection) BAD_PTR_OR_ARG: Bad pointer or msg length arg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what is wrong; better quit.
int sendQueuedMsgs_blk( ) ;
Method: sendQueuedMsgs_blk
Summary: Finish partial write (if nec) and try to send all queued
         msgs (blocking);  return status code.
Description: First tries to complete a partial write, if there is
             one, and then attempts to write all enqueued msgs.
             Since this is non-blocking, it will either
             send the entire queue or else return and error
             code.
Return: returns one of the following STREAM_SOCK:: enums
        (see streamSock.H):
WHOLE_MSG_OK  :  entire _queue_ sent;  everything is OK
TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted 
                   call) that _may_ fix itself
BAD_SOCK:  Bad file descriptor for connection (probably closed 
           connection)
BAD_PTR_OR_ARG:  Bad pointer or msg length arg
NOT_YET_CONNECTED: Possibly socket is ok, but still doing 
                   connection internal work
CLOSED_CONN: Connection is closed
UNKNOWN_SOCK_ERROR:  Don't know what is wrong;  better quit
void setConnGroup( SERVICE_GROUP* cgroup ) ;
int setMaxUnixBuffers( ) ;
Set unix send/recv buffers to max; return 0 if ok.
void setNoPartialRecv( ) ;
void setPartialRecv( SockMsgType* partMsg ) ;
void setPartialSend( msghdr* partMsg ) ;
int setRecvBuffsize( int sizeInBytes ) ;
Set unix internal recv buff; return 0 if ok.
int setSendBuffsize( int sizeInBytes ) ;
Set unix internal send buff; return 0 if ok.
int writeMsg( char* msg , int len ) ;
Method: writeMsg Summary: Send len bytes pointed to by arg, msgBuff, to peer (non-blocking); return status code. Description: Send len bytes pointed to by arg, msgBuff, down connection (non-blocking); return status code. If you get a partial write (returns PARTIAL_MSG_OK), the state of the operation is kept internally and must be completed before beginning another write; call resumePartialwrite 1 or more times to finish a partial write. Return: returns one of the following STREAM_SOCK:: enums (see streamSock.H): WHOLE_MSG_OK : entire msg sent; everything is OK PARTIAL_MSG_OK: part msg sent; everything OK. Complete this operation with calls to resumePartialwrite. TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed connection) BAD_PTR_OR_ARG: Bad pointer or msg length arg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what is wrong; better quit.
msg
len
Method: writeMsgNoCopy Summary: Send len bytes pointed to by arg, permMsgBuff, to peer (non-blocking); return status code. In case of partial write, do NOT copy remainder from permMsgBuff. Description: Send len bytes pointed to by arg, msgBuff, to peer (non-blocking); return status code. If you get a partial write (returns PARTIAL_MSG_OK), the state of the operation is kept internally; in this case we will NOT copy the remaining bytes, but will just keep a pointer into permMsgBuff until the write can be finished (with 1 or more calls to resumePartialWrite), so make sure permMsgBuff points to permanent storage. The arg, deletePermMsg_p, if true, means that this method will delete the storage when done with it using : delete[] (char *) permMsgBuff; So permMsgBuff must be allocated as new char[N] if you want to use this option; otherwise delete it yourself. Return: returns one of the following STREAM_SOCK:: enums (see streamSock.H): WHOLE_MSG_OK : entire msg sent; everything is OK PARTIAL_MSG_OK: part msg sent; everything OK. Complete this operation with calls to resumePartialWrite. TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed connection) BAD_PTR_OR_ARG: Bad pointer or msg length arg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what is wrong; better quit.
int writeMsgNoCopy( char* permMsgBuff , int len , int deletePermMsg_p ) ;
Method: writeMsgNoCopy Summary: Send len bytes pointed to by arg, permMsgBuff, to peer (non-blocking); return status code. In case of partial write, do NOT copy remainder from permMsgBuff. Description: Send len bytes pointed to by arg, msgBuff, to peer (non-blocking); return status code. If you get a partial write (returns PARTIAL_MSG_OK), the state of the operation is kept internally; in this case we will NOT copy the remaining bytes, but will just keep a pointer into permMsgBuff until the write can be finished (with 1 or more calls to resumePartialWrite), so make sure permMsgBuff points to permanent storage. The arg, deletePermMsg_p, if true, means that this method will delete the storage when done with it using : delete[] (char *) permMsgBuff; So permMsgBuff must be allocated as new char[N] if you want to use this option; otherwise delete it yourself. Return: returns one of the following STREAM_SOCK:: enums (see streamSock.H): WHOLE_MSG_OK : entire msg sent; everything is OK PARTIAL_MSG_OK: part msg sent; everything OK. Complete this operation with calls to resumePartialWrite. TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed connection) BAD_PTR_OR_ARG: Bad pointer or msg length arg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what is wrong; better quit.
int writeMsgNoCopy_blk( char* permMsgBuff , int len , int deletePermMsg_p ) ;
Method: writeMsgNoCopy_blk Summary: Send len bytes pointed to by arg, permMsgBuff, to peer (blocking); return status code. In case of partial write, do NOT copy remainder from permMsgBuff. Description: Send len bytes pointed to by arg, msgBuff, to peer (non-blocking); return status code. Although a blocking call cannot return a partial write, this can happen internally. In such a case, we will NOT copy the remaining bytes, but will just keep a pointer into permMsgBuff until the write can be finished (with 1 or more calls to resumePartialWrite), so make sure permMsgBuff points to permanent storage. The arg, deletePermMsg_p, if true, means that this method will delete the storage when done with it using : delete[] (char *) permMsgBuff; So permMsgBuff must be allocated as new char[N] if you want to use this option; otherwise delete it yourself. Return: returns one of the following STREAM_SOCK:: enums (see streamSock.H): WHOLE_MSG_OK : entire msg sent; everything is OK TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed connection) BAD_PTR_OR_ARG: Bad pointer or msg length arg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what is wrong; better quit.
int writeMsg_blk( char* msg , int len ) ;
Method: writeMsg_blk
Summary: Send len bytes pointed to by arg, msgBuff, to peer
         (blocking); return status code.
Description: Send len bytes pointed to by arg, msgBuff, to
             peer (blocking); return status code.
Return: returns one of the following STREAM_SOCK:: enums
        (see streamSock.H):
WHOLE_MSG_OK  :  entire msg sent;  everything is OK
TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted 
                   call) that _may_ fix itself
BAD_SOCK:  Bad file descriptor for connection (probably closed 
           connection)
BAD_PTR_OR_ARG:  Bad pointer or msg length arg
NOT_YET_CONNECTED: Possibly socket is ok, but still doing 
                   connection internal work
CLOSED_CONN: Connection is closed
UNKNOWN_SOCK_ERROR:  Don't know what is wrong;  better quit

<<toc >>

class GENERIC_MSG_HEADER

#include "msgHeader.H"

Geb3.98 This class contains the minimum info the server needs to get the msg to the right handler; an application should create its own class that inherits from this one. ServiceType: this specifies the service desired (the server can offer more than one service; see idsOfSrvTypes.H) group: for each service, there can be more than one group of nodes requesting that service (eg 2 simulations, 5 nodes and 8 nodes respectively, asking for comms service, are put in diff groups [we don't want msgs from sim0 going to sim1] handlerNum: # of method that will deal with this message. Bytes: #bytes following the header.

Public Interface

GENERIC_MSG_HEADER GENERIC_MSG_HEADER getBytes
getGroupNum getHandlerNum getSrvType
setBytes setGroupNum setHandlerNum
setSrvType

Public Interface

GENERIC_MSG_HEADER( ) ;
Geb3.98: give these guys bogus vals to avoid accidentally getting legit ones.
GENERIC_MSG_HEADER( int srvTypeID , int groupID , int handler ) ;
geb3.98 new constructor
In order for a msg to get routed to the right service group, we MUST
know the service type# and the group#; we also need to know which handler
to invoke.
int getBytes( ) ;
int getGroupNum( ) ;
int getHandlerNum( ) ;
int getSrvType( ) ;
void setBytes( int b ) ;
void setGroupNum( int grpNum ) ;
void setHandlerNum( int hnum ) ;
void setSrvType( int srvNum ) ;

Public Data

NET_INT bytes;
NET_INT group;
NET_INT handlerNum;
NET_INT serviceType;

<<toc >>

class SERVICE_GROUP : public C_ITEM

#include "serviceGroup.H"

Public Interface

SERVICE_GROUP ~SERVICE_GROUP CloseConnection
ConnectionHasBeenClosed addConnection addNewConnection
callHandler dequeueConnection getCurrRecvConn
getCurrSendConn getFirstConnection getNextConnection
nextRecvConn nextSendConn numConnections
setCurrRecvConn setCurrSendConn

Public Interface

enum HandlerStatus

handler_ok
delete_this_group
SERVICE_GROUP( int idnum = NO_ID ) ;
~SERVICE_GROUP( ) ;
virtual void CloseConnection( SERVICE_GROUP::CONNECTION* ) ;
This method can be provided by the user to capture the fact that the connection has been closed. Applications should not delete the connection since this is automatically done later for you.
HandlerStatus ConnectionHasBeenClosed( SERVICE_GROUP::CONNECTION* conn ) ;
This method is called when a connection is closed. It calls the CloseConnection() virtual function provided by the user, cleans up its own internal storage of the connection, and then deletes the connection class.
void addConnection( SERVICE_GROUP::CONNECTION* conn ) ;
void addNewConnection( int connectFD , int port ) ;
void callHandler( SERVICE_GROUP::CONNECTION* conn , SockMsgType& msg ) ;
void dequeueConnection( SERVICE_GROUP::CONNECTION* conn ) ;
CONNECTION* getCurrRecvConn( ) ;
CONNECTION* getCurrSendConn( ) ;
CONNECTION* getFirstConnection( ) ;
CONNECTION* getNextConnection( SERVICE_GROUP::CONNECTION* conn ) ;
CONNECTION* nextRecvConn( ) ;
CONNECTION* nextSendConn( ) ;
int numConnections( ) ;
void setCurrRecvConn( SERVICE_GROUP::CONNECTION* conn ) ;
void setCurrSendConn( SERVICE_GROUP::CONNECTION* conn ) ;

Public Data

int GroupID;
int ServiceTypeID;
Which service grp a msg gets routed to is determined by the PAIR (ServiceTypeID, GroupID); eg 3 sims request comms service so their associated sets of nodes will be put into 3 SERVICE_GROUP objs, each having a different GroupID.

<<toc >>

class STREAM_SOCK

#include "streamSock.H"

Public Interface

STREAM_SOCK STREAM_SOCK ~STREAM_SOCK
bindSock closeSock closeSock
dataReadyForRead_p doInternalMsg getfd
isBlocking_p isBlocking_p nb_send_data
readMsgIntoBuff receiveMsg receive_data
recvMsg_blk resumePartialSend resumeReadMsgIntoBuff
resumeRecvMsg sendCloseConnectMsg sendInternalMsg
sendMsg send_data setBlocking
setNoDelay setNonBlocking set_blocking
set_nodelay set_nonblocking unset_nodelay
ErrorStatus FatalErrorStatus NonFatalErrorStatus
OKStatus PartialMsg getMsgHeader
nb_receive_data peekAtReceive

Public Interface

enum Socket_Status_Code

Status codes. Note the ERR_OKCODE_SEPARATOR; all errors MUST be less than this and all other "OK" codes MUST be greater (see ErrorStatus, OKStatus methods) A similar separation has been done for fatal/non-fatal errors.
CLOSED_CONN=-100
Connection is closed.
BAD_SOCK
Bad file descriptor for connection (probably closed conn).
BAD_PTR_OR_ARG
Bad ptr in sendmsg msghdr or bad msg size arg to sendmsg.
NOT_YET_CONNECTED
Possibly socket is ok, but still doing connection internal work.
MSG_TOO_BIG
Received msg internal hdr mangled (#bytes > MAX_MSG_BYTES!).
UNKNOWN_SOCK_ERROR
Don't know what the hell is wrong; better bail out.
BAD_INTERNAL_MSG
Unrecognized internal msg (probably mangled).
FATAL_NONFATAL_SEPARATOR
Separates fatal errs from non-fatal.
ZERO_BYTES_READ
Read 0 bytes (means closed conn is SELECT said ready-to-read).
TEMP_SOCK_PROBLEM
Eg Unix buffer full; temporary problem that MAY go away.
USER_BUFF_TOO_SMALL
User buff too small to hold incoming msg in readMsgIntoBuff or resumeReadMsgIntoBuff.
ERR_OKCODE_SEPARATOR=0
Separates errors from other status codes.
WHOLE_MSG_OK
Read/wrote entire msg.
PARTIAL_MSG_OK
Read/wrote partial msg.
INTERNAL_HEADER_OK
Read/wrote internal msg header.
PARTIAL_INTERNAL_HDR_OK
Read/wrote partial msg header.
INTERNAL_MSG_DONE
Read & executed internal msg.
NO_MSGS_SENT
Haven't sent any messages.
STREAM_SOCK( int port = DEFAULT_PORT ) ;
STREAM_SOCK( int fd , int port ) ;
Kludgestructor used by CONNECTION so that we don't automatically open up a new socket as in the 1-arg constructor above:
~STREAM_SOCK( ) ;
void bindSock( u_short portNum = DEFAULT_PORT , u_long inetAddr = ( ( unsigned long int ) 0x00000000 ) ) ;
Bind (port, ipAddr) to socket. This pair uniquely specifies a location for clients to connect to. The default INADDR_ANY means "accept connections via ANY of the network inter- faces on this machine".
int closeSock( ) ;
int closeSock( int fd ) ;
int dataReadyForRead_p( ) ;
int doInternalMsg( internalMsgHdr* hdr ) ;
int getfd( ) ;
int isBlocking_p( ) ;
Is THIS STREAM_SOCK blocking?
int isBlocking_p( int sock ) ;
Not static anymore.
int nb_send_data( int sock , char* buff , int bytes , int flags = 0 ) ;
int readMsgIntoBuff( int connfd , SockMsgType* msg , char* buff , int buffSize , long* msgBytes ) ;
ReadMsgIntoBuff Same as receiveMsg except the user must provide a PERMANENT (non-stack) buffer into which the msg will be read. The arg, buffSize, gives the size in bytes of buff; if the incoming msg is too big, returns USER_BUFF_TOO_SMALL and sets *msgBytes to be the size of the msg. At this point, the user can get a bigger buffer and call resumeReadMsgIntoBuff (since the internal header has already been read, we must "resume" the receive), or else call resumeRecvMsg (which will allocate a sufficient buffer by itself). If there is a partial read (return PARTIAL_MSG_OK), *msgBytes will be set to the number of bytes read thus far. If we cannot even read the internal hdr (and therefore do not know the msg length yet), *msgBytes is set to -1.
int receiveMsg( int connfd , SockMsgType* msg , int flags = 0 ) ;
ReceiveMsg Returns one of the following: WHOLE_MSG_OK : entire msg sent; everything is OK PARTIAL_MSG_OK: part msg sent; everything OK ZERO_BYTES_READ: read 0 bytes; if select says sock is readable but we get 0 bytes, this means that the connection has been closed by the peer. MSG_TOO_BIG: incoming msg bigger than MAX_MSG_BYTES (100 MEG!); probably mangled msg TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed conn) BAD_PTR_OR_ARG: Bad ptr in sendmsg msghdr or bad msg size arg to sendmsg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what the hell is wrong; better bail out.
int receive_data( int socket , char* buffer , long length , int flags = 0 ) ;
int recvMsg_blk( int connfd , SockMsgType* msg , int flags ) ;
Jacob thinks no one calls this: SockMsgType receiveMsg(int connfd, int flags=0);
int resumePartialSend( int connfd , msghdr* mh , int flags = 0 ) ;
resumePartialSend: continue the partial send via connfd.  mh was
set previously by a sendMsg call and contains the state of the
suspended send.
Return vals:  same as sendMsg
int resumeReadMsgIntoBuff( int connfd , SockMsgType* partMsg , char* mbuff , int buffSize , long* msgBytes ) ;
ResumeReadMsgIntoBuff This is the partner to readMsgIntoBuff. It attempts to finish reading a partially-received msg (which may require 2 or more calls). Note that this fcn can also return USER_BUFF_TOO_SMALL (this will occur when readMsgIntoBuff cannot even get an entire internal msg hdr and so resumeReadMsgIntoBuff first determines that there is not enough space in the user buffer).
int resumeRecvMsg( int connfd , SockMsgType* partMsg , int flags = 0 ) ;
ResumeRecvMsg Resume receiving partial msg; return TRUE if got rest of msg Returns one of the following: WHOLE_MSG_OK : entire msg sent; everything is OK PARTIAL_MSG_OK: part msg sent; everything OK ZERO_BYTES_READ: read 0 bytes; if select says sock is readable but we get 0 bytes, this means that the connection has been closed by the peer. TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed conn) BAD_PTR_OR_ARG: Bad ptr in sendmsg msghdr or bad msg size arg to sendmsg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what the hell is wrong; better bail out.
void sendCloseConnectMsg( ) ;
int sendInternalMsg( internalMsgHdr& hdr ) ;
int sendMsg( int connfd , char* msg , int len , msghdr* mh , long* hdrSpace , int flags = 0 ) ;
SenMsg: send msg thru connection denoted by connfd. The msg is defined by args msg and len. The arg mh is an OUT param which is used in case of a partial send. It contains all the info needed to resume the send when the write buffer clears (see resumePartailSend). The arg, "hdrSpace," is a permanent buffer that will be used to store the internal msg header. The reason it's an arg is because it needs to be "permanent" in case of a partial send, and this is more efficient than doing a "new" and "delete" 99% of the time. Make sure it has at least HEADER_SIZE bytes. Returns one of the following: WHOLE_MSG_OK : entire msg sent; everything is OK PARTIAL_MSG_OK: part msg sent; everything OK TEMP_SOCK_PROBLEM: temporary problem (eg full buffer, interupted call) that _may_ fix itself BAD_SOCK: Bad file descriptor for connection (probably closed conn) BAD_PTR_OR_ARG: Bad ptr in sendmsg msghdr or bad msg size arg to sendmsg NOT_YET_CONNECTED: Possibly socket is ok, but still doing connection internal work CLOSED_CONN: Connection is closed UNKNOWN_SOCK_ERROR: Don't know what the hell is wrong; better bail out.
int send_data( int socket , char* buffer , int length , int flags = 0 ) ;
int setBlocking( ) ;
Make THIS streamSock blocking (set_blocking(sock) makes ANY sock file descriptor blocking).
int setNoDelay( ) ;
int setNonBlocking( ) ;
Make THIS streamSock non-blocking (set_nonblocking(sock) makes ANY sock file descriptor non-blocking).
int set_blocking( int sock ) ;
Not static anymore.
sock
Not static anymore.
int set_nodelay( int sock ) ;
int set_nonblocking( int sock ) ;
sock
Not static anymore.
int unset_nodelay( int sock ) ;
static int ErrorStatus( int status ) ;
static int FatalErrorStatus( int status ) ;
static int NonFatalErrorStatus( int status ) ;
static int OKStatus( int status ) ;
static int PartialMsg( int status ) ;
static int getMsgHeader( int connfd , internalMsgHdr* mhdr ) ;
static int nb_receive_data( int sock , char* buff , long bytes , int flags = 0 ) ;
static int peekAtReceive( int sock , char* buff , int bytes ) ;

<<toc >>

class SockMsgType : public C_ITEM

#include "sockMsgType.H"

Public Interface

SockMsgType SockMsgType deleteMsgBuff
emptyMsgp getBytesRecvd getDeleteBuff_p
getHdrBytesRecvd getMsgBuff getMsgLength
havePartialHdr_p partialMsgp savePartialHdr
setBytesRecvd setDeleteBuff_p setHdrBytesRecvd
setMsgBuff setMsgLength

Public Interface

SockMsgType( char* buf = ( ( void* ) 0 ) , int len = 0 ) ;
SockMsgType( char* buf , int len , int deleteIt_p ) ;
Geb5.98 whole fcn.
void deleteMsgBuff( ) ;
Geb5.98.
int emptyMsgp( ) ;
int getBytesRecvd( ) ;
int getDeleteBuff_p( ) ;
int getHdrBytesRecvd( ) ;
Geb3.98 must have "[]"!.
char* getMsgBuff( ) ;
int getMsgLength( ) ;
int havePartialHdr_p( ) ;
int partialMsgp( ) ;
void savePartialHdr( long* hdr , int hdrLen , int hdrBytesRead ) ;
void setBytesRecvd( long nbytes ) ;
void setDeleteBuff_p( int deleteIt_p ) ;
Geb5.98.
void setHdrBytesRecvd( int hdrBytesRecvd ) ;
void setMsgBuff( char* pt ) ;
void setMsgLength( long len ) ;

<<toc

class internalMsgHdr

#include "internalMsgHdr.H"

So far a header is just the msg type and length; but this struct enables me to add more later:

Public Interface

internalMsgHdr internalSockMsg_p makeCloseConnectMsg
packMsgHeader unpackHeader userMsg_p

Public Interface

USER_MSG=0
CLOSE_CONN
internalMsgHdr( long size = - 1 ) ;
int internalSockMsg_p( ) ;
void makeCloseConnectMsg( ) ;
void packMsgHeader( long* hdr ) ;
hdr
Geb3.98: long * instead of char *!.
void unpackHeader( long* hdr ) ;
Geb3.98: long * instead of char *!.
hdr
Geb3.98: long * instead of char *!.
int userMsg_p( ) ;
Geb3.98: long * instead of char *!.

Public Data

long int MsgType;
Socket internal or user.
long int NumBytes;