Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

messages.h File Reference

#include <limits.h>
#include <pthread.h>
#include "sockets.h"
#include "../stmt/statement.h"

Include dependency graph for messages.h:

Go to the source code of this file.

Data Structures

struct  VrbProt3Msg
 Message header. More...
struct  VrbProt3Pool
 Pool of values. More...
struct  VrbProt3Value
 Message values. More...

Defines

#define CONN_RECV_TIME_OUT   LONG_MAX
 Receive time-out in microseconds.
#define CONN_SEND_TIME_OUT   LONG_MAX
 Send time-out in microseconds.
#define MSG_V3_PREFIX_CONTEXT_BIT   (0x01 << MSG_V3_PREFIX_CONTEXT)
#define MSG_V3_PREFIX_DEFAULT_BIT   (0x01 << MSG_V3_PREFIX_DEFAULT)
#define MSG_V3_PREFIX_END_BIT   (0x01 << MSG_V3_PREFIX_END)
#define MSG_V3_PREFIX_ERR_BIT   (0x01 << MSG_V3_PREFIX_ERRSTR)
#define MSG_V3_PREFIX_LEN_BIT   (0x01 << MSG_V3_PREFIX_LEN)
#define MSG_V3_PREFIX_LOGIN_BIT   (0x01 << MSG_V3_PREFIX_LOGIN)
#define MSG_V3_PREFIX_MASK_BITS   (MSG_V3_PREFIX_CONTEXT_BIT | MSG_V3_PREFIX_SUBJECT_BIT | MSG_V3_PREFIX_PREDICATE_BIT | MSG_V3_PREFIX_OBJECT_BIT )
#define MSG_V3_PREFIX_NUM_BIT   (0x01 << MSG_V3_PREFIX_NUM)
#define MSG_V3_PREFIX_OBJECT_BIT   (0x01 << MSG_V3_PREFIX_OBJECT)
#define MSG_V3_PREFIX_OPERATION_BIT   (0x01 << MSG_V3_PREFIX_OPERATION)
#define MSG_V3_PREFIX_PREDICATE_BIT   (0x01 << MSG_V3_PREFIX_PREDICATE)
#define MSG_V3_PREFIX_PREV_BIT   (0x01 << MSG_V3_PREFIX_PREV)
#define MSG_V3_PREFIX_START_BIT   (0x01 << MSG_V3_PREFIX_START)
#define MSG_V3_PREFIX_STATEMENT_BITS   (MSG_V3_PREFIX_CONTEXT_BIT | MSG_V3_PREFIX_SUBJECT_BIT | MSG_V3_PREFIX_PREDICATE_BIT | MSG_V3_PREFIX_OBJECT_BIT | MSG_V3_PREFIX_OPERATION_BIT | MSG_V3_PREFIX_PREV_BIT | MSG_V3_PREFIX_START_BIT | MSG_V3_PREFIX_END_BIT )
#define MSG_V3_PREFIX_SUBJECT_BIT   (0x01 << MSG_V3_PREFIX_SUBJECT)
#define MSG_V3_PREFIX_TXN_BIT   (0x01 << MSG_V3_PREFIX_TXN)
#define MSG_V3_PROTO_BAD_VALUE   -234431
#define MSG_V3_PROTO_ERROR   -234422
 Common protocol error.
#define MSG_V3_PROTO_NO_ROOM_FOR_TXN   -234432
 No room for transaction data allocation.
#define MSG_V3_PROTO_NOMEM   -234425
#define MSG_V3_PROTO_NOT_READY   -234429
#define MSG_V3_PROTO_OK   0
 No errors.
#define MSG_V3_PROTO_SOCKET_ERROR   -234424
#define MSG_V3_PROTO_TIMEOUT   -234423
 Socket timeout.
#define MSG_V3_PROTO_UNKNOWN_COMMAND   -234428
#define MSG_V3_PROTO_UNKNOWN_PREFIX   -234427
#define MSG_V3_PROTO_WRONG_MAGIC   -234426
#define MSG_V3_PROTO_WRONG_STATE   -234430
#define SAFE_STR(s)   (s ? s : "")

Enumerations

enum  msgv3_alloc { MSG_V3_ALLOC_SELF, MSG_V3_ALLOC_AUTO }
 Value allocation types. More...
enum  msgv3_command {
  MSG_V3_COMMAND_OK = 0, MSG_V3_COMMAND_FAIL = 1, MSG_V3_COMMAND_SET, MSG_V3_COMMAND_NOP,
  MSG_V3_COMMAND_NOTIFY, MSG_V3_COMMAND_BEGIN, MSG_V3_COMMAND_COMMIT, MSG_V3_COMMAND_ROLLBACK,
  MSG_V3_COMMAND_LOGIN, MSG_V3_COMMAND_LOGOUT, MSG_V3_COMMAND_GET, MSG_V3_COMMAND_BATCHGET,
  MSG_V3_COMMAND_SYNC, MSG_V3_COMMAND_NEWID, MSG_V3_COMMAND_EMPTY, MSG_V3_COMMAND_GETCOUNT,
  MSG_V3_COMMANDS_COUNT
}
 Known v3 commands. More...
enum  msgv3_prefix {
  MSG_V3_PREFIX_DEFAULT = 0, MSG_V3_PREFIX_LEN = 1, MSG_V3_PREFIX_CONTEXT, MSG_V3_PREFIX_PREDICATE,
  MSG_V3_PREFIX_SUBJECT, MSG_V3_PREFIX_OBJECT, MSG_V3_PREFIX_OPERATION, MSG_V3_PREFIX_PREV,
  MSG_V3_PREFIX_NUM, MSG_V3_PREFIX_ERRSTR, MSG_V3_PREFIX_START, MSG_V3_PREFIX_END,
  MSG_V3_PREFIX_TXN, MSG_V3_PREFIX_LOGIN, MSG_V3_PREFIX_FINAL, MSG_V3_PREFIX_CMD,
  MSG_V3_PREFIX_MAGIC, MSG_V3_PREFIXES_COUNT
}
 Known value prefixes. More...

Functions

int msgv3_msg_recv (hsocket sk, msgv3_command *cmd, VrbProt3Pool *pool)
 Receives a message from the socket sk and updates the pool.
int msgv3_msg_send (hsocket sk, msgv3_command cmd, VrbProt3Pool *pool, unsigned int prefix_mask)
 Sends a message to the socket sk.
void msgv3_pool_clear (VrbProt3Pool *pool)
 Clears a pool deallocates all values that have alloc_type set to MSG_V3_ALLOC_AUTO.
int msgv3_pool_get_mask (VrbProt3Pool *pool, Statement *mask)
 Tries to extract masked Statement from the pool if it is ready.
int msgv3_pool_get_statement (VrbProt3Pool *pool, Statement *stmt)
 Tries to extract a Statement information from the pool if it is ready.
void msgv3_pool_get_value (VrbProt3Pool *pool, msgv3_prefix prefix, VrbProt3Value *value)
void msgv3_pool_init (VrbProt3Pool *pool)
 Initializes a pool.
int msgv3_pool_read_value (VrbProt3Pool *pool, msgv3_prefix prefix, unsigned int offset, void *buf, unsigned int size)
 Reads the value from the pool.
int msgv3_pool_set_mask (VrbProt3Pool *pool, const Statement *mask)
 Updates the pool with mask given in mask.
int msgv3_pool_set_statement (VrbProt3Pool *pool, const Statement *stmt)
 Updates the pool with a statement stmt.
void msgv3_pool_update (VrbProt3Pool *pool, VrbProt3Value *value)
 Updates a pool with a value.
void msgv3_value_ensure_string (VrbProt3Value *value)
 Sets the last byte of value to zero.
void msgv3_value_free (VrbProt3Value *value)
 Frees the value buffer if its alloc_type set to auto.
void msgv3_value_init (VrbProt3Value *value, msgv3_alloc alloc, msgv3_prefix prefix, unsigned int size, void *buf)
 Initializes value with prefix and buf.
void msgv3_value_init_integer (VrbProt3Value *value, msgv3_prefix prefix, long integer)
 Initializes a protocol value with integer.
void msgv3_value_init_null (VrbProt3Value *value, msgv3_prefix prefix)
 Initializes a value with null.
void msgv3_value_init_string (VrbProt3Value *value, unsigned char prefix, const char *str)
 Initializes value with string buffer.


Detailed Description


Define Documentation

#define CONN_RECV_TIME_OUT   LONG_MAX
 

Receive time-out in microseconds.

#define CONN_SEND_TIME_OUT   LONG_MAX
 

Send time-out in microseconds.

#define MSG_V3_PREFIX_CONTEXT_BIT   (0x01 << MSG_V3_PREFIX_CONTEXT)
 

#define MSG_V3_PREFIX_DEFAULT_BIT   (0x01 << MSG_V3_PREFIX_DEFAULT)
 

#define MSG_V3_PREFIX_END_BIT   (0x01 << MSG_V3_PREFIX_END)
 

#define MSG_V3_PREFIX_ERR_BIT   (0x01 << MSG_V3_PREFIX_ERRSTR)
 

#define MSG_V3_PREFIX_LEN_BIT   (0x01 << MSG_V3_PREFIX_LEN)
 

#define MSG_V3_PREFIX_LOGIN_BIT   (0x01 << MSG_V3_PREFIX_LOGIN)
 

#define MSG_V3_PREFIX_MASK_BITS   (MSG_V3_PREFIX_CONTEXT_BIT | MSG_V3_PREFIX_SUBJECT_BIT | MSG_V3_PREFIX_PREDICATE_BIT | MSG_V3_PREFIX_OBJECT_BIT )
 

#define MSG_V3_PREFIX_NUM_BIT   (0x01 << MSG_V3_PREFIX_NUM)
 

#define MSG_V3_PREFIX_OBJECT_BIT   (0x01 << MSG_V3_PREFIX_OBJECT)
 

#define MSG_V3_PREFIX_OPERATION_BIT   (0x01 << MSG_V3_PREFIX_OPERATION)
 

#define MSG_V3_PREFIX_PREDICATE_BIT   (0x01 << MSG_V3_PREFIX_PREDICATE)
 

#define MSG_V3_PREFIX_PREV_BIT   (0x01 << MSG_V3_PREFIX_PREV)
 

#define MSG_V3_PREFIX_START_BIT   (0x01 << MSG_V3_PREFIX_START)
 

#define MSG_V3_PREFIX_STATEMENT_BITS   (MSG_V3_PREFIX_CONTEXT_BIT | MSG_V3_PREFIX_SUBJECT_BIT | MSG_V3_PREFIX_PREDICATE_BIT | MSG_V3_PREFIX_OBJECT_BIT | MSG_V3_PREFIX_OPERATION_BIT | MSG_V3_PREFIX_PREV_BIT | MSG_V3_PREFIX_START_BIT | MSG_V3_PREFIX_END_BIT )
 

#define MSG_V3_PREFIX_SUBJECT_BIT   (0x01 << MSG_V3_PREFIX_SUBJECT)
 

#define MSG_V3_PREFIX_TXN_BIT   (0x01 << MSG_V3_PREFIX_TXN)
 

#define MSG_V3_PROTO_BAD_VALUE   -234431
 

#define MSG_V3_PROTO_ERROR   -234422
 

Common protocol error.

#define MSG_V3_PROTO_NO_ROOM_FOR_TXN   -234432
 

No room for transaction data allocation.

#define MSG_V3_PROTO_NOMEM   -234425
 

#define MSG_V3_PROTO_NOT_READY   -234429
 

#define MSG_V3_PROTO_OK   0
 

No errors.

#define MSG_V3_PROTO_SOCKET_ERROR   -234424
 

#define MSG_V3_PROTO_TIMEOUT   -234423
 

Socket timeout.

#define MSG_V3_PROTO_UNKNOWN_COMMAND   -234428
 

#define MSG_V3_PROTO_UNKNOWN_PREFIX   -234427
 

#define MSG_V3_PROTO_WRONG_MAGIC   -234426
 

#define MSG_V3_PROTO_WRONG_STATE   -234430
 

#define SAFE_STR  )     (s ? s : "")
 


Enumeration Type Documentation

enum msgv3_alloc
 

Value allocation types.

Enumerator:
MSG_V3_ALLOC_SELF 
MSG_V3_ALLOC_AUTO 

enum msgv3_command
 

Known v3 commands.

Enumerator:
MSG_V3_COMMAND_OK  OK Response Command.
MSG_V3_COMMAND_FAIL  Fail Response command.
MSG_V3_COMMAND_SET 
MSG_V3_COMMAND_NOP 
MSG_V3_COMMAND_NOTIFY 
MSG_V3_COMMAND_BEGIN 
MSG_V3_COMMAND_COMMIT 
MSG_V3_COMMAND_ROLLBACK 
MSG_V3_COMMAND_LOGIN 
MSG_V3_COMMAND_LOGOUT 
MSG_V3_COMMAND_GET 
MSG_V3_COMMAND_BATCHGET 
MSG_V3_COMMAND_SYNC 
MSG_V3_COMMAND_NEWID 
MSG_V3_COMMAND_EMPTY 
MSG_V3_COMMAND_GETCOUNT 
MSG_V3_COMMANDS_COUNT 

enum msgv3_prefix
 

Known value prefixes.

Enumerator:
MSG_V3_PREFIX_DEFAULT 
MSG_V3_PREFIX_LEN 
MSG_V3_PREFIX_CONTEXT 
MSG_V3_PREFIX_PREDICATE 
MSG_V3_PREFIX_SUBJECT 
MSG_V3_PREFIX_OBJECT 
MSG_V3_PREFIX_OPERATION 
MSG_V3_PREFIX_PREV 
MSG_V3_PREFIX_NUM 
MSG_V3_PREFIX_ERRSTR 
MSG_V3_PREFIX_START 
MSG_V3_PREFIX_END 
MSG_V3_PREFIX_TXN 
MSG_V3_PREFIX_LOGIN 
MSG_V3_PREFIX_FINAL 
MSG_V3_PREFIX_CMD 
MSG_V3_PREFIX_MAGIC 
MSG_V3_PREFIXES_COUNT 


Function Documentation

int msgv3_msg_recv hsocket  sk,
msgv3_command cmd,
VrbProt3Pool pool
 

Receives a message from the socket sk and updates the pool.

int msgv3_msg_send hsocket  sk,
msgv3_command  cmd,
VrbProt3Pool pool,
unsigned int  prefix_mask
 

Sends a message to the socket sk.

Each message consists of a commanad cmd and a number of values. Each value has a prefix and a byte content. There are only several prefixes that have their own meanings. Only one value with a given prefix can be tranferred within a message. The values are preliminary set in the pool. The MSG_V3_PREFIX_mask argument says which values should be sent.

Returns:
zero on success and error value otherwise.

void msgv3_pool_clear VrbProt3Pool pool  ) 
 

Clears a pool deallocates all values that have alloc_type set to MSG_V3_ALLOC_AUTO.

int msgv3_pool_get_mask VrbProt3Pool pool,
Statement mask
 

Tries to extract masked Statement from the pool if it is ready.

int msgv3_pool_get_statement VrbProt3Pool pool,
Statement stmt
 

Tries to extract a Statement information from the pool if it is ready.

Returns:
zero on success and MSG_V3_PROTO_NOT_READY otherwise.

void msgv3_pool_get_value VrbProt3Pool pool,
msgv3_prefix  prefix,
VrbProt3Value value
 

void msgv3_pool_init VrbProt3Pool pool  ) 
 

Initializes a pool.

int msgv3_pool_read_value VrbProt3Pool pool,
msgv3_prefix  prefix,
unsigned int  offset,
void *  buf,
unsigned int  size
 

Reads the value from the pool.

Retruns positive number of bytes actually read

int msgv3_pool_set_mask VrbProt3Pool pool,
const Statement mask
 

Updates the pool with mask given in mask.

int msgv3_pool_set_statement VrbProt3Pool pool,
const Statement stmt
 

Updates the pool with a statement stmt.

void msgv3_pool_update VrbProt3Pool pool,
VrbProt3Value value
 

Updates a pool with a value.

void msgv3_value_ensure_string VrbProt3Value value  ) 
 

Sets the last byte of value to zero.

void msgv3_value_free VrbProt3Value value  ) 
 

Frees the value buffer if its alloc_type set to auto.

void msgv3_value_init VrbProt3Value value,
msgv3_alloc  alloc,
msgv3_prefix  prefix,
unsigned int  size,
void *  buf
 

Initializes value with prefix and buf.

void msgv3_value_init_integer VrbProt3Value value,
msgv3_prefix  prefix,
long  integer
 

Initializes a protocol value with integer.

void msgv3_value_init_null VrbProt3Value value,
msgv3_prefix  prefix
 

Initializes a value with null.

void msgv3_value_init_string VrbProt3Value value,
unsigned char  prefix,
const char *  str
 

Initializes value with string buffer.


Generated on Wed Dec 27 16:52:21 2006 for VRB Online Server by  doxygen 1.4.4