This is Unofficial EPICS BASE Doxygen Site
server.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /*
11  * Author: Jeffrey O. Hill
12  *
13  */
14 
15 #ifndef INCLserverh
16 #define INCLserverh
17 
18 #ifdef epicsExportSharedSymbols
19 # define rsrvRestore_epicsExportSharedSymbols
20 # undef epicsExportSharedSymbols
21 #endif /* ifdef epicsExportSharedSymbols */
22 
23 #include "epicsThread.h"
24 #include "epicsMutex.h"
25 #include "epicsEvent.h"
26 #include "bucketLib.h"
27 #include "asLib.h"
28 #include "dbChannel.h"
29 #include "dbNotify.h"
30 #define CA_MINOR_PROTOCOL_REVISION 13
31 #include "caProto.h"
32 #include "ellLib.h"
33 #include "epicsTime.h"
34 #include "epicsAssert.h"
35 #include "osiSock.h"
36 
37 #ifdef rsrvRestore_epicsExportSharedSymbols
38 #define epicsExportSharedSymbols
39 #endif
40 
41 /* a modified ca header with capacity for large arrays */
42 typedef struct caHdrLargeArray {
43  ca_uint32_t m_postsize; /* size of message extension */
44  ca_uint32_t m_count; /* operation data count */
45  ca_uint32_t m_cid; /* channel identifier */
46  ca_uint32_t m_available; /* protocol stub dependent */
47  ca_uint16_t m_dataType; /* operation data type */
48  ca_uint16_t m_cmmd; /* operation to be performed */
50 
51 /*
52  * !! buf must be the first item in this structure !!
53  * This guarantees that buf will have 8 byte natural
54  * alignment
55  *
56  * The terminating unsigned pad0 field is there to force the
57  * length of the message_buffer to be a multiple of 8 bytes.
58  * This is due to the sequential placing of two message_buffer
59  * structures (trans, rec) within the client structure.
60  * Eight-byte alignment is required by the Sparc 5 and other RISC
61  * processors.
62  */
65  char *buf;
67  unsigned stk;
68  unsigned maxstk;
70  unsigned cnt;
72 };
73 
75 
76 typedef struct client {
79  struct message_buffer send;
81  struct message_buffer recv;
89  struct sockaddr_in addr; /* peer address, TCP only */
92  void *evuser;
93  char *pUserName;
94  char *pHostName;
95  epicsEventId blockSem; /* used whenever the client blocks */
96  SOCKET sock, udpRecv;
97  int proto;
100  ca_uint32_t seqNoOfReq; /* for udp */
102  unsigned priority;
103  char disconnect; /* disconnect detected */
104 } client;
105 
106 /* Channel state shows which struct client list a
107  * channel_in_us::node is in.
108  *
109  * client::chanList
110  * rsrvCS_pendConnectResp, rsrvCS_inService
111  * client::chanPendingUpdateARList
112  * rsrvCS_pendConnectRespUpdatePendAR, rsrvCS_inServiceUpdatePendAR
113  * Not in any list
114  * rsrvCS_shutdown
115  *
116  * rsrvCS_invalid is not used
117  */
125 };
126 
127 /*
128  * per channel structure
129  * (stored in chanList or chanPendingUpdateARList off of a client block)
130  */
134  struct client *client;
135  struct rsrv_put_notify *pPutNotify; /* potential active put notify */
136  const unsigned cid; /* client id */
137  const unsigned sid; /* server id */
138  epicsTimeStamp time_at_creation; /* for UDP timeout */
139  struct dbChannel *dbch;
141  enum rsrvChanState state;
142 };
143 
144 /*
145  * Event block extension for channel access
146  * some things duplicated for speed
147  */
148 struct event_ext {
152  struct event_block *pdbev; /* ptr to db event block */
153  unsigned size; /* for speed */
154  unsigned mask;
155  char modified; /* mod & ev flw ctrl enbl */
156 };
157 
158 typedef struct {
160  osiSockAddr tcpAddr, /* TCP listener endpoint */
161  udpAddr, /* UDP name unicast receiver endpoint */
162  udpbcastAddr; /* UDP name broadcast receiver endpoint */
163  SOCKET tcp, udp, udpbcast;
164  struct client *client, *bclient;
165 
166  unsigned int startbcast:1;
168 
170 
171 /* NOTE: external used so they remember the state across loads */
172 #ifdef GLBLSOURCE
173 # define GLBLTYPE
174 # define GLBLTYPE_INIT(A) = A
175 #else
176 # define GLBLTYPE extern
177 # define GLBLTYPE_INIT(A)
178 #endif
179 
180 /*
181  * for debug-level dependent messages:
182  */
183 #ifdef DEBUG
184 # define DLOG(LEVEL,ARGSINPAREN) \
185  if (CASDEBUG > LEVEL) errlogPrintf ARGSINPAREN
186 #else
187 # define DLOG(LEVEL,ARGSINPAREN)
188 #endif
189 
193 GLBLTYPE ELLLIST servers; /* rsrv_iface_config::node, read-only after rsrv_init() */
199 GLBLTYPE BUCKET *pCaBucket; /* locked by clientQlock */
207 GLBLTYPE unsigned rsrvChannelCount; /* locked by clientQlock */
208 
212 GLBLTYPE volatile enum ctl casudp_ctl;
213 GLBLTYPE volatile enum ctl beacon_ctl;
214 GLBLTYPE volatile enum ctl castcp_ctl;
215 
216 GLBLTYPE unsigned int threadPrios[5];
217 
218 #define CAS_HASH_TABLE_SIZE 4096
219 
220 #define SEND_LOCK(CLIENT) epicsMutexMustLock((CLIENT)->lock)
221 #define SEND_UNLOCK(CLIENT) epicsMutexUnlock((CLIENT)->lock)
222 
223 #define LOCK_CLIENTQ epicsMutexMustLock (clientQlock);
224 #define UNLOCK_CLIENTQ epicsMutexUnlock (clientQlock);
225 
226 #ifdef __cplusplus
227 extern "C" {
228 #endif
229 
230 void camsgtask (void *client);
231 void cas_send_bs_msg ( struct client *pclient, int lock_needed );
232 void cas_send_dg_msg ( struct client *pclient );
233 void rsrv_online_notify_task (void *);
234 void cast_server (void *);
235 struct client *create_client ( SOCKET sock, int proto );
236 void destroy_client ( struct client * );
237 struct client *create_tcp_client ( SOCKET sock, const osiSockAddr* peerAddr );
238 void destroy_tcp_client ( struct client * );
239 void casAttachThreadToClient ( struct client * );
240 int camessage ( struct client *client );
241 void rsrv_extra_labor ( void * pArg );
242 int rsrvCheckPut ( const struct channel_in_use *pciu );
243 int rsrv_version_reply ( struct client *client );
244 void rsrvFreePutNotify ( struct client *pClient,
245  struct rsrv_put_notify *pNotify );
246 void initializePutNotifyFreeList (void);
247 unsigned rsrvSizeOfPutNotify ( struct rsrv_put_notify *pNotify );
248 
249 /*
250  * inclming protocol maintetnance
251  */
252 void casExpandRecvBuffer ( struct client *pClient, ca_uint32_t size );
253 
254 /*
255  * outgoing protocol maintenance
256  */
257 void casExpandSendBuffer ( struct client *pClient, ca_uint32_t size );
258 int cas_copy_in_header (
259  struct client *pClient, ca_uint16_t response, ca_uint32_t payloadSize,
260  ca_uint16_t dataType, ca_uint32_t nElem, ca_uint32_t cid,
261  ca_uint32_t responseSpecific, void **pPayload );
262 void cas_set_header_cid ( struct client *pClient, ca_uint32_t );
263 void cas_set_header_count (struct client *pClient, ca_uint32_t count);
264 void cas_commit_msg ( struct client *pClient, ca_uint32_t size );
265 
266 #ifdef __cplusplus
267 }
268 #endif
269 
270 #endif /*INCLserverh*/
struct dbChannel * dbch
Definition: server.h:139
epicsTimeStamp time_at_creation
Definition: server.h:138
GLBLTYPE int CASDEBUG
Definition: server.h:190
SOCKET udpbcast
Definition: server.h:163
epicsThreadPrivateId rsrvCurrentClient
Definition: caservertask.c:50
unsigned cnt
Definition: server.h:70
struct client client
void cas_commit_msg(struct client *pClient, ca_uint32_t size)
Definition: caserverio.c:351
unsigned size
Definition: server.h:153
const unsigned sid
Definition: server.h:137
unsigned maxstk
Definition: server.h:68
An EPICS-specific replacement for ANSI C's assert.
char * pUserName
Definition: server.h:93
GLBLTYPE unsigned int threadPrios[5]
Definition: server.h:216
GLBLTYPE SOCKET beaconSocket
Definition: server.h:195
struct rsrv_put_notify * pPutNotify
Definition: server.h:135
ca_uint32_t m_postsize
GLBLTYPE ELLLIST casMCastAddrList
Definition: server.h:196
Definition: server.h:63
void cas_send_bs_msg(struct client *pclient, int lock_needed)
Definition: caserverio.c:44
osiSockAddr udpbcastAddr
Definition: server.h:160
#define GLBLTYPE
Definition: server.h:176
void casExpandRecvBuffer(struct client *pClient, ca_uint32_t size)
ELLNODE node
Definition: server.h:159
GLBLTYPE void * rsrvSmallBufFreeListTCP
Definition: server.h:203
GLBLTYPE epicsMutexId clientQlock
Definition: server.h:198
pvd::StructureConstPtr type
unsigned int ca_uint32_t
Definition: caProto.h:76
struct caHdrLargeArray caHdrLargeArray
epicsEventId blockSem
Definition: server.h:95
void rsrv_extra_labor(void *pArg)
Definition: camessage.c:1497
ca_uint16_t m_dataType
struct client * client
Definition: server.h:164
unsigned int epicsUInt32
Definition: epicsTypes.h:43
#define ELLLIST_INIT
Value of an empty list.
Definition: ellLib.h:63
SOCKET sock
Definition: server.h:96
const unsigned cid
Definition: server.h:136
unsigned short ca_uint16_t
Definition: caProto.h:75
unsigned stk
Definition: server.h:67
rsrvChanState
Definition: server.h:118
int proto
Definition: server.h:97
ELLLIST putNotifyQue
Definition: server.h:88
GLBLTYPE ELLLIST casIntfAddrList
Definition: server.h:196
A doubly-linked list library.
char * pHostName
Definition: server.h:94
GLBLTYPE ELLLIST beaconAddrList
Definition: server.h:194
GLBLTYPE void * rsrvClientFreeList
Definition: server.h:200
int rsrv_version_reply(struct client *client)
Definition: camessage.c:2141
caHdrLargeArray msg
Definition: server.h:150
ca_uint32_t m_count
epicsMutexId chanListLock
Definition: server.h:84
void destroy_tcp_client(struct client *)
char disconnect
Definition: server.h:103
int rsrvCheckPut(const struct channel_in_use *pciu)
Definition: camessage.c:2566
epicsThreadId tid
Definition: server.h:98
Definition: server.h:169
Definition: server.h:76
epicsTimeStamp time_at_last_recv
Definition: server.h:91
APIs for the epicsMutex mutual exclusion semaphore.
struct client * client
Definition: server.h:134
unsigned recvBytesToDrain
Definition: server.h:101
GLBLTYPE void * rsrvLargeBufFreeListTCP
Definition: server.h:204
epicsMutexId lock
Definition: server.h:82
char * buf
Definition: server.h:65
void cas_set_header_cid(struct client *pClient, ca_uint32_t)
Definition: caserverio.c:329
void cas_set_header_count(struct client *pClient, ca_uint32_t count)
Definition: caserverio.c:335
int SOCKET
Definition: osdSock.h:31
ASCLIENTPVT asClientPVT
Definition: server.h:140
void casAttachThreadToClient(struct client *)
struct client * create_tcp_client(SOCKET sock, const osiSockAddr *peerAddr)
GLBLTYPE BUCKET * pCaBucket
Definition: server.h:199
epicsMutexId eventqLock
Definition: server.h:85
List node type.
Definition: ellLib.h:45
GLBLTYPE enum ctl castcp_ctl
Definition: server.h:214
GLBLTYPE epicsEventId casudp_startStopEvent
Definition: server.h:209
APIs for the epicsEvent binary semaphore.
GLBLTYPE void * rsrvChanFreeList
Definition: server.h:201
unsigned mask
Definition: server.h:154
GLBLTYPE unsigned short ca_beacon_port
Definition: server.h:191
GLBLTYPE unsigned rsrvSizeofLargeBufTCP
Definition: server.h:205
ca_uint32_t m_cid
GLBLTYPE void * rsrvEventFreeList
Definition: server.h:202
#define GLBLTYPE_INIT(A)
Definition: server.h:177
void casExpandSendBuffer(struct client *pClient, ca_uint32_t size)
unsigned rsrvSizeOfPutNotify(struct rsrv_put_notify *pNotify)
Definition: camessage.c:1604
GLBLTYPE epicsEventId castcp_startStopEvent
Definition: server.h:211
char modified
Definition: server.h:155
ELLNODE node
Definition: server.h:149
ELLLIST chanPendingUpdateARList
Definition: server.h:87
ctl
Definition: server.h:169
ELLLIST eventq
Definition: server.h:133
ELLNODE node
Definition: server.h:132
GLBLTYPE epicsUInt32 * casIgnoreAddrs
Definition: server.h:197
EPICS time stamp, for use from C code.
Definition: epicsTime.h:33
GLBLTYPE enum ctl beacon_ctl
Definition: server.h:213
messageBufferType
Definition: server.h:63
void rsrv_online_notify_task(void *)
Definition: online_notify.c:40
A hash table. Do not use for new code.
GLBLTYPE unsigned short ca_server_port
Definition: server.h:191
ca_uint16_t m_cmmd
GLBLTYPE epicsEventId beacon_startStopEvent
Definition: server.h:210
void camsgtask(void *client)
Definition: camsgtask.c:42
int camessage(struct client *client)
Definition: camessage.c:2391
struct channel_in_use * pciu
Definition: server.h:151
ca_uint32_t m_available
void * evuser
Definition: server.h:92
unsigned minor_version_number
Definition: server.h:99
ELLNODE node
Definition: server.h:77
void rsrvFreePutNotify(struct client *pClient, struct rsrv_put_notify *pNotify)
Definition: camessage.c:1616
EPICS time-stamps (epicsTimeStamp), epicsTime C++ class and C functions for handling wall-clock times...
ELLLIST chanList
Definition: server.h:86
void destroy_client(struct client *)
epicsMutexId putNotifyLock
Definition: server.h:83
List header type.
Definition: ellLib.h:56
void cas_send_dg_msg(struct client *pclient)
Definition: caserverio.c:173
C++ and C descriptions for a thread.
struct event_block * pdbev
Definition: server.h:152
epicsTimeStamp time_at_last_send
Definition: server.h:90
GLBLTYPE unsigned rsrvChannelCount
Definition: server.h:207
ca_uint32_t seqNoOfReq
Definition: server.h:100
GLBLTYPE ELLLIST servers
Definition: server.h:193
unsigned priority
Definition: server.h:102
GLBLTYPE unsigned short ca_udp_port
Definition: server.h:191
SOCKET udpRecv
Definition: server.h:96
int cas_copy_in_header(struct client *pClient, ca_uint16_t response, ca_uint32_t payloadSize, ca_uint16_t dataType, ca_uint32_t nElem, ca_uint32_t cid, ca_uint32_t responseSpecific, void **pPayload)
Definition: caserverio.c:251
GLBLTYPE enum ctl casudp_ctl
Definition: server.h:212
void cast_server(void *)
Definition: cast_server.c:116
GLBLTYPE void * rsrvPutNotifyFreeList
Definition: server.h:206
Internal: Hash table structure.
Definition: bucketLib.h:48
struct client * create_client(SOCKET sock, int proto)
void initializePutNotifyFreeList(void)
Definition: camessage.c:1530