This is Unofficial EPICS BASE Doxygen Site
caservertask.c File Reference
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include "addrList.h"
#include "epicsEvent.h"
#include "epicsMutex.h"
#include "epicsSignal.h"
#include "epicsStdio.h"
#include "epicsTime.h"
#include "errlog.h"
#include "freeList.h"
#include "osiPoolStatus.h"
#include "osiSock.h"
#include "taskwd.h"
#include "cantProceed.h"
#include "epicsExport.h"
#include "dbChannel.h"
#include "dbCommon.h"
#include "dbEvent.h"
#include "db_field_log.h"
#include "dbServer.h"
#include "rsrv.h"
#include "server.h"
+ Include dependency graph for caservertask.c:

Go to the source code of this file.

Macros

#define epicsExportSharedSymbols
 
#define GLBLSOURCE
 

Functions

void casr (unsigned level)
 
void destroy_client (struct client *client)
 
void destroy_tcp_client (struct client *client)
 
struct clientcreate_client (SOCKET sock, int proto)
 
void casAttachThreadToClient (struct client *pClient)
 
void casExpandSendBuffer (struct client *pClient, ca_uint32_t size)
 
void casExpandRecvBuffer (struct client *pClient, ca_uint32_t size)
 
struct clientcreate_tcp_client (SOCKET sock, const osiSockAddr *peerAddr)
 
void casStatsFetch (unsigned *pChanCount, unsigned *pCircuitCount)
 
void rsrv_register_server (void)
 

Variables

epicsThreadPrivateId rsrvCurrentClient
 

Macro Definition Documentation

#define epicsExportSharedSymbols

Definition at line 39 of file caservertask.c.

#define GLBLSOURCE

Definition at line 47 of file caservertask.c.

Function Documentation

void casAttachThreadToClient ( struct client pClient)

Definition at line 1307 of file caservertask.c.

1308 {
1311  pClient->tid = epicsThreadGetIdSelf ();
1313  taskwdInsert ( pClient->tid, NULL, NULL );
1314 }
void taskwdInsert(epicsThreadId tid, TASKWDFUNC callback, void *usr)
Definition: taskwd.c:176
LIBCOM_API void epicsStdCall epicsSignalInstallSigPipeIgnore(void)
Definition: osdSignal.cpp:17
epicsThreadPrivateId rsrvCurrentClient
Definition: caservertask.c:50
#define NULL
Definition: catime.c:38
epicsThreadId tid
Definition: server.h:98
LIBCOM_API void epicsStdCall epicsThreadPrivateSet(epicsThreadPrivateId, void *)
Definition: osdThread.c:961
LIBCOM_API void epicsStdCall epicsSignalInstallSigAlarmIgnore(void)
Definition: osdSignal.cpp:18
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810
void casExpandRecvBuffer ( struct client pClient,
ca_uint32_t  size 
)

Definition at line 1394 of file caservertask.c.

1395 {
1396  casExpandBuffer (&pClient->recv, size, 0);
1397 }
struct message_buffer recv
Definition: server.h:81
void casExpandSendBuffer ( struct client pClient,
ca_uint32_t  size 
)

Definition at line 1389 of file caservertask.c.

1390 {
1391  casExpandBuffer (&pClient->send, size, 1);
1392 }
struct message_buffer send
Definition: server.h:79
void casr ( unsigned  level)

Definition at line 897 of file caservertask.c.

898 {
899  size_t bytes_reserved;
900  int n;
901 
902  if ( ! clientQlock ) {
903  return;
904  }
905 
906  printf ("Channel Access Server V%s\n",
908 
910  n = ellCount ( &clientQ );
911  if (n == 0) {
912  printf("No clients connected.\n");
913  }
914  else if (level == 0) {
915  printf("%d client%s connected.\n",
916  n, n == 1 ? "" : "s" );
917  }
918  else {
919  struct client *client = (struct client *) ellFirst ( &clientQ );
920 
921  printf("%d client%s connected:\n",
922  n, n == 1 ? "" : "s" );
923  while (client) {
924  log_one_client(client, level - 1);
925  client = (struct client *) ellNext(&client->node);
926  }
927  }
929 
930  if (level>=1) {
932  while (iface) {
933  char buf[40];
934 
935  ipAddrToDottedIP (&iface->tcpAddr.ia, buf, sizeof(buf));
936  printf("CAS-TCP server on %s with\n", buf);
937 
938  ipAddrToDottedIP (&iface->udpAddr.ia, buf, sizeof(buf));
939 #if defined(_WIN32)
940  printf(" CAS-UDP name server on %s\n", buf);
941  if (level >= 2)
942  log_one_client(iface->client, level - 2);
943 #else
944  if (iface->udpbcast==INVALID_SOCKET) {
945  printf(" CAS-UDP name server on %s\n", buf);
946  if (level >= 2)
947  log_one_client(iface->client, level - 2);
948  }
949  else {
950  printf(" CAS-UDP unicast name server on %s\n", buf);
951  if (level >= 2)
952  log_one_client(iface->client, level - 2);
953  ipAddrToDottedIP (&iface->udpbcastAddr.ia, buf, sizeof(buf));
954  printf(" CAS-UDP broadcast name server on %s\n", buf);
955  if (level >= 2)
956  log_one_client(iface->bclient, level - 2);
957  }
958 #endif
959 
960  iface = (rsrv_iface_config *) ellNext(&iface->node);
961  }
962  }
963 
964  if (level>=1) {
965  osiSockAddrNode * pAddr;
966  char buf[40];
967  int n = ellCount(&casMCastAddrList);
968 
969  if (n) {
970  printf("Monitoring %d multicast address%s:\n",
971  n, n == 1 ? "" : "es");
972  for(pAddr = (osiSockAddrNode*)ellFirst(&casMCastAddrList);
973  pAddr;
974  pAddr = (osiSockAddrNode*)ellNext(&pAddr->node))
975  {
976  ipAddrToDottedIP (&pAddr->addr.ia, buf, sizeof(buf));
977  printf(" %s\n", buf);
978  }
979  }
980 
981  n = ellCount(&beaconAddrList);
982  printf("Sending CAS-beacons to %d address%s:\n",
983  n, n == 1 ? "" : "es");
984  for(pAddr = (osiSockAddrNode*)ellFirst(&beaconAddrList);
985  pAddr;
986  pAddr = (osiSockAddrNode*)ellNext(&pAddr->node))
987  {
988  ipAddrToDottedIP (&pAddr->addr.ia, buf, sizeof(buf));
989  printf(" %s\n", buf);
990  }
991 
992  if (casIgnoreAddrs[0]) { /* 0 indicates end of array */
993  size_t i;
994  printf("Ignoring UDP messages from address%s\n",
995  n == 1 ? "" : "es");
996  for(i=0; casIgnoreAddrs[i]; i++)
997  {
998  struct sockaddr_in addr;
999  memset(&addr, 0, sizeof(addr));
1000  addr.sin_family = AF_INET;
1001  addr.sin_addr.s_addr = casIgnoreAddrs[i];
1002  addr.sin_port = 0;
1003  ipAddrToDottedIP(&addr, buf, sizeof(buf));
1004  printf(" %s\n", buf);
1005  }
1006  }
1007  }
1008 
1009  if (level>=4u) {
1010  bytes_reserved = 0u;
1011  bytes_reserved += sizeof (struct client) *
1013  bytes_reserved += sizeof (struct channel_in_use) *
1015  bytes_reserved += sizeof(struct event_ext) *
1017  bytes_reserved += MAX_TCP *
1020  bytes_reserved += rsrvSizeofLargeBufTCP *
1022  }
1023  bytes_reserved += rsrvSizeOfPutNotify ( 0 ) *
1025  printf( "Free-lists total %u bytes, comprising\n",
1026  (unsigned int) bytes_reserved);
1027  printf( " %u client(s), %u channel(s), %u monitor event(s), %u putNotify(s)\n",
1028  (unsigned int) freeListItemsAvail ( rsrvClientFreeList ),
1029  (unsigned int) freeListItemsAvail ( rsrvChanFreeList ),
1030  (unsigned int) freeListItemsAvail ( rsrvEventFreeList ),
1031  (unsigned int) freeListItemsAvail ( rsrvPutNotifyFreeList ));
1032  printf( " %u small (%u byte) buffers, %u jumbo (%u byte) buffers\n",
1033  (unsigned int) freeListItemsAvail ( rsrvSmallBufFreeListTCP ),
1034  MAX_TCP,
1037  printf( "Server resource id table:\n");
1038  LOCK_CLIENTQ;
1041  }
1042 }
SOCKET udpbcast
Definition: server.h:163
#define MAX_TCP
Definition: caProto.h:63
#define INVALID_SOCKET
Definition: osdSock.h:32
#define ellCount(PLIST)
Report the number of nodes in a list.
Definition: ellLib.h:84
osiSockAddr addr
Definition: osiSock.h:163
int i
Definition: scan.c:967
GLBLTYPE ELLLIST casMCastAddrList
Definition: server.h:196
LIBCOM_API int epicsStdCall bucketShow(BUCKET *pb)
Display information about a hash table.
Definition: bucketLib.c:476
struct sockaddr_in ia
Definition: osiSock.h:157
osiSockAddr tcpAddr
Definition: server.h:160
osiSockAddr udpbcastAddr
Definition: server.h:160
ELLNODE node
Definition: server.h:159
GLBLTYPE void * rsrvSmallBufFreeListTCP
Definition: server.h:203
#define printf
Definition: epicsStdio.h:41
GLBLTYPE epicsMutexId clientQlock
Definition: server.h:198
struct client * client
Definition: server.h:164
#define LOCK_CLIENTQ
Definition: server.h:223
osiSockAddr udpAddr
Definition: server.h:160
#define CA_VERSION_STRING(MINOR_REVISION)
Definition: caProto.h:27
#define CA_MINOR_PROTOCOL_REVISION
Definition: nciu.h:35
GLBLTYPE ELLLIST beaconAddrList
Definition: server.h:194
#define ellNext(PNODE)
Find the next node in list.
Definition: ellLib.h:99
GLBLTYPE void * rsrvClientFreeList
Definition: server.h:200
Definition: server.h:76
GLBLTYPE void * rsrvLargeBufFreeListTCP
Definition: server.h:204
LIBCOM_API size_t epicsStdCall freeListItemsAvail(void *pvt)
Definition: freeListLib.c:171
GLBLTYPE BUCKET * pCaBucket
Definition: server.h:199
GLBLTYPE void * rsrvChanFreeList
Definition: server.h:201
GLBLTYPE unsigned rsrvSizeofLargeBufTCP
Definition: server.h:205
GLBLTYPE void * rsrvEventFreeList
Definition: server.h:202
ELLNODE node
Definition: osiSock.h:162
GLBLTYPE epicsUInt32 * casIgnoreAddrs
Definition: server.h:197
ELLNODE node
Definition: server.h:77
#define UNLOCK_CLIENTQ
Definition: server.h:224
GLBLTYPE ELLLIST servers
Definition: server.h:193
unsigned rsrvSizeOfPutNotify(struct rsrv_put_notify *pNotify)
Definition: camessage.c:1604
GLBLTYPE void * rsrvPutNotifyFreeList
Definition: server.h:206
unsigned epicsStdCall ipAddrToDottedIP(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:144
struct client * bclient
Definition: server.h:164
#define ellFirst(PLIST)
Find the first node in list.
Definition: ellLib.h:89
void casStatsFetch ( unsigned *  pChanCount,
unsigned *  pCircuitCount 
)

Definition at line 1527 of file caservertask.c.

1528 {
1529  LOCK_CLIENTQ;
1530  {
1531  int circuitCount = ellCount ( &clientQ );
1532  if ( circuitCount < 0 ) {
1533  *pCircuitCount = 0;
1534  }
1535  else {
1536  *pCircuitCount = (unsigned) circuitCount;
1537  }
1538  *pChanCount = rsrvChannelCount;
1539  }
1541 }
#define ellCount(PLIST)
Report the number of nodes in a list.
Definition: ellLib.h:84
#define LOCK_CLIENTQ
Definition: server.h:223
#define UNLOCK_CLIENTQ
Definition: server.h:224
GLBLTYPE unsigned rsrvChannelCount
Definition: server.h:207
struct client* create_client ( SOCKET  sock,
int  proto 
)

Definition at line 1225 of file caservertask.c.

1226 {
1227  struct client *client;
1228  int spaceAvailOnFreeList;
1229  size_t spaceNeeded;
1230 
1231  /*
1232  * stop further use of server if memory becomes scarse
1233  */
1234  spaceAvailOnFreeList = freeListItemsAvail ( rsrvClientFreeList ) > 0
1236  spaceNeeded = sizeof (struct client) + MAX_TCP;
1237  if ( ! ( osiSufficentSpaceInPool(spaceNeeded) || spaceAvailOnFreeList ) ) {
1239  epicsPrintf ("CAS: no space in pool for a new client (below max block thresh)\n");
1240  return NULL;
1241  }
1242 
1243  client = freeListCalloc ( rsrvClientFreeList );
1244  if ( ! client ) {
1246  epicsPrintf ("CAS: no space in pool for a new client (alloc failed)\n");
1247  return NULL;
1248  }
1249 
1250  client->sock = sock;
1251  client->proto = proto;
1252 
1254  client->lock = epicsMutexCreate();
1255  client->putNotifyLock = epicsMutexCreate();
1256  client->chanListLock = epicsMutexCreate();
1257  client->eventqLock = epicsMutexCreate();
1258  if ( ! client->blockSem || ! client->lock || ! client->putNotifyLock ||
1259  ! client->chanListLock || ! client->eventqLock ) {
1260  destroy_client ( client );
1261  return NULL;
1262  }
1263 
1264  client->pUserName = NULL;
1265  client->pHostName = NULL;
1266  ellInit ( & client->chanList );
1267  ellInit ( & client->chanPendingUpdateARList );
1268  ellInit ( & client->putNotifyQue );
1269  memset ( (char *)&client->addr, 0, sizeof (client->addr) );
1270  client->tid = 0;
1271 
1272  if ( proto == IPPROTO_TCP ) {
1273  client->send.buf = (char *) freeListCalloc ( rsrvSmallBufFreeListTCP );
1274  client->send.maxstk = MAX_TCP;
1275  client->send.type = mbtSmallTCP;
1276  client->recv.buf = (char *) freeListCalloc ( rsrvSmallBufFreeListTCP );
1277  client->recv.maxstk = MAX_TCP;
1278  client->recv.type = mbtSmallTCP;
1279  }
1280  else if ( proto == IPPROTO_UDP ) {
1281  client->send.buf = malloc ( MAX_UDP_SEND );
1282  client->send.maxstk = MAX_UDP_SEND;
1283  client->send.type = mbtUDP;
1284  client->recv.buf = malloc ( MAX_UDP_RECV );
1285  client->recv.maxstk = MAX_UDP_RECV;
1286  client->recv.type = mbtUDP;
1287  }
1288  if ( ! client->send.buf || ! client->recv.buf ) {
1289  destroy_client ( client );
1290  return NULL;
1291  }
1292  client->send.stk = 0u;
1293  client->send.cnt = 0u;
1294  client->recv.stk = 0u;
1295  client->recv.cnt = 0u;
1296  client->evuser = NULL;
1297  client->priority = CA_PROTO_PRIORITY_MIN;
1298  client->disconnect = FALSE;
1302  client->recvBytesToDrain = 0u;
1303 
1304  return client;
1305 }
LIBCOM_API void epicsStdCall epicsSocketDestroy(SOCKET s)
Definition: osdSock.c:117
LIBCOM_API void *epicsStdCall freeListCalloc(void *pvt)
Definition: freeListLib.c:60
#define MAX_TCP
Definition: caProto.h:63
struct message_buffer recv
Definition: server.h:81
#define FALSE
Definition: dbDefs.h:32
unsigned cnt
Definition: server.h:70
struct client client
unsigned maxstk
Definition: server.h:68
char * pUserName
Definition: server.h:93
Definition: server.h:63
GLBLTYPE void * rsrvSmallBufFreeListTCP
Definition: server.h:203
#define CA_UKN_MINOR_VERSION
Definition: caProto.h:29
epicsEventId blockSem
Definition: server.h:95
#define NULL
Definition: catime.c:38
LIBCOM_API int epicsStdCall osiSufficentSpaceInPool(size_t contiguousBlockSize)
Checks if a memory block of a specific size can be safely allocated.
Definition: osdPoolStatus.c:19
SOCKET sock
Definition: server.h:96
unsigned stk
Definition: server.h:67
int proto
Definition: server.h:97
ELLLIST putNotifyQue
Definition: server.h:88
struct sockaddr_in addr
Definition: server.h:89
void destroy_client(struct client *client)
char * pHostName
Definition: server.h:94
GLBLTYPE void * rsrvClientFreeList
Definition: server.h:200
epicsMutexId chanListLock
Definition: server.h:84
char disconnect
Definition: server.h:103
epicsThreadId tid
Definition: server.h:98
Definition: server.h:76
struct message_buffer send
Definition: server.h:79
epicsTimeStamp time_at_last_recv
Definition: server.h:91
unsigned recvBytesToDrain
Definition: server.h:101
int epicsStdCall epicsTimeGetCurrent(epicsTimeStamp *pDest)
Get current time into *pDest.
#define CA_PROTO_PRIORITY_MIN
Definition: caProto.h:66
#define epicsPrintf
Definition: errlog.h:51
LIBCOM_API size_t epicsStdCall freeListItemsAvail(void *pvt)
Definition: freeListLib.c:171
epicsMutexId lock
Definition: server.h:82
char * buf
Definition: server.h:65
epicsMutexId eventqLock
Definition: server.h:85
#define MAX_UDP_RECV
Definition: caProto.h:61
ELLLIST chanPendingUpdateARList
Definition: server.h:87
#define ellInit(PLIST)
Initialize a list type.
Definition: ellLib.h:76
#define epicsMutexCreate()
Create an epicsMutex semaphore for use from C code.
Definition: epicsMutex.h:168
void * evuser
Definition: server.h:92
unsigned minor_version_number
Definition: server.h:99
ELLLIST chanList
Definition: server.h:86
epicsMutexId putNotifyLock
Definition: server.h:83
epicsTimeStamp time_at_last_send
Definition: server.h:90
unsigned priority
Definition: server.h:102
LIBCOM_API epicsEventId epicsEventCreate(epicsEventInitialState initialState)
Create an epicsEvent for use from C code, or return NULL.
Definition: osdEvent.c:47
enum messageBufferType type
Definition: server.h:71
#define MAX_UDP_SEND
Definition: caProto.h:62
struct client* create_tcp_client ( SOCKET  sock,
const osiSockAddr peerAddr 
)

Definition at line 1402 of file caservertask.c.

1403 {
1404  int status;
1405  struct client *client;
1406  int intTrue = TRUE;
1407  unsigned priorityOfEvents;
1408 
1409  /* socket passed in is destroyed here if unsuccessful */
1410  client = create_client ( sock, IPPROTO_TCP );
1411  if ( ! client ) {
1412  return NULL;
1413  }
1414 
1415  client->addr = peerAddr->ia;
1416  if(asCheckClientIP) {
1417  epicsUInt32 ip = ntohl(client->addr.sin_addr.s_addr);
1418  client->pHostName = malloc(24);
1419  if(!client->pHostName) {
1420  destroy_client ( client );
1421  return NULL;
1422  }
1423  epicsSnprintf(client->pHostName, 24,
1424  "%u.%u.%u.%u",
1425  (ip>>24)&0xff,
1426  (ip>>16)&0xff,
1427  (ip>>8)&0xff,
1428  (ip>>0)&0xff);
1429  }
1430 
1431  /*
1432  * see TCP(4P) this seems to make unsolicited single events much
1433  * faster. I take care of queue up as load increases.
1434  */
1435  status = setsockopt ( sock, IPPROTO_TCP, TCP_NODELAY,
1436  (char *) &intTrue, sizeof (intTrue) );
1437  if (status < 0) {
1438  errlogPrintf ( "CAS: TCP_NODELAY option set failed\n" );
1439  destroy_client ( client );
1440  return NULL;
1441  }
1442 
1443  /*
1444  * turn on KEEPALIVE so if the client crashes
1445  * this task will find out and exit
1446  */
1447  status = setsockopt ( sock, SOL_SOCKET, SO_KEEPALIVE,
1448  (char *) &intTrue, sizeof (intTrue) );
1449  if ( status < 0 ) {
1450  errlogPrintf ( "CAS: SO_KEEPALIVE option set failed\n" );
1451  destroy_client ( client );
1452  return NULL;
1453  }
1454 
1455  /*
1456  * some concern that vxWorks will run out of mBuf's
1457  * if this change is made
1458  *
1459  * joh 11-10-98
1460  */
1461 #if 0
1462  /*
1463  * set TCP buffer sizes to be synergistic
1464  * with CA internal buffering
1465  */
1466  i = MAX_MSG_SIZE;
1467  status = setsockopt ( sock, SOL_SOCKET, SO_SNDBUF, (char *) &i, sizeof (i) );
1468  if (status < 0) {
1469  errlogPrintf ( "CAS: SO_SNDBUF set failed\n" );
1470  destroy_client ( client );
1471  return NULL;
1472  }
1473  i = MAX_MSG_SIZE;
1474  status = setsockopt ( sock, SOL_SOCKET, SO_RCVBUF, (char *) &i, sizeof (i) );
1475  if (status < 0) {
1476  errlogPrintf ( "CAS: SO_RCVBUF set failed\n" );
1477  destroy_client ( client );
1478  return NULL;
1479  }
1480 #endif
1481 
1482  client->evuser = (struct event_user *) db_init_events ();
1483  if ( ! client->evuser ) {
1484  errlogPrintf ("CAS: unable to init the event facility\n");
1485  destroy_tcp_client (client);
1486  return NULL;
1487  }
1488 
1489  status = db_add_extra_labor_event ( client->evuser, rsrv_extra_labor, client );
1490  if (status != DB_EVENT_OK) {
1491  errlogPrintf("CAS: unable to setup the event facility\n");
1492  destroy_tcp_client (client);
1493  return NULL;
1494  }
1495 
1496  {
1498 
1500  if ( tbs != epicsThreadBooleanStatusSuccess ) {
1501  priorityOfEvents = epicsThreadPriorityCAServerLow;
1502  }
1503  }
1504 
1505  status = db_start_events ( client->evuser, "CAS-event",
1506  NULL, NULL, priorityOfEvents );
1507  if ( status != DB_EVENT_OK ) {
1508  errlogPrintf ( "CAS: unable to start the event facility\n" );
1509  destroy_tcp_client ( client );
1510  return NULL;
1511  }
1512 
1513  /*
1514  * add first version message should it be needed
1515  */
1516  rsrv_version_reply ( client );
1517 
1518  if ( CASDEBUG > 0 ) {
1519  char buf[64];
1520  ipAddrToDottedIP ( &client->addr, buf, sizeof(buf) );
1521  errlogPrintf ( "CAS: conn req from %s\n", buf );
1522  }
1523 
1524  return client;
1525 }
GLBLTYPE int CASDEBUG
Definition: server.h:190
int rsrv_version_reply(struct client *client)
Definition: camessage.c:2141
epicsThreadBooleanStatus
Definition: epicsThread.h:93
LIBCOM_API int asCheckClientIP
Definition: asLibRoutines.c:31
struct client client
void destroy_tcp_client(struct client *client)
pvd::Status status
int i
Definition: scan.c:967
struct sockaddr_in ia
Definition: osiSock.h:157
#define NULL
Definition: catime.c:38
unsigned int epicsUInt32
Definition: epicsTypes.h:43
SOCKET sock
Definition: server.h:96
struct sockaddr_in addr
Definition: server.h:89
void destroy_client(struct client *client)
char * pHostName
Definition: server.h:94
Definition: server.h:76
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
struct client * create_client(SOCKET sock, int proto)
LIBCOM_API epicsThreadBooleanStatus epicsStdCall epicsThreadHighestPriorityLevelBelow(unsigned int priority, unsigned *pPriorityJustBelow)
Definition: osdThread.c:740
#define epicsThreadPriorityCAServerLow
Definition: epicsThread.h:80
#define TRUE
Definition: dbDefs.h:27
#define MAX_MSG_SIZE
Definition: caProto.h:64
void * evuser
Definition: server.h:92
void rsrv_extra_labor(void *pArg)
Definition: camessage.c:1497
LIBCOM_API int epicsStdCall epicsSnprintf(char *str, size_t size, const char *format,...) EPICS_PRINTF_STYLE(3
unsigned epicsStdCall ipAddrToDottedIP(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:144
void destroy_client ( struct client client)

Definition at line 1047 of file caservertask.c.

1048 {
1049  if ( ! client ) {
1050  return;
1051  }
1052 
1053  if ( client->tid != 0 ) {
1054  taskwdRemove ( client->tid );
1055  }
1056 
1057  if ( client->sock != INVALID_SOCKET ) {
1058  epicsSocketDestroy ( client->sock );
1059  }
1060 
1061  if ( client->proto == IPPROTO_TCP ) {
1062  if ( client->send.buf ) {
1063  if ( client->send.type == mbtSmallTCP ) {
1065  }
1066  else if ( client->send.type == mbtLargeTCP ) {
1069  else
1070  free(client->send.buf);
1071  }
1072  else {
1073  errlogPrintf ( "CAS: Corrupt send buffer free list type code=%u during client cleanup?\n",
1074  client->send.type );
1075  }
1076  }
1077  if ( client->recv.buf ) {
1078  if ( client->recv.type == mbtSmallTCP ) {
1080  }
1081  else if ( client->recv.type == mbtLargeTCP ) {
1084  else
1085  free(client->recv.buf);
1086  }
1087  else {
1088  errlogPrintf ( "CAS: Corrupt recv buffer free list type code=%u during client cleanup?\n",
1089  client->send.type );
1090  }
1091  }
1092  }
1093  else if ( client->proto == IPPROTO_UDP ) {
1094  if ( client->send.buf ) {
1095  free ( client->send.buf );
1096  }
1097  if ( client->recv.buf ) {
1098  free ( client->recv.buf );
1099  }
1100  }
1101 
1102  if ( client->eventqLock ) {
1103  epicsMutexDestroy ( client->eventqLock );
1104  }
1105 
1106  if ( client->chanListLock ) {
1107  epicsMutexDestroy ( client->chanListLock );
1108  }
1109 
1110  if ( client->putNotifyLock ) {
1111  epicsMutexDestroy ( client->putNotifyLock );
1112  }
1113 
1114  if ( client->lock ) {
1115  epicsMutexDestroy ( client->lock );
1116  }
1117 
1118  if ( client->blockSem ) {
1119  epicsEventDestroy ( client->blockSem );
1120  }
1121 
1122  if ( client->pUserName ) {
1123  free ( client->pUserName );
1124  }
1125 
1126  if ( client->pHostName ) {
1127  free ( client->pHostName );
1128  }
1129 
1130  freeListFree ( rsrvClientFreeList, client );
1131 }
LIBCOM_API void epicsStdCall epicsSocketDestroy(SOCKET s)
Definition: osdSock.c:117
struct message_buffer recv
Definition: server.h:81
#define INVALID_SOCKET
Definition: osdSock.h:32
void epicsStdCall epicsMutexDestroy(epicsMutexId pmutexNode)
Destroy an epicsMutex semaphore.
Definition: epicsMutex.cpp:127
char * pUserName
Definition: server.h:93
GLBLTYPE void * rsrvSmallBufFreeListTCP
Definition: server.h:203
epicsEventId blockSem
Definition: server.h:95
SOCKET sock
Definition: server.h:96
int proto
Definition: server.h:97
char * pHostName
Definition: server.h:94
GLBLTYPE void * rsrvClientFreeList
Definition: server.h:200
epicsMutexId chanListLock
Definition: server.h:84
epicsThreadId tid
Definition: server.h:98
struct message_buffer send
Definition: server.h:79
LIBCOM_API void epicsStdCall freeListFree(void *pvt, void *pmem)
Definition: freeListLib.c:131
GLBLTYPE void * rsrvLargeBufFreeListTCP
Definition: server.h:204
epicsMutexId lock
Definition: server.h:82
char * buf
Definition: server.h:65
LIBCOM_API void epicsEventDestroy(epicsEventId id)
Destroy an epicsEvent and any resources it holds.
Definition: osdEvent.c:70
epicsMutexId eventqLock
Definition: server.h:85
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
void taskwdRemove(epicsThreadId tid)
Definition: taskwd.c:206
epicsMutexId putNotifyLock
Definition: server.h:83
enum messageBufferType type
Definition: server.h:71
void destroy_tcp_client ( struct client client)

Definition at line 1191 of file caservertask.c.

1192 {
1193  int status;
1194 
1195  if ( CASDEBUG > 0 ) {
1196  errlogPrintf ( "CAS: Connection %d Terminated\n", (int)client->sock );
1197  }
1198 
1199  if ( client->evuser ) {
1200  /*
1201  * turn off extra labor callbacks from the event thread
1202  */
1203  status = db_add_extra_labor_event ( client->evuser, NULL, NULL );
1204  assert ( ! status );
1205 
1206  /*
1207  * wait for extra labor in progress to comple
1208  */
1209  db_flush_extra_labor_event ( client->evuser );
1210  }
1211 
1212  destroyAllChannels ( client, & client->chanList );
1213  destroyAllChannels ( client, & client->chanPendingUpdateARList );
1214 
1215  if ( client->evuser ) {
1216  db_close_events (client->evuser);
1217  }
1218 
1219  destroy_client ( client );
1220 }
GLBLTYPE int CASDEBUG
Definition: server.h:190
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
pvd::Status status
#define NULL
Definition: catime.c:38
SOCKET sock
Definition: server.h:96
void destroy_client(struct client *client)
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
ELLLIST chanPendingUpdateARList
Definition: server.h:87
void * evuser
Definition: server.h:92
ELLLIST chanList
Definition: server.h:86
void rsrv_register_server ( void  )

Definition at line 1555 of file caservertask.c.

1556 {
1557  dbRegisterServer(&rsrv_server);
1558 }

Variable Documentation

epicsThreadPrivateId rsrvCurrentClient

Definition at line 50 of file caservertask.c.