![]() |
botsense
3.2.0
RoadNarrows Client-Server Proxied Services Framework
|
BotSense bsProxy IP server declarations. More...
#include <sys/time.h>
#include <sys/select.h>
#include <stdarg.h>
#include <pthread.h>
#include <errno.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/dlistvoid.h"
#include "rnr/dliststr.h"
#include "rnr/sock.h"
#include "rnr/sockset.h"
#include "rnr/netmsgs.h"
#include "botsense/BotSense.h"
#include "botsense/libBotSense.h"
#include "botsense/bsProxyModIF.h"
#include "botsense/bsProxyMsgs.h"
Go to the source code of this file.
Classes | |
struct | BsProxyModIF_T |
struct | _bsproxy_th_ctl |
struct | BsProxyClientCtl_T |
struct | BsProxyServerCtl_T |
struct | BsProxyVConn_T |
struct | _bsproxy_th_req |
struct | BsProxyListenIF_T |
Macros | |
#define | BSPROXY_TUNE_T_RECV 1000000 |
1.0s receive time out | |
#define | BSPROXY_TUNE_T_SEND 500000 |
0.5s send time out | |
#define | BSPROXY_TUNE_T_SELECT 5000000 |
5.0s send select time out | |
#define | BSPROXY_FD_SETSIZE 256 |
server socket set size | |
#define | BSPROXY_LOG_WARN(hndClient, ecode, wfmt, ...) |
Log Proxy Server Warning. More... | |
#define | BSPROXY_LOG_ERROR(hndClient, ecode, efmt, ...) |
Log Proxy Server Error. More... | |
#define | BSPROXY_LOG_NMERROR(hndClient, nmecode, efmt, ...) |
Log Proxy Server NetMsgs (Un)Packing Error. More... | |
#define | BSPROXY_LOG_SYSERROR(hndClient, efmt, ...) |
Log Proxy Server System Error. More... | |
#define | BSPROXY_SEND_ERROR_RSP(hndClient, hndVConn, uTid, ecode, efmt, ...) |
Log BotSense Error and Send Error Response. More... | |
#define | BSPROXY_SEND_NMERROR_RSP(hndClient, hndVConn, uTid, nmecode, efmt, ...) |
Log NetMsgs (Un)Packing Error and Send Error Response. More... | |
#define | BSPROXY_SEND_SYSERROR_RSP(hndClient, hndVConn, uTid, efmt, ...) |
Log System Error and Send Error Response. More... | |
#define | BSPROXY_LOG_REQ(hndClient, pMsgHdr) |
Log client request. More... | |
#define | BSPROXY_LOG_RSP(hndClient, pMsgHdr) |
Log client request. More... | |
#define | BSPROXY_CHK_VCONN_HND(hndVConn) |
#define | BSPROXY_CHK_MOD_VCONN_HND(hndVConn) |
Typedefs | |
typedef struct _bsproxy_th_ctl * | BsProxyThCtl_P |
service thread control | |
typedef struct _bsproxy_th_req * | BsProxyThReq_P |
service thread request | |
typedef int | BsProxyClientHnd_T |
bsProxy server client handle | |
typedef struct _bsproxy_th_ctl | BsProxyThCtl_T |
typedef struct _bsproxy_th_req | BsProxyThReq_T |
Enumerations | |
enum | BsProxyThState_T { BsProxyThStateUninit, BsProxyThStateInit, BsProxyThStateRunning, BsProxyThStateExit } |
Service thread states. More... | |
enum | BsProxyClientState_T { BsProxyClientStateInit, BsProxyClientStateNominal, BsProxyClientStateReSync, BsProxyClientStateZombie } |
Functions | |
static void | timer_mark (struct timeval *pTvMark) |
Mark the current time. Resolution is microseconds. More... | |
uint_t | timer_elapsed (struct timeval *pTvMark) |
Calculate the elapsed time between the given time mark and this call. More... | |
INLINE_IN_H BsProxyServerCtl_T * | ServerGet () |
Get the BotSense server. More... | |
INLINE_IN_H const char * | ServerHasName () |
Get the BotSense server's official name. More... | |
INLINE_IN_H const char * | ServerHasAddr () |
Get the BotSense server's listening address. More... | |
INLINE_IN_H int | ServerHasPort () |
Get the BotSense server's listening port. More... | |
INLINE_IN_H int | ServerClientHnd2Sd (BsProxyClientHnd_T hndClient) |
Convert the BotSense server client handle to client socket descriptor. More... | |
INLINE_IN_H BsProxyClientHnd_T | ServerClientSd2Hnd (int sd) |
Convert the BotSense server client socket descriptor to client handle. More... | |
INLINE_IN_H BsProxyClientCtl_T * | ServerGetClient (BsProxyClientHnd_T hndClient) |
Get the BotSense server client. More... | |
INLINE_IN_H const char * | ClientThisHasName (BsProxyClientCtl_T *pClient) |
Get this BotSense client official name. More... | |
INLINE_IN_H const char * | ClientHasName (BsProxyClientHnd_T hndClient) |
Get the BotSense client official name. More... | |
INLINE_IN_H bool_t | ClientGetTraceState (BsProxyClientHnd_T hndClient) |
Get the BotSense client's server-terminated message trace state. More... | |
INLINE_IN_H void | ClientSetTraceState (BsProxyClientHnd_T hndClient, bool_t bTrace) |
Set the BotSense client's server-terminated message trace state. More... | |
void | BsProxyLogMsgHdr (const char *sPreface, BsProxyMsgHdr_T *pMsgHdr) |
Log message header. More... | |
void | ClientOneTimeInit () |
The BotSense bsProxy server one-time client control initialization. | |
BsProxyClientCtl_T * | ClientAcquire (BsProxyClientHnd_T hndClient) |
Acquire client, locking it from other threads. More... | |
void | ClientRelease (BsProxyClientHnd_T hndClient) |
Release the locked client. More... | |
BsProxyClientCtl_T * | ClientNew (Socket_T *pSockClient) |
Create new client control structure. More... | |
void | ClientDelete (BsProxyClientCtl_T *pClient) |
Delete a client with the server. More... | |
void | ClientSetState (BsProxyClientCtl_T *pClient, BsProxyClientState_T eNewState) |
Set client's state. More... | |
int | ClientRecvReq (BsProxyClientHnd_T hndClient, BsProxyMsgHdr_T *pMsgHdr, byte_t **addrBuf) |
Receive a request message from client. More... | |
int | ClientSendOkRsp (BsProxyClientHnd_T hndClient, BsTid_T uTid) |
Send an ok response to the client. More... | |
int | ClientSendErrorRsp (BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt,...) |
Send an error response to the client. More... | |
int | ClientSendVErrorRsp (BsProxyClientHnd_T hndClient, BsTid_T uTid, int nECode, const char *sErrFmt, va_list ap) |
Send va_list error response to the client. More... | |
int | ClientSendServerRsp (BsProxyClientHnd_T hndClient, BsTid_T uTid, BsProxyMsgId_T uMsgId, void *pMsgRsp) |
Send a server-terminated response message to client. More... | |
int | ClientSendRsp (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufRsp[], size_t uRspSize) |
Send module-specific response to the client. More... | |
void | VConnOneTimeInit () |
The bsProxy virtual connections one-time initialization. | |
BsProxyVConn_T * | VConnNew () |
Create a new, allocated virtual connection entry. More... | |
void | VConnDelete (BsProxyVConn_T *pVConn) |
Delete allocated virtual connection entry. More... | |
BsProxyVConn_T * | VConnGet (BsVConnHnd_T hndVConn) |
Get the virtual connection entry associated with the handle. More... | |
int | VConnOpenServer () |
Open special server virtual connection. More... | |
int | VConnOpenDev (BsProxyClientHnd_T hndClient, const char *sDevName, const char *sModName, byte_t argbuf[], size_t uArgLen, bool_t bTrace) |
Open a virtual device connection. More... | |
int | VConnClose (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn) |
Close the virtual connection. More... | |
BsProxyVConn_T * | VConnAcquire (BsVConnHnd_T hndVConn) |
Acquire virtual connection, locking it from other threads. More... | |
void | VConnRelease (BsVConnHnd_T hndVConn) |
Release the locked virtual client. More... | |
void | ModOneTimeInit (DListStr_T *pDListLibPath) |
The bsProxy interface module handling one-time initialization. More... | |
char * | ModNewModUri (const char *sModName) |
Convert the module name to a quasi Uniform Resource Id. More... | |
BsProxyModIF_T * | ModGetLoadedIF (const char *sModUri) |
Get the defined interface from a previously loaded i/f module. More... | |
BsProxyModIF_T * | ModLoad (const char *sModUri) |
Load the interface module. More... | |
void | ModUnload (BsProxyModIF_T *pModIF) |
Unload the interface module. More... | |
BsProxyThReq_T * | ThReqNew (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen) |
Allocate and initalized a new service thread request. More... | |
void | ThReqDelete (BsProxyThReq_T *pThReq) |
Delete service thread request. More... | |
int | ThQueue (BsProxyThCtl_T *pThCtl, BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen) |
Queue a request for the given service thread. More... | |
BsProxyThReq_T * | ThDequeue (BsProxyThCtl_T *pThCtl) |
Dequeue a request for the given service thread. More... | |
void | ThOneTimeInit () |
The service thread one-time global initialization. | |
char * | ThNewDevUri (const char *sDevName) |
Convert the device name to a quasi Uniform Resource Id. More... | |
BsProxyThCtl_T * | ThCreateDevThread (const char *sDevUri) |
Create a device service thread. More... | |
BsProxyThCtl_T * | ThCreateServerThread () |
Create the special server service thread. More... | |
void | ThDestroyThread (BsProxyThCtl_T *pThCtl) |
Destroy service thread. More... | |
int | ServerRequest (BsProxyClientHnd_T hndClient, BsVConnHnd_T hndVConn, BsTid_T uTid, BsMsgId_T uMsgId, byte_t bufReq[], size_t uReqLen) |
Server service thread request handler. More... | |
Variables | |
BsProxyServerCtl_T * | BsServerCtl |
The server control block. More... | |
BotSense bsProxy IP server declarations.
Add support for botsense configuration XML files.
Add fork-exec'ing to support multiple interfaces.
Definition in file bsProxy.h.
#define BSPROXY_CHK_MOD_VCONN_HND | ( | hndVConn | ) |
Check if handle is in virtual connection device module range.
hndVConn | Virtual connection handle. |
Definition at line 441 of file bsProxy.h.
Referenced by VConnClose().
#define BSPROXY_CHK_VCONN_HND | ( | hndVConn | ) |
Check if handle is in virtual connection range.
The special server handle is included.
hndVConn | Virtual connection handle. |
Definition at line 428 of file bsProxy.h.
Referenced by BsProxyDispatch(), VConnAcquire(), VConnDelete(), VConnGet(), and VConnRelease().
#define BSPROXY_LOG_ERROR | ( | hndClient, | |
ecode, | |||
efmt, | |||
... | |||
) |
Log Proxy Server Error.
hndClient | Client handle. |
ecode |
Definition at line 288 of file bsProxy.h.
Referenced by ClientRecvBody(), ClientRecvHdr(), ClientSendRsp(), ClientSendServerRsp(), ThDevRequest(), VConnClose(), and VConnOpenDev().
#define BSPROXY_LOG_NMERROR | ( | hndClient, | |
nmecode, | |||
efmt, | |||
... | |||
) |
Log Proxy Server NetMsgs (Un)Packing Error.
hndClient | Client handle. |
nmecode | NetMsgs error code. |
efmt | Error output format string literal. |
... | Error variable arguments. |
Definition at line 302 of file bsProxy.h.
Referenced by ClientSendServerRsp().
#define BSPROXY_LOG_REQ | ( | hndClient, | |
pMsgHdr | |||
) |
Log client request.
hndClient | Client handle. |
pMsgHdr | Request message header. |
Definition at line 384 of file bsProxy.h.
Referenced by ClientRecvReq().
#define BSPROXY_LOG_RSP | ( | hndClient, | |
pMsgHdr | |||
) |
Log client request.
hndClient | Client handle. |
pMsgHdr | Request message header. |
Definition at line 404 of file bsProxy.h.
Referenced by ClientSendRsp().
#define BSPROXY_LOG_SYSERROR | ( | hndClient, | |
efmt, | |||
... | |||
) |
Log Proxy Server System Error.
hndClient | Client handle. |
efmt | Error output format string litteral. |
... | Error variable arguments. |
Definition at line 314 of file bsProxy.h.
Referenced by ClientRead(), ClientSendRsp(), and ClientWrite().
#define BSPROXY_LOG_WARN | ( | hndClient, | |
ecode, | |||
wfmt, | |||
... | |||
) |
Log Proxy Server Warning.
hndClient | Client handle. |
ecode |
#define BSPROXY_SEND_ERROR_RSP | ( | hndClient, | |
hndVConn, | |||
uTid, | |||
ecode, | |||
efmt, | |||
... | |||
) |
Log BotSense Error and Send Error Response.
hndClient | Client handle. |
hndVConn | Requestor's virtual connection handle. |
uTid | Request-Response transaction id. |
ecode |
Definition at line 330 of file bsProxy.h.
Referenced by BsProxyDispatch(), ReqDevClose(), ReqDevOpen(), ReqMsgTrace(), ServerRequest(), and ThDevRequest().
#define BSPROXY_SEND_NMERROR_RSP | ( | hndClient, | |
hndVConn, | |||
uTid, | |||
nmecode, | |||
efmt, | |||
... | |||
) |
Log NetMsgs (Un)Packing Error and Send Error Response.
hndClient | Client handle. |
hndVConn | Requestor's virtual connection handle. |
uTid | Request-Response transaction id. |
nmecode | NetMsgs error code. |
efmt | Error output format string literal. |
... | Error variable arguments. |
Definition at line 348 of file bsProxy.h.
Referenced by ReqDevClose(), ReqDevOpen(), ReqGetVConnInfo(), ReqLoopback(), ReqMsgTrace(), and ReqSetLogging().
#define BSPROXY_SEND_SYSERROR_RSP | ( | hndClient, | |
hndVConn, | |||
uTid, | |||
efmt, | |||
... | |||
) |
Log System Error and Send Error Response.
hndClient | Client handle. |
hndVConn | Requestor's virtual connection handle. |
uTid | Request-Response transaction id. |
efmt | Error output format string literal. |
... | Error variable arguments. |
typedef struct _bsproxy_th_ctl BsProxyThCtl_T |
BotSense Service Thread Control Block Structure Type
typedef struct _bsproxy_th_req BsProxyThReq_T |
BotSense Service Thread Request Structure Type
enum BsProxyClientState_T |
enum BsProxyThState_T |
void BsProxyLogMsgHdr | ( | const char * | sPreface, |
BsProxyMsgHdr_T * | pMsgHdr | ||
) |
Log message header.
sPreface | Preface string. |
pMsgHdr | Pointer to message header structure. |
Definition at line 108 of file bsProxyUtils.c.
References BSPROXY_VCONN_SERVER, BsProxyLookupMsgDef(), BsProxyMsgHdr_T::m_hdrBodyLen, BsProxyMsgHdr_T::m_hdrMagic, BsProxyMsgHdr_T::m_hdrMsgId, BsProxyMsgHdr_T::m_hdrTid, and BsProxyMsgHdr_T::m_hdrVConn.
Referenced by ClientSetTraceState().
BsProxyClientCtl_T* ClientAcquire | ( | BsProxyClientHnd_T | hndClient | ) |
Acquire client, locking it from other threads.
The calling thread is blocked until the client is availble or has been deleted.
hndClient | Client handle. |
Definition at line 546 of file bsProxyClient.c.
References ClientLockBusy(), ClientUnlockBusy(), ClientWaitNotBusy(), BsProxyClientCtl_T::m_bBusy, and ServerGetClient().
Referenced by BsProxyClientUnregister(), ClientRecvReq(), ClientSendRsp(), ClientSetTraceState(), ReqDevClose(), and ReqDevOpen().
void ClientDelete | ( | BsProxyClientCtl_T * | pClient | ) |
Delete a client with the server.
pClient |
Definition at line 621 of file bsProxyClient.c.
References BsProxyClientCtl_T::m_pClientSock, and BsProxyClientCtl_T::m_sClientName.
Referenced by BsProxyClientUnregister(), and ClientSetTraceState().
INLINE_IN_H bool_t ClientGetTraceState | ( | BsProxyClientHnd_T | hndClient | ) |
Get the BotSense client's server-terminated message trace state.
hndClient |
Definition at line 602 of file bsProxy.h.
References BsProxyClientCtl_T::m_bServerTrace, and ServerGetClient().
Referenced by ClientSendServerRsp(), and ServerRequest().
INLINE_IN_H const char* ClientHasName | ( | BsProxyClientHnd_T | hndClient | ) |
Get the BotSense client official name.
hndClient |
Definition at line 588 of file bsProxy.h.
References ClientThisHasName(), and ServerGetClient().
Referenced by BsProxyServer(), ReqGetVConnInfo(), ReqLoopback(), VConnClose(), and VConnOpenDev().
BsProxyClientCtl_T* ClientNew | ( | Socket_T * | pSockClient | ) |
Create new client control structure.
pSockClient | Accecpted client socket. |
Definition at line 602 of file bsProxyClient.c.
References BsProxyClientStateNominal, BsProxyClientCtl_T::m_bServerTrace, BsProxyClientCtl_T::m_eClientState, BsProxyClientCtl_T::m_pClientSock, BsProxyClientCtl_T::m_sClientName, and BsProxyClientCtl_T::m_uRefCnt.
Referenced by BsProxyClientRegister(), and ClientSetTraceState().
int ClientRecvReq | ( | BsProxyClientHnd_T | hndClient, |
BsProxyMsgHdr_T * | pMsgHdr, | ||
byte_t ** | addrBuf | ||
) |
Receive a request message from client.
hndClient |
Definition at line 836 of file bsProxyClient.c.
References BS_ECODE_SERVER_BAD_CLIENT, BSPROXY_LOG_REQ, BsProxyClientStateNominal, ClientAcquire(), ClientRecvBody(), ClientRecvHdr(), ClientRelease(), ClientSetState(), ClientThisHasName(), BsProxyClientCtl_T::m_eClientState, BsProxyMsgHdr_T::m_hdrBodyLen, and ServerHasName().
Referenced by BsProxyServer(), and ClientSetTraceState().
void ClientRelease | ( | BsProxyClientHnd_T | hndClient | ) |
Release the locked client.
A broadcast is sent to all blocking threads on the freed event.
hndClient | Client handle. |
Definition at line 574 of file bsProxyClient.c.
References ClientBroadcastNotBusy(), ClientLockBusy(), ClientUnlockBusy(), BsProxyClientCtl_T::m_bBusy, and ServerGetClient().
Referenced by ClientRecvReq(), ClientSendRsp(), ClientSetTraceState(), ReqDevClose(), and ReqDevOpen().
int ClientSendErrorRsp | ( | BsProxyClientHnd_T | hndClient, |
BsTid_T | uTid, | ||
int | nECode, | ||
const char * | sErrFmt, | ||
... | |||
) |
Send an error response to the client.
hndClient |
Definition at line 960 of file bsProxyClient.c.
References ClientSendVErrorRsp().
Referenced by ClientSetTraceState().
int ClientSendOkRsp | ( | BsProxyClientHnd_T | hndClient, |
BsTid_T | uTid | ||
) |
Send an ok response to the client.
hndClient |
Definition at line 936 of file bsProxyClient.c.
References BSPROXY_MSG_HDR_LEN, BSPROXY_VCONN_SERVER, BsProxyMsgIdRspOk, and ClientSendRsp().
Referenced by ClientSetTraceState(), ModCbSendOkRsp(), ReqDevClose(), ReqMsgTrace(), and ReqSetLogging().
int ClientSendRsp | ( | BsProxyClientHnd_T | hndClient, |
BsVConnHnd_T | hndVConn, | ||
BsTid_T | uTid, | ||
BsMsgId_T | uMsgId, | ||
byte_t | bufRsp[], | ||
size_t | uRspSize | ||
) |
Send module-specific response to the client.
hndClient |
Definition at line 1084 of file bsProxyClient.c.
References BS_ECODE_BAD_SEND, BS_ECODE_INTERNAL, BS_ECODE_SERVER_BAD_CLIENT, BSPROXY_LOG_ERROR, BSPROXY_LOG_RSP, BSPROXY_LOG_SYSERROR, BSPROXY_MSG_HDR_LEN, BSPROXY_MSG_MAGIC, ClientAcquire(), ClientRelease(), ClientWrite(), BsProxyMsgHdr_T::m_hdrBodyLen, BsProxyMsgHdr_T::m_hdrMagic, BsProxyMsgHdr_T::m_hdrMsgId, BsProxyMsgHdr_T::m_hdrTid, and BsProxyMsgHdr_T::m_hdrVConn.
Referenced by ClientSendOkRsp(), ClientSendServerRsp(), ClientSetTraceState(), and ModCbSendRsp().
int ClientSendServerRsp | ( | BsProxyClientHnd_T | hndClient, |
BsTid_T | uTid, | ||
BsProxyMsgId_T | uMsgId, | ||
void * | pMsgRsp | ||
) |
Send a server-terminated response message to client.
The response message header must contain the information except for the body length which will be automatically calculated.
hndClient |
Definition at line 1025 of file bsProxyClient.c.
References BS_ECODE_INTERNAL, BSPROXY_BUF_BODY, BSPROXY_LOG_ERROR, BSPROXY_LOG_NMERROR, BSPROXY_MSG_MAX_LEN, BSPROXY_VCONN_SERVER, BsProxyLookupMsgDef(), BsProxyPackMsg(), ClientGetTraceState(), and ClientSendRsp().
Referenced by ClientSendVErrorRsp(), ClientSetTraceState(), ReqDevOpen(), ReqGetVConnInfo(), ReqGetVConnList(), ReqGetVersion(), and ReqLoopback().
int ClientSendVErrorRsp | ( | BsProxyClientHnd_T | hndClient, |
BsTid_T | uTid, | ||
int | nECode, | ||
const char * | sErrFmt, | ||
va_list | ap | ||
) |
Send va_list error response to the client.
hndClient |
Definition at line 986 of file bsProxyClient.c.
References BSPROXY_RSPERR_EMSG_LEN, BsProxyMsgIdRspErr, ClientSendServerRsp(), BsProxyRspErr_T::m_ecode, and BsProxyRspErr_T::m_emsg.
Referenced by ClientSendErrorRsp(), ClientSetTraceState(), and ModCbSendErrorRsp().
void ClientSetState | ( | BsProxyClientCtl_T * | pClient, |
BsProxyClientState_T | eNewState | ||
) |
Set client's state.
pClient |
< disconnected but not deleted
< normal operation
< resyncing server with client
Definition at line 643 of file bsProxyClient.c.
References BsProxyClientStateNominal, BsProxyClientStateReSync, BsProxyClientStateZombie, ClientThisHasName(), BsProxyClientCtl_T::m_eClientState, BsProxyClientCtl_T::m_sClientName, and ServerHasName().
Referenced by BsProxyClientUnregister(), ClientRecvBody(), ClientRecvHdr(), ClientRecvReq(), and ClientSetTraceState().
INLINE_IN_H void ClientSetTraceState | ( | BsProxyClientHnd_T | hndClient, |
bool_t | bTrace | ||
) |
Set the BotSense client's server-terminated message trace state.
hndClient |
Definition at line 617 of file bsProxy.h.
References BsProxyLogMsgHdr(), ClientAcquire(), ClientDelete(), ClientNew(), ClientOneTimeInit(), ClientRecvReq(), ClientRelease(), ClientSendErrorRsp(), ClientSendOkRsp(), ClientSendRsp(), ClientSendServerRsp(), ClientSendVErrorRsp(), ClientSetState(), BsProxyClientCtl_T::m_bServerTrace, ModGetLoadedIF(), ModLoad(), ModNewModUri(), ModOneTimeInit(), ModUnload(), ServerGetClient(), ServerRequest(), ThCreateDevThread(), ThCreateServerThread(), ThDequeue(), ThDestroyThread(), ThNewDevUri(), ThOneTimeInit(), ThQueue(), ThReqDelete(), ThReqNew(), VConnAcquire(), VConnClose(), VConnDelete(), VConnGet(), VConnNew(), VConnOneTimeInit(), VConnOpenDev(), VConnOpenServer(), and VConnRelease().
Referenced by ReqMsgTrace().
INLINE_IN_H const char* ClientThisHasName | ( | BsProxyClientCtl_T * | pClient | ) |
Get this BotSense client official name.
pClient |
Definition at line 574 of file bsProxy.h.
References BsProxyClientCtl_T::m_sClientName.
Referenced by ClientHasName(), ClientRead(), ClientRecvReq(), ClientSetState(), and ClientWrite().
BsProxyModIF_T* ModGetLoadedIF | ( | const char * | sModUri | ) |
Get the defined interface from a previously loaded i/f module.
Multi-Thread safe.
sModUri | Interface module expanded, canonical name. |
Definition at line 1058 of file bsProxyMod.c.
References ModHashGetIF(), ModLock(), and ModUnlock().
Referenced by ClientSetTraceState().
BsProxyModIF_T* ModLoad | ( | const char * | sModUri | ) |
Load the interface module.
The module's expanded, canonical name is determined, the dynamic library is loaded, the module's exported interface is attached, and the module's initialization routine is called.
The the same module is loaded again, the reference count is bumped and the already attached interface is returned.
Multi-Thread safe.
sModUri | Interface module expanded, canonical name. |
Definition at line 1089 of file bsProxyMod.c.
References BS_ECODE_BAD_MOD, BS_ECODE_NO_MOD, BS_ECODE_NO_RSRC, BS_OK, BSPROXY_MOD_LOG_ERROR, BsProxyModIF_T::m_fnModInit, BsProxyModIF_T::m_sModUri, BsProxyModIF_T::m_uRefCnt, ModDllDeleteIF(), ModDllNewIF(), ModDllOpen(), ModHashAdd(), ModHashGetIF(), ModLock(), and ModUnlock().
Referenced by ClientSetTraceState(), and VConnOpenDev().
char* ModNewModUri | ( | const char * | sModName | ) |
Convert the module name to a quasi Uniform Resource Id.
sModName | Module path name. |
Definition at line 1042 of file bsProxyMod.c.
References ModDllNewCanonicalName().
Referenced by ClientSetTraceState(), and VConnOpenDev().
void ModOneTimeInit | ( | DListStr_T * | pDListLibPath | ) |
The bsProxy interface module handling one-time initialization.
pDListLibPath | List of optional library search paths. |
Definition at line 1013 of file bsProxyMod.c.
References BsModHashTbl, BsModMutex, BSPROXY_MOD_HASH_MAX, BSPROXY_MOD_HASH_MIN, ModDllInit(), and ModHashDeleteData().
Referenced by ClientSetTraceState(), and main().
void ModUnload | ( | BsProxyModIF_T * | pModIF | ) |
Unload the interface module.
The module's reference count is decremented. If the count is zero, then the module's exit routine is called and the module dynamic library is unloaded from bsProxy server application.
Multi-Thread safe.
pModIF | Exported module interface. |
Definition at line 1191 of file bsProxyMod.c.
References BsProxyModIF_T::m_dllHandle, BsProxyModIF_T::m_fnModExit, BsProxyModIF_T::m_sModUri, BsProxyModIF_T::m_uRefCnt, ModDllClose(), ModHashDelete(), ModHashGetIF(), ModLock(), and ModUnlock().
Referenced by ClientSetTraceState(), VConnClose(), and VConnOpenDev().
INLINE_IN_H int ServerClientHnd2Sd | ( | BsProxyClientHnd_T | hndClient | ) |
Convert the BotSense server client handle to client socket descriptor.
hndClient |
Definition at line 521 of file bsProxy.h.
Referenced by BsProxyClientUnregister(), BsProxyServerDelete(), and ServerGetClient().
INLINE_IN_H BsProxyClientHnd_T ServerClientSd2Hnd | ( | int | sd | ) |
Convert the BotSense server client socket descriptor to client handle.
sd |
Definition at line 537 of file bsProxy.h.
Referenced by BsProxyClientRegister(), BsProxyServer(), ClientRead(), and ClientWrite().
INLINE_IN_H BsProxyServerCtl_T* ServerGet | ( | ) |
Get the BotSense server.
Definition at line 475 of file bsProxy.h.
References BsServerCtl.
Referenced by BsProxyClientRegister(), BsProxyClientUnregister(), ServerGetClient(), ServerHasAddr(), ServerHasName(), and ServerHasPort().
INLINE_IN_H BsProxyClientCtl_T* ServerGetClient | ( | BsProxyClientHnd_T | hndClient | ) |
Get the BotSense server client.
hndClient |
Definition at line 551 of file bsProxy.h.
References BSPROXY_FD_SETSIZE, BsProxyServerCtl_T::m_pServerRegClient, ServerClientHnd2Sd(), and ServerGet().
Referenced by BsProxyServer(), ClientAcquire(), ClientGetTraceState(), ClientHasName(), ClientRelease(), and ClientSetTraceState().
INLINE_IN_H const char* ServerHasAddr | ( | ) |
Get the BotSense server's listening address.
Definition at line 495 of file bsProxy.h.
References ServerGet().
INLINE_IN_H const char* ServerHasName | ( | ) |
Get the BotSense server's official name.
Definition at line 485 of file bsProxy.h.
References BsProxyServerCtl_T::m_sServerName, and ServerGet().
Referenced by BsProxyServer(), ClientRecvReq(), ClientSetState(), main(), ModCbSendErrorRsp(), ModCbSendOkRsp(), ModCbSendRsp(), ModDllOpen(), ThQueue(), VConnClose(), VConnOpenDev(), and VConnOpenServer().
INLINE_IN_H int ServerHasPort | ( | ) |
Get the BotSense server's listening port.
Definition at line 505 of file bsProxy.h.
References BsProxyServerCtl_T::m_nServerPort, and ServerGet().
Referenced by BsProxyServer().
int ServerRequest | ( | BsProxyClientHnd_T | hndClient, |
BsVConnHnd_T | hndVConn, | ||
BsTid_T | uTid, | ||
BsMsgId_T | uMsgId, | ||
byte_t | bufReq[], | ||
size_t | uReqLen | ||
) |
Server service thread request handler.
hndClient |
Definition at line 610 of file bsProxyRequest.c.
References BS_ECODE_UNKNOWN_REQ, BSPROXY_SEND_ERROR_RSP, BsProxyMsgIdReqDevClose, BsProxyMsgIdReqDevOpen, BsProxyMsgIdReqGetVConnInfo, BsProxyMsgIdReqGetVConnList, BsProxyMsgIdReqGetVersion, BsProxyMsgIdReqLoopback, BsProxyMsgIdReqMsgTrace, BsProxyMsgIdReqSetLogging, ClientGetTraceState(), ReqDevClose(), ReqDevOpen(), ReqGetVConnInfo(), ReqGetVConnList(), ReqGetVersion(), ReqLoopback(), ReqMsgTrace(), and ReqSetLogging().
Referenced by ClientSetTraceState(), and ThCreateServerThread().
BsProxyThCtl_T* ThCreateDevThread | ( | const char * | sDevUri | ) |
Create a device service thread.
The actual thread is only created if it does not already exists. The internal reference count is incremented to keep track of the users of this thread.
sDevUri | Device URI. |
Definition at line 756 of file bsProxyThread.c.
References BsProxyThStateInit, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_fnRequest, _bsproxy_th_ctl::m_sDevUri, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ThCtlBlkDelete(), ThCtlBlkNew(), ThDevRequest(), ThGlobalLock(), ThGlobalUnlock(), ThHashAdd(), ThHashDelete(), ThHashGetCtl(), ThServiceThread(), and ThSyncRun().
Referenced by ClientSetTraceState(), and VConnOpenDev().
BsProxyThCtl_T* ThCreateServerThread | ( | ) |
Create the special server service thread.
There is only one server service thread per server. The server thread processes all server terminated requests.
Definition at line 837 of file bsProxyThread.c.
References BS_ECODE_INTERNAL, BSPROXY_TH_LOG_ERROR, BSPROXY_TH_SERVER_URI, BsProxyThStateInit, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_fnRequest, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ServerRequest(), ThCtlBlkDelete(), ThCtlBlkNew(), ThGlobalLock(), ThGlobalUnlock(), ThHashAdd(), ThHashDelete(), ThHashGetCtl(), ThServiceThread(), and ThSyncRun().
Referenced by ClientSetTraceState(), and VConnOpenServer().
BsProxyThReq_T* ThDequeue | ( | BsProxyThCtl_T * | pThCtl | ) |
Dequeue a request for the given service thread.
The service thread will block if no queued request is present.
Definition at line 675 of file bsProxyThread.c.
References BsProxyThStateRunning, _bsproxy_th_ctl::m_eState, _bsproxy_th_ctl::m_queue, ThSyncLock(), ThSyncUnlock(), and ThSyncWait().
Referenced by ClientSetTraceState(), and ThServiceThread().
void ThDestroyThread | ( | BsProxyThCtl_T * | pThCtl | ) |
Destroy service thread.
The thread's reference count is decremented. If the count is zero, then the thread is actually destroyed with all queued requests deleted. The calling thread is suspended until the target service thread terminates.
pThCtl | Service thread control block. |
Definition at line 921 of file bsProxyThread.c.
References _bsproxy_th_ctl::m_sDevUri, _bsproxy_th_ctl::m_thread, _bsproxy_th_ctl::m_uRefCnt, ThGlobalLock(), ThGlobalUnlock(), ThHashDelete(), and ThSyncExit().
Referenced by ClientSetTraceState(), VConnClose(), and VConnOpenDev().
char* ThNewDevUri | ( | const char * | sDevName | ) |
Convert the device name to a quasi Uniform Resource Id.
sDevName | Device path name. |
Definition at line 737 of file bsProxyThread.c.
Referenced by ClientSetTraceState(), and VConnOpenDev().
int ThQueue | ( | BsProxyThCtl_T * | pThCtl, |
BsProxyClientHnd_T | hndClient, | ||
BsVConnHnd_T | hndVConn, | ||
BsTid_T | uTid, | ||
BsMsgId_T | uMsgId, | ||
byte_t | bufReq[], | ||
size_t | uReqLen | ||
) |
Queue a request for the given service thread.
pThCtl | Service thread control block. |
hndClient | Client handle. |
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
uMsgId | Request message id. |
bufReq | Allocated packed request message body. |
uReqLen | Length of request in buffer (number of bytes). |
Definition at line 626 of file bsProxyThread.c.
References BS_ECODE_NO_RSRC, BS_OK, BSPROXY_TH_LOG_ERROR, BSPROXY_TH_MAX_QUEUE_SIZE, _bsproxy_th_ctl::m_queue, _bsproxy_th_ctl::m_sDevUri, ServerHasName(), ThReqNew(), ThSyncLock(), ThSyncSignal(), and ThSyncUnlock().
Referenced by BsProxyDispatch(), and ClientSetTraceState().
void ThReqDelete | ( | BsProxyThReq_T * | pThReq | ) |
Delete service thread request.
pThReq | Service thread request. |
Definition at line 601 of file bsProxyThread.c.
References _bsproxy_th_req::m_bufReq.
Referenced by ClientSetTraceState(), ThQReqDelete(), and ThServiceThread().
BsProxyThReq_T* ThReqNew | ( | BsProxyClientHnd_T | hndClient, |
BsVConnHnd_T | hndVConn, | ||
BsTid_T | uTid, | ||
BsMsgId_T | uMsgId, | ||
byte_t | bufReq[], | ||
size_t | uReqLen | ||
) |
Allocate and initalized a new service thread request.
hndClient | Client handle. |
hndVConn | Virtual connection handle. |
uTid | Request-Response transaction id. |
uMsgId | Request message id. |
bufReq | Allocated packed request message body. |
uReqLen | Length of request in buffer (number of bytes). |
Definition at line 577 of file bsProxyThread.c.
References _bsproxy_th_req::m_bufReq, _bsproxy_th_req::m_hndClient, _bsproxy_th_req::m_hndVConn, _bsproxy_th_req::m_uMsgId, _bsproxy_th_req::m_uReqLen, and _bsproxy_th_req::m_uTid.
Referenced by ClientSetTraceState(), and ThQueue().
uint_t timer_elapsed | ( | struct timeval * | pTvMark | ) |
Calculate the elapsed time between the given time mark and this call.
pTvMark | Pointer to timeval holding time mark. |
Definition at line 79 of file bsProxyUtils.c.
References timer_mark().
Referenced by timer_mark().
|
inlinestatic |
Mark the current time. Resolution is microseconds.
pTvMark | Pointer to timeval structure to be populated with the current system seconds and useconds. |
Definition at line 456 of file bsProxy.h.
References timer_elapsed().
BsProxyVConn_T* VConnAcquire | ( | BsVConnHnd_T | hndVConn | ) |
Acquire virtual connection, locking it from other threads.
The calling thread is blocked until the virtual connection is availble or has been deleted.
hndVConn |
Definition at line 552 of file bsProxyVConn.c.
References BSPROXY_CHK_VCONN_HND, BsProxyVConn_T::m_bBusy, VConnLockBusy(), VConnUnlockBusy(), and VConnWaitNotBusy().
Referenced by BsProxyDispatch(), ClientSetTraceState(), ModCbGetDevUri(), ModCbIterNext(), ReqGetVConnInfo(), ReqGetVConnList(), ReqMsgTrace(), ThDevRequest(), and VConnClose().
int VConnClose | ( | BsProxyClientHnd_T | hndClient, |
BsVConnHnd_T | hndVConn | ||
) |
Close the virtual connection.
Closing a virtual connections may close the resource (file) descriptor associated with the device, unload the interface module associated with the device, and terminate the device thread. These actions occur only when the reference counts are zero.
hndClient |
Definition at line 478 of file bsProxyVConn.c.
References BS_ECODE_BAD_VCONN_HND, BS_ECODE_NO_VCONN, BS_OK, BSPROXY_CHK_MOD_VCONN_HND, BSPROXY_LOG_ERROR, BsVConnActiveCnt, ClientHasName(), BsProxyModIF_T::m_fnModClose, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, ModUnload(), ServerHasName(), ThDestroyThread(), VConnAcquire(), and VConnDelete().
Referenced by BsProxyClientUnregister(), ClientSetTraceState(), and ReqDevClose().
void VConnDelete | ( | BsProxyVConn_T * | pVConn | ) |
Delete allocated virtual connection entry.
The deletion event is broadcasted to all blocked threads waiting on this connection.
Definition at line 220 of file bsProxyVConn.c.
References BSPROXY_CHK_VCONN_HND, BsVConnActiveCnt, BsProxyVConn_T::m_hndVConn, VConnBroadcastNotBusy(), VConnLockBusy(), and VConnUnlockBusy().
Referenced by ClientSetTraceState(), VConnClose(), and VConnOpenDev().
BsProxyVConn_T* VConnGet | ( | BsVConnHnd_T | hndVConn | ) |
Get the virtual connection entry associated with the handle.
hndVConn |
Definition at line 248 of file bsProxyVConn.c.
References BSPROXY_CHK_VCONN_HND.
Referenced by BsProxyClientUnregister(), ClientSetTraceState(), ModCbSendErrorRsp(), ModCbSendOkRsp(), and ModCbSendRsp().
BsProxyVConn_T* VConnNew | ( | ) |
Create a new, allocated virtual connection entry.
The new virtual connection is added to the virtual connection table. It is marked busy (i.e. locked). The caller must call VConnRelease() or VConnDelete() to free the entry.
Definition at line 183 of file bsProxyVConn.c.
References BSPROXY_VCONN_MOD_NUMOF, BSPROXY_VCONN_NUMOF, BsVConnActiveCnt, BsProxyVConn_T::m_bBusy, BsProxyVConn_T::m_hndVConn, VConnLockBusy(), and VConnUnlockBusy().
Referenced by ClientSetTraceState(), and VConnOpenDev().
int VConnOpenDev | ( | BsProxyClientHnd_T | hndClient, |
const char * | sDevName, | ||
const char * | sModName, | ||
byte_t | argbuf[], | ||
size_t | uArgLen, | ||
bool_t | bTrace | ||
) |
Open a virtual device connection.
To open a virtual connection:
hndClient |
Definition at line 325 of file bsProxyVConn.c.
References BS_ECODE_BAD_VAL, BS_ECODE_NO_EXEC, BS_ECODE_NO_MOD, BS_ECODE_NO_RSRC, BSPROXY_LOG_ERROR, BsVConnActiveCnt, ClientHasName(), BsProxyModIF_T::m_fnModOpen, BsProxyVConn_T::m_hndClient, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, BsProxyVConn_T::m_rd, BsProxyModIF_T::m_sModUri, ModLoad(), ModNewModUri(), ModUnload(), ServerHasName(), ThCreateDevThread(), ThDestroyThread(), ThNewDevUri(), VConnDelete(), VConnNew(), and VConnRelease().
Referenced by ClientSetTraceState(), and ReqDevOpen().
int VConnOpenServer | ( | ) |
Open special server virtual connection.
Definition at line 265 of file bsProxyVConn.c.
References BS_ECODE_NO_EXEC, BS_OK, BSPROXY_VCONN_SERVER, BsVConnActiveCnt, BsProxyVConn_T::m_bBusy, BsProxyVConn_T::m_hndClient, BsProxyVConn_T::m_hndVConn, BsProxyVConn_T::m_pModIF, BsProxyVConn_T::m_pThCtl, BsProxyVConn_T::m_rd, ServerHasName(), and ThCreateServerThread().
Referenced by ClientSetTraceState(), and main().
void VConnRelease | ( | BsVConnHnd_T | hndVConn | ) |
Release the locked virtual client.
A broadcast is sent to all blocking threads on the freed event.
hndVConn |
Definition at line 585 of file bsProxyVConn.c.
References BSPROXY_CHK_VCONN_HND, BsProxyVConn_T::m_bBusy, VConnBroadcastNotBusy(), VConnLockBusy(), and VConnUnlockBusy().
Referenced by BsProxyDispatch(), ClientSetTraceState(), ModCbGetDevUri(), ModCbIterNext(), ReqGetVConnInfo(), ReqGetVConnList(), ReqMsgTrace(), ThDevRequest(), and VConnOpenDev().
BsProxyServerCtl_T* BsServerCtl |
The server control block.
Definition at line 831 of file bsProxy.c.
Referenced by ServerGet(), ServerLock(), ServerTryLock(), and ServerUnlock().