![]() |
botsense
3.2.0
RoadNarrows Client-Server Proxied Services Framework
|
Virtual connections management operations. More...
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include "rnr/rnrconfig.h"
#include "rnr/log.h"
#include "rnr/new.h"
#include "botsense/BotSense.h"
#include "botsense/bsProxyModIF.h"
#include "bsProxy.h"
Go to the source code of this file.
Functions | |
static void | VConnLockBusy () |
Lock virtual connection's global busy mutual exclusion. | |
static void | VConnUnlockBusy () |
Unlock virtual connection's global busy mutual exclusion. | |
static bool_t | VConnBusyTryLock () |
Try to lock virtual connection's global busy mutual exclusion. More... | |
static void | VConnBroadcastNotBusy () |
Broadcast that a virtual connection has been freed or deleted. More... | |
static void | VConnWaitNotBusy () |
Wait on a virtual connection to become's free. | |
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... | |
Variables | |
static pthread_mutex_t | BsVConnBusyMutex |
operations mutex | |
static pthread_cond_t | BsVConnBusyCond |
block condition | |
static BsProxyVConn_T * | BsVConnTbl [BSPROXY_VCONN_NUMOF] = {NULL, } |
table of virtual connections | |
static uint_t | BsVConnActiveCnt |
Number of active v. connections. | |
Virtual connections management operations.
Definition in file bsProxyVConn.c.
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().
|
inlinestatic |
Broadcast that a virtual connection has been freed or deleted.
A broadcast will unblock all threads currently blocked on the busy condition variable. Only those thread waiting on virtual connections whose condition has changed will run. If multiple threads are waiting on the same virtual connection, then only one is schedule to run.
Definition at line 132 of file bsProxyVConn.c.
References BsVConnBusyCond.
Referenced by VConnDelete(), and VConnRelease().
|
inlinestatic |
Try to lock virtual connection's global busy mutual exclusion.
Definition at line 119 of file bsProxyVConn.c.
References BsVConnBusyMutex.
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().