socket/xmlBlasterSocket.h File Reference

#include <stdlib.h>
#include <util/basicDefs.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <util/msgUtil.h>

Include dependency graph for xmlBlasterSocket.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SocketDataHolder
 Helper struct to hold all necessary informations. More...

Defines

#define MAX_MSG_LEN   1000000000
#define MSG_LEN_FIELD_LEN   10
#define MAX_PACKET_SIZE   10*1024
#define MSG_FLAG_FIELD_LEN   6
#define XMLBLASTER_SOCKET_VERSION   49

Typedefs

typedef enum XMLBLASTER_MSG_TYPE_ENUM XMLBLASTER_MSG_TYPE
 Settings for MSG_FLAG_POS_TYPE.

Enumerations

enum  XMLBLASTER_MSG_TYPE_ENUM { MSG_TYPE_INVOKE = 73, MSG_TYPE_RESPONSE = 82, MSG_TYPE_EXCEPTION = 69 }
 Settings for MSG_FLAG_POS_TYPE. More...
enum  MSG_FLAG_POS_ENUM {
  MSG_FLAG_POS_CHECKSUM = 10, MSG_FLAG_POS_COMPRESS, MSG_FLAG_POS_TYPE, MSG_FLAG_POS_RESERVED1,
  MSG_FLAG_POS_RESERVED2, MSG_FLAG_POS_VERSION, MSG_POS_REQESTID
}

Functions

void closeSocket (int fd)
ssize_t writen (const int fd, const char *ptr, const size_t nbytes)
ssize_t readn (const int fd, char *ptr, const size_t nbytes, XmlBlasterNumReadFunc fpNumRead, void *userP)
 Read the given amount of bytes from socket.
int xbl_isOneway (XMLBLASTER_MSG_TYPE msgType, const char *const methodName)
char * encodeSocketMessage (enum XMLBLASTER_MSG_TYPE_ENUM msgType, const char *const requestId, const char *const methodName, const char *const secretSessionId, const char *data, size_t dataLen, int debug, size_t *rawMsgLen)
 Creates a raw blob to push over a socket as described in the protocol.socket requirement.
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.
int parseSocketData (int xmlBlasterSocket, const XmlBlasterReadFromSocketFuncHolder *fpHolder, SocketDataHolder *socketDataHolder, XmlBlasterException *exception, int *stopP, int udp, int debug)
void convertToXmlBlasterException (const XmlBlasterBlob *blob, XmlBlasterException *exception, int debug)
void encodeXmlBlasterException (XmlBlasterBlob *blob, const XmlBlasterException *exception, int debug)
MsgUnitArrparseMsgUnitArr (size_t dataLen, char *data)
 Parses the userData part of a raw socket message and fills an array of MsgUnit structs.
QosArrparseQosArr (size_t dataLen, char *data)
 Parses the QoS XML string array returned by erase() and unSubscribe().


Define Documentation

#define MAX_MSG_LEN   1000000000

Definition at line 49 of file xmlBlasterSocket.h.

Referenced by parseSocketData().

#define MAX_PACKET_SIZE   10*1024

Definition at line 77 of file xmlBlasterSocket.h.

Referenced by parseSocketData().

#define MSG_FLAG_FIELD_LEN   6

Definition at line 78 of file xmlBlasterSocket.h.

#define MSG_LEN_FIELD_LEN   10

Definition at line 76 of file xmlBlasterSocket.h.

Referenced by encodeSocketMessage(), and parseSocketData().

#define XMLBLASTER_SOCKET_VERSION   49

Definition at line 90 of file xmlBlasterSocket.h.

Referenced by encodeSocketMessage(), parseSocketData(), and sendData().


Typedef Documentation

typedef enum XMLBLASTER_MSG_TYPE_ENUM XMLBLASTER_MSG_TYPE

Settings for MSG_FLAG_POS_TYPE.


Enumeration Type Documentation

enum MSG_FLAG_POS_ENUM

Enumerator:
MSG_FLAG_POS_CHECKSUM 
MSG_FLAG_POS_COMPRESS 
MSG_FLAG_POS_TYPE 
MSG_FLAG_POS_RESERVED1 
MSG_FLAG_POS_RESERVED2 
MSG_FLAG_POS_VERSION 
MSG_POS_REQESTID 

Definition at line 80 of file xmlBlasterSocket.h.

enum XMLBLASTER_MSG_TYPE_ENUM

Settings for MSG_FLAG_POS_TYPE.

Enumerator:
MSG_TYPE_INVOKE 
MSG_TYPE_RESPONSE 
MSG_TYPE_EXCEPTION 

Definition at line 54 of file xmlBlasterSocket.h.


Function Documentation

void closeSocket ( int  fd  ) 

Definition at line 12 of file xmlBlasterSocket.c.

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

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

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,
const char *const  requestId,
const char *const  methodName,
const char *const  secretSessionId,
const char *  data,
size_t  dataLen,
int  debug,
size_t *  rawMsgLen 
)

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

Parameters:
msgType invoke, response or exception
requestId The unique request ID for each invocation
methodName The method name like "PUBLISH"
secretSessionId The authentication string
data is returned
dataLen is returned
debug Pass true for debugging output to stdout
rawMsgLen 
See also:
http://www.xmlblaster.org/xmlBlaster/doc/requirements/protocol.socket.html
Returns:
The raw message, the caller needs to free() it.
Parameters:
requestId  The unique request ID for each invocation

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

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(), MsgUnitStructArr::len, QosStructArr::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,
const XmlBlasterReadFromSocketFuncHolder fpHolder,
SocketDataHolder socketDataHolder,
XmlBlasterException exception,
int *  stopP,
int  udp,
int  debug 
)

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 ( const int  fd,
const char *  ptr,
const size_t  nbytes 
)

int xbl_isOneway ( XMLBLASTER_MSG_TYPE  msgType,
const char *const  methodName 
)