Skip to content

Commit

Permalink
Add a class method to cac for creating sockets
Browse files Browse the repository at this point in the history
When EPICS_CAC_AVOID_LOW_FDS exists in the environment, all client
socket fds are renumbered to above FD_SETSIZE, allowing the client
library to play nice with applications like the CA gateway which use
select() for their own sockets.
  • Loading branch information
anjohnson committed Jan 15, 2025
1 parent 8cfde70 commit 3047681
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modules/ca/src/client/ca_client_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ ca_client_context::ca_client_context ( bool enablePreemptiveCallback ) :
}
}

this->sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
this->sock = cac::SocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
if ( this->sock == INVALID_SOCKET ) {
char sockErrBuf[64];
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
Expand Down
15 changes: 15 additions & 0 deletions modules/ca/src/client/cac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,21 @@ unsigned cac::highestPriorityLevelBelow ( unsigned priority )
return belowPriority;
}

SOCKET cac::SocketCreate (
int domain,
int type,
int protocol )
{
SOCKET sock = epicsSocketCreate ( domain, type, protocol );
#ifdef HAS_SOCK_RENUMBER
static bool renumber = getenv ( "EPICS_CAC_AVOID_LOW_FDS" );
if ( renumber ) {
sock = epicsSocketRenumber ( sock );
}
#endif
return sock;
}

//
// set the push pending flag on all virtual circuits
//
Expand Down
2 changes: 2 additions & 0 deletions modules/ca/src/client/cac.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ class cac :

const char * pLocalHostName ();

static SOCKET SocketCreate ( int domain, int type, int protocol );

private:
epicsSingleton < localHostName > :: reference _refLocalHostName;
chronIntIdResTable < nciu > chanTable;
Expand Down
2 changes: 1 addition & 1 deletion modules/ca/src/client/tcpiiu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ tcpiiu::tcpiiu (
if(!pCurData)
throw std::bad_alloc();

this->sock = epicsSocketCreate ( AF_INET, SOCK_STREAM, IPPROTO_TCP );
this->sock = cac::SocketCreate ( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( this->sock == INVALID_SOCKET ) {
freeListFree(this->cacRef.tcpSmallRecvBufFreeList, this->pCurData);
char sockErrBuf[64];
Expand Down
4 changes: 2 additions & 2 deletions modules/ca/src/client/udpiiu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ udpiiu::udpiiu (
envGetInetPortConfigParam ( &EPICS_CA_REPEATER_PORT,
static_cast <unsigned short> (CA_REPEATER_PORT) );

this->sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
this->sock = cac::SocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
if ( this->sock == INVALID_SOCKET ) {
char sockErrBuf[64];
epicsSocketConvertErrnoToString (
Expand Down Expand Up @@ -594,7 +594,7 @@ void epicsStdCall caStartRepeaterIfNotInstalled ( unsigned repeaterPort )
return;
}

tmpSock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
tmpSock = cac::SocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
if ( tmpSock != INVALID_SOCKET ) {
ca_uint16_t port = static_cast < ca_uint16_t > ( repeaterPort );
memset ( (char *) &bd, 0, sizeof ( bd ) );
Expand Down

0 comments on commit 3047681

Please sign in to comment.