This is Unofficial EPICS BASE Doxygen Site
online_notify.c File Reference
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <cantProceed.h>
#include "addrList.h"
#include "dbDefs.h"
#include "envDefs.h"
#include "errlog.h"
#include "osiSock.h"
#include "taskwd.h"
#include "server.h"
+ Include dependency graph for online_notify.c:

Go to the source code of this file.

Macros

#define epicsExportSharedSymbols
 

Functions

void rsrv_online_notify_task (void *pParm)
 

Macro Definition Documentation

#define epicsExportSharedSymbols

Definition at line 34 of file online_notify.c.

Function Documentation

void rsrv_online_notify_task ( void *  pParm)

Definition at line 40 of file online_notify.c.

41 {
42  double delay;
43  double maxdelay;
44  long longStatus;
45  double maxPeriod;
46  caHdr msg;
47  int status;
48  ca_uint32_t beaconCounter = 0;
49  int *lastError;
50 
52 
54  longStatus = envGetDoubleConfigParam ( & EPICS_CAS_BEACON_PERIOD, & maxPeriod );
55  }
56  else {
57  longStatus = envGetDoubleConfigParam ( & EPICS_CA_BEACON_PERIOD, & maxPeriod );
58  }
59  if (longStatus || maxPeriod<=0.0) {
60  maxPeriod = 15.0;
61  epicsPrintf ("EPICS \"%s\" float fetch failed\n",
63  epicsPrintf ("Setting \"%s\" = %f\n",
64  EPICS_CAS_BEACON_PERIOD.name, maxPeriod);
65  }
66 
67  delay = 0.02; /* initial beacon period in sec */
68  maxdelay = maxPeriod;
69 
70  memset((char *)&msg, 0, sizeof msg);
71  msg.m_cmmd = htons (CA_PROTO_RSRV_IS_UP);
72  msg.m_count = htons (ca_server_port);
74 
75  /* beaconAddrList should not change after rsrv_init(), which then starts this thread */
76  lastError = callocMustSucceed(ellCount(&beaconAddrList), sizeof(*lastError), "rsrv_online_notify_task lastError");
77 
79 
80  while (TRUE) {
81  ELLNODE *cur;
82  unsigned i;
83 
84  /* send beacon to each interface */
85  for(i=0, cur=ellFirst(&beaconAddrList); cur; i++, cur=ellNext(cur))
86  {
88  status = sendto (beaconSocket, (char *)&msg, sizeof(msg), 0,
89  &pAddr->addr.sa, sizeof(pAddr->addr));
90  if (status < 0) {
91  int err = SOCKERRNO;
92  if(err != lastError[i]) {
93  char sockErrBuf[64];
94  char sockDipBuf[22];
95 
96  epicsSocketConvertErrorToString(sockErrBuf, sizeof(sockErrBuf), err);
97  ipAddrToDottedIP(&pAddr->addr.ia, sockDipBuf, sizeof(sockDipBuf));
98  errlogPrintf ( "CAS: CA beacon send to %s error: %s\n",
99  sockDipBuf, sockErrBuf);
100 
101  lastError[i] = err;
102  }
103  }
104  else {
105  assert (status == sizeof(msg));
106  if(lastError[i]) {
107  char sockDipBuf[22];
108 
109  ipAddrToDottedIP(&pAddr->addr.ia, sockDipBuf, sizeof(sockDipBuf));
110  errlogPrintf ( "CAS: CA beacon send to %s ok\n",
111  sockDipBuf);
112  }
113  lastError[i] = 0;
114  }
115  }
116 
117  epicsThreadSleep(delay);
118  if (delay<maxdelay) {
119  delay *= 2.0;
120  if (delay>maxdelay) {
121  delay = maxdelay;
122  }
123  }
124 
125  msg.m_cid = htonl ( beaconCounter++ ); /* expected to overflow */
126 
127  while (beacon_ctl == ctlPause) {
128  epicsThreadSleep(0.1);
129  delay = 0.02; /* Restart beacon timing if paused */
130  }
131  }
132 
133  free(lastError);
134 }
void taskwdInsert(epicsThreadId tid, TASKWDFUNC callback, void *usr)
Definition: taskwd.c:176
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
#define ellCount(PLIST)
Report the number of nodes in a list.
Definition: ellLib.h:84
osiSockAddr addr
Definition: osiSock.h:163
pvd::Status status
LIBCOM_API const ENV_PARAM EPICS_CA_BEACON_PERIOD
deprecated
char * name
Name of the parameter.
Definition: envDefs.h:42
#define CONTAINER(ptr, structure, member)
Find parent object from a member pointer.
Definition: dbDefs.h:66
int i
Definition: scan.c:967
LIBCOM_API const char *epicsStdCall envGetConfigParamPtr(const ENV_PARAM *pParam)
Get a configuration parameter&#39;s value or default string.
Definition: envSubr.c:81
struct sockaddr sa
Definition: osiSock.h:158
GLBLTYPE SOCKET beaconSocket
Definition: server.h:195
struct sockaddr_in ia
Definition: osiSock.h:157
unsigned int ca_uint32_t
Definition: caProto.h:76
#define NULL
Definition: catime.c:38
#define CA_MINOR_PROTOCOL_REVISION
Definition: nciu.h:35
GLBLTYPE ELLLIST beaconAddrList
Definition: server.h:194
ca_uint16_t m_cmmd
Definition: caProto.h:161
#define ellNext(PNODE)
Find the next node in list.
Definition: ellLib.h:99
LIBCOM_API long epicsStdCall envGetDoubleConfigParam(const ENV_PARAM *pParam, double *pDouble)
Get value of a double configuration parameter.
Definition: envSubr.c:191
#define epicsEventSignal(ID)
A synonym for epicsEventTrigger().
Definition: epicsEvent.h:172
ca_uint32_t m_cid
Definition: caProto.h:165
#define epicsPrintf
Definition: errlog.h:51
LIBCOM_API const ENV_PARAM EPICS_CAS_BEACON_PERIOD
ca_uint16_t m_dataType
Definition: caProto.h:163
LIBCOM_API void * callocMustSucceed(size_t count, size_t size, const char *msg)
A calloc() that never returns NULL.
Definition: cantProceed.c:22
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
List node type.
Definition: ellLib.h:45
ca_uint16_t m_count
Definition: caProto.h:164
#define SOCKERRNO
Definition: osdSock.h:33
GLBLTYPE enum ctl beacon_ctl
Definition: server.h:213
#define TRUE
Definition: dbDefs.h:27
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
GLBLTYPE unsigned short ca_server_port
Definition: server.h:191
GLBLTYPE epicsEventId beacon_startStopEvent
Definition: server.h:210
ELLNODE node
Definition: server.h:77
#define CA_PROTO_RSRV_IS_UP
Definition: caProto.h:96
void epicsSocketConvertErrorToString(char *pBuf, unsigned bufSize, int theSockError)
unsigned epicsStdCall ipAddrToDottedIP(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:144
#define ellFirst(PLIST)
Find the first node in list.
Definition: ellLib.h:89
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810