socket/xmlBlasterSocket.c File Reference

#include <stdio.h>
#include <string.h>
#include <socket/xmlBlasterSocket.h>

Include dependency graph for xmlBlasterSocket.c:

Go to the source code of this file.

Functions

void closeSocket (int fd)
ssize_t writen (int fd, char *ptr, size_t nbytes)
 Write the given amount of bytes to socket.
ssize_t readn (int fd, char *ptr, size_t nbytes, XmlBlasterNumReadFunc fpNumRead, void *userP)
 Read the given amount of bytes from socket.
int xbl_isOneway (XMLBLASTER_MSG_TYPE msgType, char *methodName)
 Check if the given arguments mark a oneway message.
BlobHolder encodeMsgUnit (MsgUnit *msgUnit, int debug)
 Creates a raw blob to push over a socket as described in protocol.socket.
BlobHolder encodeMsgUnitArr (MsgUnitArr *msgUnitArr, int debug)
 Creates a raw blob to push over a socket as described in protocol.socket.
char * encodeSocketMessage (enum XMLBLASTER_MSG_TYPE_ENUM msgType, char *requestId, char *methodName, char *secretSessionId, char *data, size_t dataLen, int debug, size_t *rawMsgLen)
int parseSocketData (int xmlBlasterSocket, XmlBlasterReadFromSocketFuncHolder *fpHolder, SocketDataHolder *socketDataHolder, XmlBlasterException *exception, int *stopP, int udp, int debug)
 Read a message from the given socket.
void convertToXmlBlasterException (XmlBlasterBlob *blob, XmlBlasterException *exception, int debug)
 The blob data is copied into the given exception object.
void encodeXmlBlasterException (XmlBlasterBlob *blob, XmlBlasterException *exception, int debug)
 The given exception is dumped into the blob data.
QosArrparseQosArr (size_t dataLen, char *data)
 Parses the QoS XML string array returned by erase() and unSubscribe().
MsgUnitArrparseMsgUnitArr (size_t dataLen, char *data)
 Parses the userData part of a raw socket message and fills an array of MsgUnit structs.


Function Documentation

void closeSocket ( int  fd  ) 

Definition at line 12 of file xmlBlasterSocket.c.

Referenced by closeAcceptSocket(), shutdownCallbackServer(), and xmlBlasterConnectionShutdown().

void convertToXmlBlasterException ( XmlBlasterBlob blob,
XmlBlasterException exception,
int  debug 
)

The blob data is copied into the given exception object.

Note: exception->remote is always set to true (assuming a remote blob)

Definition at line 494 of file xmlBlasterSocket.c.

References BlobHolder::data, BlobHolder::dataLen, ExceptionStruct::errorCode, ExceptionStruct::message, ExceptionStruct::remote, strncpy0(), trim(), XMLBLASTEREXCEPTION_ERRORCODE_LEN, and XMLBLASTEREXCEPTION_MESSAGE_LEN.

Referenced by postSendEvent(), and sendData().

Here is the call graph for this function:

BlobHolder encodeMsgUnit ( MsgUnit msgUnit,
int  debug 
)

Creates a raw blob to push over a socket as described in protocol.socket.

Parameters:
msgUnit The message which we need to send
debug Pass true for debugging output to stdout
See also:
http://www.xmlblaster.org/xmlBlaster/doc/requirements/protocol.socket.html
Returns:
The raw 'serialized' MsgUnit as a char* in BlobHolder, the caller needs to free() it.

Definition at line 119 of file xmlBlasterSocket.c.

References MsgUnit::content, MsgUnit::contentLen, BlobHolder::data, BlobHolder::dataLen, MsgUnit::key, MsgUnit::qos, and SNPRINTF.

Referenced by encodeXmlBlasterException(), sendResponse(), sendXmlBlasterException(), and xmlBlasterPublish().

BlobHolder encodeMsgUnitArr ( MsgUnitArr msgUnitArr,
int  debug 
)

Creates a raw blob to push over a socket as described in protocol.socket.

Parameters:
msgUnitArr An array of messages
debug Set to true if you wish debugging output to stdout
See also:
http://www.xmlblaster.org/xmlBlaster/doc/requirements/protocol.socket.html
Returns:
The raw 'serialized' MsgUnitArr as a char*, the caller needs to free() it.

Definition at line 176 of file xmlBlasterSocket.c.

References MsgUnit::contentLen, BlobHolder::dataLen, MsgUnitStructArr::len, MsgUnitStructArr::msgUnitArr, and snprintf0().

Referenced by xmlBlasterPublishArr(), and xmlBlasterPublishOneway().

Here is the call graph for this function:

char* encodeSocketMessage ( enum XMLBLASTER_MSG_TYPE_ENUM  msgType,
char *  requestId,
char *  methodName,
char *  secretSessionId,
char *  data,
size_t  dataLen,
int  debug,
size_t *  rawMsgLen 
)

Definition at line 249 of file xmlBlasterSocket.c.

References MAX_METHODNAME_LEN, MAX_SESSIONID_LEN, MSG_FLAG_POS_TYPE, MSG_FLAG_POS_VERSION, MSG_LEN_FIELD_LEN, MSG_POS_REQESTID, snprintf0(), toReadableDump(), and XMLBLASTER_SOCKET_VERSION.

Referenced by sendData(), sendResponse(), and sendXmlBlasterException().

Here is the call graph for this function:

void encodeXmlBlasterException ( XmlBlasterBlob blob,
XmlBlasterException exception,
int  debug 
)

The given exception is dumped into the blob data.

Parameters:
blob The encoded exception, you need to free the blob struct yourself after usage with freeBlobHolderContent(&blob);
exception The given exception struct
debug Print output to stdout

Definition at line 515 of file xmlBlasterSocket.c.

References BlobHolder::data, BlobHolder::dataLen, encodeMsgUnit(), ExceptionStruct::errorCode, MsgUnit::key, ExceptionStruct::message, and MsgUnit::qos.

Referenced by handleMessage().

Here is the call graph for this function:

MsgUnitArr* parseMsgUnitArr ( size_t  dataLen,
char *  data 
)

Parses the userData part of a raw socket message and fills an array of MsgUnit structs.

Returns:
The messages (never NULL), you need to free them after usage with freeMsgUnitArr(MsgUnitArr *)

Definition at line 553 of file xmlBlasterSocket.c.

References MsgUnit::content, MsgUnit::contentLen, MsgUnitStructArr::isOneway, MsgUnit::key, MsgUnitStructArr::len, MsgUnitStructArr::msgUnitArr, MsgUnit::qos, strcpyAlloc(), strncpy0(), strToULong(), and trim().

Referenced by parseQosArr(), and xmlBlasterGet().

Here is the call graph for this function:

QosArr* parseQosArr ( size_t  dataLen,
char *  data 
)

Parses the QoS XML string array returned by erase() and unSubscribe().

Returns:
The returned status QoS, never null, needs to be freed with freeQosArr() after usage.

Definition at line 534 of file xmlBlasterSocket.c.

References freeMsgUnitArr(), QosStructArr::len, MsgUnitStructArr::len, MsgUnitStructArr::msgUnitArr, parseMsgUnitArr(), MsgUnit::qos, QosStructArr::qosArr, and strcpyAlloc().

Referenced by xmlBlasterErase(), and xmlBlasterUnSubscribe().

Here is the call graph for this function:

int parseSocketData ( int  xmlBlasterSocket,
XmlBlasterReadFromSocketFuncHolder fpHolder,
SocketDataHolder socketDataHolder,
XmlBlasterException exception,
int *  stopP,
int  udp,
int  debug 
)

Read a message from the given socket.

This method blocks until data arrives.

Parameters:
xmlBlasterSocket The socket to read data from (needs to be valid)
fpHolder Struct containing the function pointer which access the socket to read from (if necessary decompressing on the fly)
socketDataHolder The struct to put the parsed message into (needs to be allocated by you or on your stack)
exception The struct to put exceptions into (needs to be allocated by you or to be on your stack)
stopP The *stopP may change to 'true' during receiv() blocking
udp true if it is a UDP connection
debug Set to true to have debugging output on console
Returns:
true: A messages is parsed and put into your socketDataHolder, you need to free(socketDataHolder->data) after working with it. Please check socketDataHolder->type if it is an exception. false: The socket is closed (EOF)

Definition at line 330 of file xmlBlasterSocket.c.

References SocketDataHolder::blob, BlobHolder::data, BlobHolder::dataLen, SocketDataHolder::dataLenUncompressed, ExceptionStruct::errorCode, EXCEPTIONSTRUCT_MESSAGE_LEN, MAX_METHODNAME_LEN, MAX_MSG_LEN, MAX_PACKET_SIZE, MAX_REQUESTID_LEN, MAX_SESSIONID_LEN, ExceptionStruct::message, SocketDataHolder::methodName, MSG_FLAG_POS_TYPE, MSG_FLAG_POS_VERSION, MSG_LEN_FIELD_LEN, MSG_POS_REQESTID, MSG_TYPE_EXCEPTION, MSG_TYPE_INVOKE, MSG_TYPE_RESPONSE, SocketDataHolder::msgLen, XmlBlasterReadFromSocketFuncHolder::numReadFuncP, XmlBlasterReadFromSocketFuncHolder::numReadUserP, XmlBlasterReadFromSocketFuncHolder::readFromSocketFuncP, ExceptionStruct::remote, SocketDataHolder::requestId, SocketDataHolder::secretSessionId, snprintf0(), strncpy0(), strToULong(), toReadableDump(), trim(), SocketDataHolder::type, XmlBlasterReadFromSocketFuncHolder::userP, SocketDataHolder::version, XMLBLASTER_SOCKET_VERSION, and XMLBLASTEREXCEPTION_ERRORCODE_LEN.

Referenced by getResponse(), and readMessage().

Here is the call graph for this function:

ssize_t readn ( int  fd,
char *  ptr,
size_t  nbytes,
XmlBlasterNumReadFunc  fpNumRead,
void *  userP 
)

Read the given amount of bytes from socket.

This method blocks until data arrives, we loop as the low level recv() can return when the socket buffer is empty but not all data expected arrived.

This code is not thread safe, you need to add a mutex to your calling code if two threads simultaneously want to read from the same socket 'fd'.

Parameters:
fd The socket descriptor
ptr A buffer which is big enough to hold nbytes
nbytes The number of bytes to read
fpNumRead Function pointer, if not null we make a callback about the progress
userP Is bounced back to fpNumRead
Returns:
number of bytes read, -1 is EOF
Author:
W. Richard Stevens

Definition at line 68 of file xmlBlasterSocket.c.

Referenced by readnPlain().

ssize_t writen ( int  fd,
char *  ptr,
size_t  nbytes 
)

Write the given amount of bytes to socket.

This method blocks until data all data is sent, we loop as the low level write() can return when the socket buffer is full but not all data expected are sent.

This code is not thread safe, you need to add a mutex to your calling code if two threads simultaneously want to read from the same socket 'fd'.

Returns:
number of bytes written, -1 is EOF
Author:
W. Richard Stevens

Definition at line 33 of file xmlBlasterSocket.c.

Referenced by writenPlain(), and xmlBlaster_writenCompressed().

int xbl_isOneway ( XMLBLASTER_MSG_TYPE  msgType,
char *  methodName 
)

Check if the given arguments mark a oneway message.

Parameters:
msgType The message type like MSG_TYPE_INVOKE
methodName The name of the invoked message like "publish", can be null
Returns:
if true it is treated as oneway

Definition at line 100 of file xmlBlasterSocket.c.

References MSG_TYPE_EXCEPTION, MSG_TYPE_RESPONSE, and XMLBLASTER_PUBLISH_ONEWAY.

Referenced by preSendEvent(), and sendData().