fixed base to use close on exec options whenever creating a socket
on posix compliant systems
This commit is contained in:
@@ -46,7 +46,7 @@ ca_client_context::ca_client_context ( bool enablePreemptiveCallback ) :
|
||||
{
|
||||
static const unsigned short PORT_ANY = 0u;
|
||||
|
||||
this->sock = socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
this->sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
if ( this->sock == INVALID_SOCKET ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
@@ -64,7 +64,7 @@ ca_client_context::ca_client_context ( bool enablePreemptiveCallback ) :
|
||||
if ( status < 0 ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
this->printf (
|
||||
"%s: non blocking IO set fail because \"%s\"\n",
|
||||
__FILE__, sockErrBuf );
|
||||
@@ -84,7 +84,7 @@ ca_client_context::ca_client_context ( bool enablePreemptiveCallback ) :
|
||||
if ( status < 0 ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
this->printf (
|
||||
"CAC: unable to bind to an unconstrained "
|
||||
"address because = \"%s\"\n",
|
||||
@@ -100,12 +100,12 @@ ca_client_context::ca_client_context ( bool enablePreemptiveCallback ) :
|
||||
if ( status < 0 ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
this->printf ( "CAC: getsockname () error was \"%s\"\n", sockErrBuf );
|
||||
throwWithLocation ( noSocket () );
|
||||
}
|
||||
if ( tmpAddr.sa.sa_family != AF_INET) {
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
this->printf ( "CAC: UDP socket was not inet addr family\n" );
|
||||
throwWithLocation ( noSocket () );
|
||||
}
|
||||
@@ -131,7 +131,7 @@ ca_client_context::~ca_client_context ()
|
||||
( *this->fdRegFunc )
|
||||
( this->fdRegArg, this->sock, false );
|
||||
}
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
}
|
||||
|
||||
void ca_client_context::destroyChannel ( oldChannelNotify & chan )
|
||||
|
||||
@@ -100,7 +100,7 @@ int main ( int argc, char ** argv )
|
||||
|
||||
caStartRepeaterIfNotInstalled ( repeaterPort );
|
||||
|
||||
sock = socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
@@ -119,7 +119,7 @@ int main ( int argc, char ** argv )
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close ( sock );
|
||||
epicsSocketDestroy ( sock );
|
||||
errlogPrintf ( "casw: unable to bind to an unconstrained address because = \"%s\"\n",
|
||||
sockErrBuf );
|
||||
return -1;
|
||||
@@ -131,7 +131,7 @@ int main ( int argc, char ** argv )
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close ( sock );
|
||||
epicsSocketDestroy ( sock );
|
||||
errlogPrintf ( "casw: unable to set socket to nonblocking state because \"%s\"\n",
|
||||
sockErrBuf );
|
||||
return -1;
|
||||
@@ -153,7 +153,7 @@ int main ( int argc, char ** argv )
|
||||
|
||||
attemptNumber++;
|
||||
if ( attemptNumber > 100 ) {
|
||||
socket_close ( sock );
|
||||
epicsSocketDestroy ( sock );
|
||||
errlogPrintf ( "casw: unable to register with the CA repeater\n" );
|
||||
return -1;
|
||||
}
|
||||
@@ -165,7 +165,7 @@ int main ( int argc, char ** argv )
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close ( sock );
|
||||
epicsSocketDestroy ( sock );
|
||||
errlogPrintf ( "casw: unable to set socket to blocking state because \"%s\"\n",
|
||||
sockErrBuf );
|
||||
return -1;
|
||||
@@ -181,7 +181,7 @@ int main ( int argc, char ** argv )
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close ( sock );
|
||||
epicsSocketDestroy ( sock );
|
||||
errlogPrintf ("casw: error from recv was = \"%s\"\n",
|
||||
sockErrBuf );
|
||||
return -1;
|
||||
|
||||
@@ -115,7 +115,7 @@ static bool makeSocket ( unsigned short port, bool reuseAddr, SOCKET * pSock )
|
||||
} bd;
|
||||
int flag;
|
||||
|
||||
SOCKET sock = socket ( AF_INET, SOCK_DGRAM, 0 );
|
||||
SOCKET sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, 0 );
|
||||
if ( sock == INVALID_SOCKET ) {
|
||||
return false;
|
||||
}
|
||||
@@ -131,7 +131,7 @@ static bool makeSocket ( unsigned short port, bool reuseAddr, SOCKET * pSock )
|
||||
bd.ia.sin_port = epicsHTON16 (port);
|
||||
status = bind ( sock, &bd.sa, (int) sizeof(bd) );
|
||||
if ( status < 0 ) {
|
||||
socket_close ( sock );
|
||||
epicsSocketDestroy ( sock );
|
||||
return false;
|
||||
}
|
||||
if (reuseAddr) {
|
||||
@@ -139,7 +139,7 @@ static bool makeSocket ( unsigned short port, bool reuseAddr, SOCKET * pSock )
|
||||
status = setsockopt ( sock, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *) &flag, sizeof (flag) );
|
||||
if ( status < 0 ) {
|
||||
socket_close ( sock );
|
||||
epicsSocketDestroy ( sock );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -233,7 +233,7 @@ bool repeaterClient::sendMessage ( const void *pBuf, unsigned bufSize ) // X aCC
|
||||
repeaterClient::~repeaterClient ()
|
||||
{
|
||||
if ( this->sock != INVALID_SOCKET ) {
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
}
|
||||
debugPrintf ( ( "Deleted client %u\n", epicsNTOH16 ( this->from.ia.sin_port ) ) );
|
||||
}
|
||||
@@ -302,7 +302,7 @@ bool repeaterClient::verify () // X aCC 361
|
||||
SOCKET tmpSock;
|
||||
bool success = makeSocket ( this->port (), false, & tmpSock );
|
||||
if ( success ) {
|
||||
socket_close ( tmpSock );
|
||||
epicsSocketDestroy ( tmpSock );
|
||||
}
|
||||
else {
|
||||
if ( SOCKERRNO != SOCK_EADDRINUSE ) {
|
||||
|
||||
@@ -457,7 +457,7 @@ tcpiiu::tcpiiu ( cac & cac, callbackMutex & cbMutex, double connectionTimeout,
|
||||
discardingPendingData ( false ),
|
||||
socketHasBeenClosed ( false )
|
||||
{
|
||||
this->sock = socket ( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
this->sock = epicsSocketCreate ( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
if ( this->sock == INVALID_SOCKET ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
@@ -677,17 +677,8 @@ void tcpiiu::initiateAbortShutdown ( epicsGuard < callbackMutex > &,
|
||||
// some complexity because we must unregister the fd early
|
||||
//
|
||||
if ( ! this->socketHasBeenClosed ) {
|
||||
int status = socket_close ( this->sock );
|
||||
if ( status ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
errlogPrintf ("CAC TCP socket close error was %s\n",
|
||||
sockErrBuf );
|
||||
}
|
||||
else {
|
||||
this->socketHasBeenClosed = true;
|
||||
}
|
||||
epicsSocketDestroy ( this->sock );
|
||||
this->socketHasBeenClosed = true;
|
||||
}
|
||||
break;
|
||||
case esscimqi_socketBothShutdownRequired:
|
||||
@@ -727,14 +718,7 @@ tcpiiu::~tcpiiu ()
|
||||
this->recvThread.exitWait ();
|
||||
|
||||
if ( ! this->socketHasBeenClosed ) {
|
||||
int status = socket_close ( this->sock );
|
||||
if ( status ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
errlogPrintf ("CAC TCP socket close error was %s\n",
|
||||
sockErrBuf );
|
||||
}
|
||||
epicsSocketDestroy ( this->sock );
|
||||
}
|
||||
|
||||
// free message body cache
|
||||
|
||||
@@ -103,7 +103,7 @@ udpiiu::udpiiu ( epicsTimerQueueActive & timerQueue, callbackMutex & cbMutex, ca
|
||||
envGetInetPortConfigParam ( &EPICS_CA_SERVER_PORT,
|
||||
static_cast <unsigned short> (CA_SERVER_PORT) );
|
||||
|
||||
this->sock = socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
this->sock = epicsSocketCreate ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
if ( this->sock == INVALID_SOCKET ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
@@ -154,7 +154,7 @@ udpiiu::udpiiu ( epicsTimerQueueActive & timerQueue, callbackMutex & cbMutex, ca
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
this->printf ( "CAC: unable to bind to an unconstrained address because = \"%s\"\n",
|
||||
sockErrBuf );
|
||||
throwWithLocation ( noSocket () );
|
||||
@@ -168,12 +168,12 @@ udpiiu::udpiiu ( epicsTimerQueueActive & timerQueue, callbackMutex & cbMutex, ca
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
this->printf ( "CAC: getsockname () error was \"%s\"\n", sockErrBuf );
|
||||
throwWithLocation ( noSocket () );
|
||||
}
|
||||
if ( tmpAddr.sa.sa_family != AF_INET) {
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
this->printf ( "CAC: UDP socket was not inet addr family\n" );
|
||||
throwWithLocation ( noSocket () );
|
||||
}
|
||||
@@ -221,7 +221,7 @@ udpiiu::~udpiiu ()
|
||||
free ( pnode );
|
||||
}
|
||||
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
}
|
||||
|
||||
void udpiiu::shutdown ()
|
||||
@@ -483,7 +483,7 @@ void epicsShareAPI caStartRepeaterIfNotInstalled ( unsigned repeaterPort )
|
||||
return;
|
||||
}
|
||||
|
||||
tmpSock = socket ( AF_INET, SOCK_DGRAM, IPPROTO_UDP );
|
||||
tmpSock = epicsSocketCreate ( 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 ) );
|
||||
@@ -512,7 +512,7 @@ void epicsShareAPI caStartRepeaterIfNotInstalled ( unsigned repeaterPort )
|
||||
fprintf ( stderr, "caStartRepeaterIfNotInstalled () : set socket option reuseaddr set failed\n" );
|
||||
}
|
||||
|
||||
socket_close ( tmpSock );
|
||||
epicsSocketDestroy ( tmpSock );
|
||||
|
||||
if ( ! installed ) {
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ casDGIntfIO::casDGIntfIO ( caServerI & serverIn, clientBufMemoryManager & memMgr
|
||||
|
||||
this->beaconSock = casDGIntfIO::makeSockDG();
|
||||
if (this->beaconSock==INVALID_SOCKET) {
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
throw S_cas_internal;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ casDGIntfIO::casDGIntfIO ( caServerI & serverIn, clientBufMemoryManager & memMgr
|
||||
removeDuplicateAddresses ( &BCastAddrList, &tmpList, 1 );
|
||||
if (ellCount(&BCastAddrList)<1) {
|
||||
errMessage (S_cas_noInterface, "- unable to continue");
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
throw S_cas_noInterface;
|
||||
}
|
||||
pAddr = reinterpret_cast < osiSockAddrNode * > ( ellFirst ( &BCastAddrList ) );
|
||||
@@ -129,7 +129,7 @@ casDGIntfIO::casDGIntfIO ( caServerI & serverIn, clientBufMemoryManager & memMgr
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
errPrintf ( S_cas_bindFail, __FILE__, __LINE__,
|
||||
"- bind UDP IP addr=%s failed because %s", buf, sockErrBuf );
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
throw S_cas_bindFail;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ casDGIntfIO::casDGIntfIO ( caServerI & serverIn, clientBufMemoryManager & memMgr
|
||||
|
||||
this->bcastRecvSock = casDGIntfIO::makeSockDG ();
|
||||
if (this->bcastRecvSock==INVALID_SOCKET) {
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
throw S_cas_internal;
|
||||
}
|
||||
|
||||
@@ -221,8 +221,8 @@ casDGIntfIO::casDGIntfIO ( caServerI & serverIn, clientBufMemoryManager & memMgr
|
||||
errPrintf ( S_cas_bindFail, __FILE__, __LINE__,
|
||||
"- bind UDP IP addr=%s failed because %s",
|
||||
buf, sockErrBuf );
|
||||
socket_close ( this->sock );
|
||||
socket_close ( this->bcastRecvSock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
epicsSocketDestroy ( this->bcastRecvSock );
|
||||
throw S_cas_bindFail;
|
||||
}
|
||||
}
|
||||
@@ -240,15 +240,15 @@ casDGIntfIO::casDGIntfIO ( caServerI & serverIn, clientBufMemoryManager & memMgr
|
||||
casDGIntfIO::~casDGIntfIO()
|
||||
{
|
||||
if ( this->sock != INVALID_SOCKET ) {
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
}
|
||||
|
||||
if ( this->bcastRecvSock != INVALID_SOCKET ) {
|
||||
socket_close ( this->bcastRecvSock );
|
||||
epicsSocketDestroy ( this->bcastRecvSock );
|
||||
}
|
||||
|
||||
if ( this->beaconSock != INVALID_SOCKET ) {
|
||||
socket_close ( this->beaconSock );
|
||||
epicsSocketDestroy ( this->beaconSock );
|
||||
}
|
||||
|
||||
// avoid use of ellFree because problems on windows occur if the
|
||||
@@ -515,7 +515,7 @@ SOCKET casDGIntfIO::makeSockDG ()
|
||||
int status;
|
||||
SOCKET newSock;
|
||||
|
||||
newSock = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
newSock = epicsSocketCreate (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (newSock == INVALID_SOCKET) {
|
||||
errMessage(S_cas_noMemory, "CAS: unable to create cast socket\n");
|
||||
return INVALID_SOCKET;
|
||||
@@ -528,7 +528,7 @@ SOCKET casDGIntfIO::makeSockDG ()
|
||||
(char *)&yes,
|
||||
sizeof(yes));
|
||||
if (status<0) {
|
||||
socket_close (newSock);
|
||||
epicsSocketDestroy (newSock);
|
||||
errMessage(S_cas_internal,
|
||||
"CAS: unable to set up cast socket\n");
|
||||
return INVALID_SOCKET;
|
||||
@@ -558,7 +558,7 @@ SOCKET casDGIntfIO::makeSockDG ()
|
||||
(char *)&size,
|
||||
sizeof(size));
|
||||
if (status<0) {
|
||||
socket_close (newSock);
|
||||
epicsSocketDestroy (newSock);
|
||||
errMessage(S_cas_internal,
|
||||
"CAS: unable to set cast socket size\n");
|
||||
return INVALID_SOCKET;
|
||||
@@ -579,7 +579,7 @@ SOCKET casDGIntfIO::makeSockDG ()
|
||||
(char *) &yes,
|
||||
sizeof (yes));
|
||||
if (status<0) {
|
||||
socket_close (newSock);
|
||||
epicsSocketDestroy (newSock);
|
||||
errMessage(S_cas_internal,
|
||||
"CAS: unable to set SO_REUSEADDR on UDP socket?\n");
|
||||
return INVALID_SOCKET;
|
||||
|
||||
@@ -49,7 +49,7 @@ casIntfIO::casIntfIO ( const caNetAddr & addrIn ) :
|
||||
/*
|
||||
* Setup the server socket
|
||||
*/
|
||||
this->sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
this->sock = epicsSocketCreate ( AF_INET, SOCK_STREAM, IPPROTO_TCP );
|
||||
if (this->sock==INVALID_SOCKET) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
@@ -77,7 +77,7 @@ casIntfIO::casIntfIO ( const caNetAddr & addrIn ) :
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
errlogPrintf ( "CAS: server set SO_REUSEADDR failed? %s\n",
|
||||
sockErrBuf );
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
throw S_cas_internal;
|
||||
}
|
||||
# endif
|
||||
@@ -107,7 +107,7 @@ casIntfIO::casIntfIO ( const caNetAddr & addrIn ) :
|
||||
__FILE__, __LINE__,
|
||||
"- bind TCP IP addr=%s failed because %s",
|
||||
buf, sockErrBuf );
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
throw S_cas_bindFail;
|
||||
}
|
||||
portChange = true;
|
||||
@@ -126,7 +126,7 @@ casIntfIO::casIntfIO ( const caNetAddr & addrIn ) :
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
errlogPrintf ( "CAS: getsockname() error %s\n",
|
||||
sockErrBuf );
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
throw S_cas_internal;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ casIntfIO::casIntfIO ( const caNetAddr & addrIn ) :
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
errlogPrintf ( "CAS: listen() error %s\n", sockErrBuf );
|
||||
socket_close (this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
throw S_cas_internal;
|
||||
}
|
||||
}
|
||||
@@ -161,7 +161,7 @@ casIntfIO::casIntfIO ( const caNetAddr & addrIn ) :
|
||||
casIntfIO::~casIntfIO()
|
||||
{
|
||||
if (this->sock != INVALID_SOCKET) {
|
||||
socket_close(this->sock);
|
||||
epicsSocketDestroy (this->sock);
|
||||
}
|
||||
|
||||
osiSockRelease ();
|
||||
@@ -193,7 +193,7 @@ casStreamOS *casIntfIO::newStreamClient ( caServerI & cas,
|
||||
return NULL;
|
||||
}
|
||||
else if ( sizeof ( newAddr ) > (size_t) length ) {
|
||||
socket_close ( newSock );
|
||||
epicsSocketDestroy ( newSock );
|
||||
errlogPrintf ( "CAS: accept returned bad address len?\n" );
|
||||
return NULL;
|
||||
}
|
||||
@@ -205,7 +205,7 @@ casStreamOS *casIntfIO::newStreamClient ( caServerI & cas,
|
||||
if ( ! pOS ) {
|
||||
errMessage ( S_cas_noMemory,
|
||||
"unable to create data structures for a new client" );
|
||||
socket_close ( newSock );
|
||||
epicsSocketDestroy ( newSock );
|
||||
}
|
||||
else {
|
||||
if ( cas.getDebugLevel() > 0u ) {
|
||||
|
||||
@@ -97,7 +97,7 @@ casStreamIO::casStreamIO ( caServerI & cas, clientBufMemoryManager & bufMgr,
|
||||
casStreamIO::~casStreamIO()
|
||||
{
|
||||
if ( ! this->sockHasBeenClosed ) {
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ void casStreamIO::forceDisconnect ()
|
||||
errlogPrintf ("CAC TCP socket shutdown error was %s\n",
|
||||
sockErrBuf );
|
||||
}
|
||||
socket_close ( this->sock );
|
||||
epicsSocketDestroy ( this->sock );
|
||||
// other wakeup will be required here when we
|
||||
// switch to a threaded implementation
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ LOCAL void logClientReset (logClient *pClient)
|
||||
# ifdef vxWorks
|
||||
logFdDelete ( pClient->sock );
|
||||
# endif
|
||||
socket_close ( pClient->sock );
|
||||
epicsSocketDestroy ( pClient->sock );
|
||||
pClient->sock = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ LOCAL void logClientMakeSock (logClient *pClient)
|
||||
/*
|
||||
* allocate a socket
|
||||
*/
|
||||
pClient->sock = socket ( AF_INET, SOCK_STREAM, 0 );
|
||||
pClient->sock = epicsSocketCreate ( AF_INET, SOCK_STREAM, 0 );
|
||||
if ( pClient->sock == INVALID_SOCKET ) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString (
|
||||
@@ -387,9 +387,9 @@ LOCAL void logClientMakeSock (logClient *pClient)
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
fprintf (stderr, "%s:%d ioctl FBIO client er %s\n",
|
||||
__FILE__, __LINE__, sockErrBuf);
|
||||
socket_close (pClient->sock);
|
||||
epicsSocketDestroy ( pClient->sock );
|
||||
pClient->sock = INVALID_SOCKET;
|
||||
epicsMutexUnlock (pClient->mutex);
|
||||
epicsMutexUnlock ( pClient->mutex );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
typedef int osiSocklen_t;
|
||||
|
||||
@@ -54,7 +54,6 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
typedef socklen_t osiSocklen_t;
|
||||
|
||||
@@ -40,7 +40,6 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
|
||||
#ifdef LYNXOS_RELEASE_2_4_0 /* only for LynxOS v2.4.0 */
|
||||
# define socket_ioctl(A,B,C) ioctl(A,B,(char *)C)
|
||||
|
||||
@@ -41,7 +41,6 @@ int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, str
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
typedef int osiSocklen_t;
|
||||
|
||||
@@ -116,6 +116,24 @@ epicsShareFunc void epicsShareAPI osiSockRelease()
|
||||
}
|
||||
}
|
||||
|
||||
epicsShareFunc SOCKET epicsShareAPI epicsSocketCreate (
|
||||
int domain, int type, int protocol )
|
||||
{
|
||||
return socket ( domain, type, protocol );
|
||||
}
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsSocketDestroy ( SOCKET s )
|
||||
{
|
||||
int status = closesocket ( s );
|
||||
if ( status < 0 ) {
|
||||
char buf [ 64 ];
|
||||
epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
|
||||
errlogPrintf (
|
||||
"epicsSocketDestroy: failed to "
|
||||
"close a socket because \"%s\"\n", buf );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ipAddrToHostName
|
||||
*/
|
||||
|
||||
@@ -31,7 +31,6 @@ extern "C" {
|
||||
|
||||
#define SOCKERRNO WSAGetLastError()
|
||||
|
||||
#define socket_close(S) closesocket(S)
|
||||
#define socket_ioctl(A,B,C) ioctlsocket(A,B,C)
|
||||
typedef u_long FAR osiSockIoctl_t;
|
||||
typedef int osiSocklen_t;
|
||||
|
||||
@@ -43,7 +43,6 @@ struct ifafilt;
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
typedef int osiSocklen_t;
|
||||
|
||||
@@ -38,7 +38,6 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
typedef int osiSocklen_t;
|
||||
|
||||
@@ -41,7 +41,6 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
typedef int osiSocklen_t;
|
||||
|
||||
@@ -64,6 +64,42 @@ void osiSockRelease()
|
||||
{
|
||||
}
|
||||
|
||||
epicsShareFunc SOCKET epicsShareAPI epicsSocketCreate (
|
||||
int domain, int type, int protocol )
|
||||
{
|
||||
SOCKET sock = socket ( domain, type, protocol );
|
||||
if ( sock < 0 ) {
|
||||
sock = INVALID_SOCKET;
|
||||
}
|
||||
else {
|
||||
int status = fcntl ( sock, F_SETFD, FD_CLOEXEC );
|
||||
if ( status < 0 ) {
|
||||
char buf [ 64 ];
|
||||
epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
|
||||
errlogPrintf (
|
||||
"epicsSocketCreate: failed to "
|
||||
"fcntl FD_CLOEXEC because \"%s\"\n",
|
||||
buf ):
|
||||
close ( sock );
|
||||
sock = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
return sock;
|
||||
}
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsSocketDestroy ( SOCKET s )
|
||||
{
|
||||
int status = close ( s );
|
||||
if ( status < 0 ) {
|
||||
char buf [ 64 ];
|
||||
epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
|
||||
errlogPrintf (
|
||||
"epicsSocketDestroy: failed to "
|
||||
"close a socket because \"%s\"\n",
|
||||
buf );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ipAddrToHostName
|
||||
* On many systems, gethostbyaddr must be protected by a
|
||||
@@ -42,7 +42,6 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
typedef int osiSocklen_t;
|
||||
|
||||
@@ -42,7 +42,6 @@ extern "C" {
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
|
||||
|
||||
@@ -111,7 +111,6 @@ int gethostname (char *name, int namelen);
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#define socket_ioctl(A,B,C) ioctl(A,B,C)
|
||||
typedef int osiSockIoctl_t;
|
||||
typedef int osiSocklen_t;
|
||||
|
||||
@@ -30,6 +30,29 @@ void osiSockRelease()
|
||||
{
|
||||
}
|
||||
|
||||
epicsShareFunc SOCKET epicsShareAPI epicsSocketCreate (
|
||||
int domain, int type, int protocol )
|
||||
{
|
||||
SOCKET sock = socket ( domain, type, protocol );
|
||||
if ( sock < 0 ) {
|
||||
sock = INVALID_SOCKET;
|
||||
}
|
||||
return sock;
|
||||
}
|
||||
|
||||
epicsShareFunc void epicsShareAPI epicsSocketDestroy ( SOCKET s )
|
||||
{
|
||||
int status = close ( s );
|
||||
if ( status < 0 ) {
|
||||
char buf [ 64 ];
|
||||
epicsSocketConvertErrnoToString ( buf, sizeof ( buf ) );
|
||||
errlogPrintf (
|
||||
"epicsSocketDestroy: failed to "
|
||||
"close a socket because \"%s\"\n",
|
||||
buf );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ipAddrToHostName
|
||||
*/
|
||||
|
||||
@@ -43,7 +43,6 @@ int sysClkRateGet(void);
|
||||
typedef int SOCKET;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKERRNO errno
|
||||
#define socket_close(S) close(S)
|
||||
#ifndef SHUT_RD
|
||||
# define SHUT_RD 0
|
||||
#endif
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define osiSockh
|
||||
|
||||
#include "shareLib.h"
|
||||
#include "osdSock.h"
|
||||
#include "ellLib.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -29,6 +30,25 @@ struct sockaddr;
|
||||
struct sockaddr_in;
|
||||
struct in_addr;
|
||||
|
||||
epicsShareFunc SOCKET epicsShareAPI epicsSocketCreate ( int domain, int type, int protocol );
|
||||
epicsShareFunc void epicsShareAPI epicsSocketDestroy ( SOCKET );
|
||||
|
||||
/*
|
||||
* Fortunately, on most systems the combination of a shutdown of both
|
||||
* directions and or a signal is sufficent to interrupt a blocking send,
|
||||
* receive, or connect call. For odd ball systems this is stubbed out in the
|
||||
* osi area.
|
||||
*/
|
||||
enum epicsSocketSystemCallInterruptMechanismQueryInfo {
|
||||
esscimqi_socketCloseRequired,
|
||||
esscimqi_socketBothShutdownRequired,
|
||||
esscimqi_socketSigAlarmRequired,
|
||||
esscimqi_shuechanismImplemenedHerein
|
||||
};
|
||||
epicsShareFunc enum epicsSocketSystemCallInterruptMechanismQueryInfo
|
||||
epicsSocketSystemCallInterruptMechanismQuery ();
|
||||
|
||||
|
||||
/*
|
||||
* convert socket address to ASCII in this order
|
||||
* 1) look for matching host name and typically add trailing IP port
|
||||
@@ -101,16 +121,6 @@ epicsShareFunc void epicsShareAPI osiSockRelease (void);
|
||||
epicsShareFunc void epicsSocketConvertErrnoToString (
|
||||
char * pBuf, unsigned bufSize );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "osdSock.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef union osiSockAddr {
|
||||
struct sockaddr_in ia;
|
||||
struct sockaddr sa;
|
||||
@@ -167,21 +177,6 @@ epicsShareFunc void epicsShareAPI osiSockDiscoverBroadcastAddresses
|
||||
*/
|
||||
epicsShareFunc osiSockAddr epicsShareAPI osiLocalAddr (SOCKET socket);
|
||||
|
||||
/*
|
||||
* Fortunately, on most systems the combination of a shutdown of both
|
||||
* directions and or a signal is sufficent to interrupt a blocking send,
|
||||
* receive, or connect call. For odd ball systems this is stubbed out in the
|
||||
* osi area.
|
||||
*/
|
||||
enum epicsSocketSystemCallInterruptMechanismQueryInfo {
|
||||
esscimqi_socketCloseRequired,
|
||||
esscimqi_socketBothShutdownRequired,
|
||||
esscimqi_socketSigAlarmRequired,
|
||||
esscimqi_shuechanismImplemenedHerein
|
||||
};
|
||||
epicsShareFunc enum epicsSocketSystemCallInterruptMechanismQueryInfo
|
||||
epicsSocketSystemCallInterruptMechanismQuery ();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -81,15 +81,15 @@ LOCAL void req_server (void *pParm)
|
||||
(unsigned short) CA_SERVER_PORT );
|
||||
}
|
||||
|
||||
if (IOC_sock != 0 && IOC_sock != INVALID_SOCKET)
|
||||
if ((status = socket_close(IOC_sock)) < 0)
|
||||
errlogPrintf( "CAS: Unable to close open master socket\n");
|
||||
|
||||
if (IOC_sock != 0 && IOC_sock != INVALID_SOCKET) {
|
||||
epicsSocketDestroy ( IOC_sock );
|
||||
}
|
||||
|
||||
/*
|
||||
* Open the socket. Use ARPA Internet address format and stream
|
||||
* sockets. Format described in <sys/socket.h>.
|
||||
*/
|
||||
if ( ( IOC_sock = socket(AF_INET, SOCK_STREAM, 0) ) == INVALID_SOCKET ) {
|
||||
if ( ( IOC_sock = epicsSocketCreate (AF_INET, SOCK_STREAM, 0) ) == INVALID_SOCKET ) {
|
||||
errlogPrintf ("CAS: Socket creation error\n");
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
@@ -176,7 +176,7 @@ LOCAL void req_server (void *pParm)
|
||||
/* listen and accept new connections */
|
||||
if ( listen ( IOC_sock, 20 ) < 0 ) {
|
||||
errlogPrintf ("CAS: Listen error\n");
|
||||
socket_close (IOC_sock);
|
||||
epicsSocketDestroy (IOC_sock);
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
@@ -499,9 +499,7 @@ void destroy_client ( struct client *client )
|
||||
|
||||
|
||||
if ( client->sock != INVALID_SOCKET ) {
|
||||
if ( socket_close (client->sock) < 0) {
|
||||
errlogPrintf( "CAS: Unable to close socket\n" );
|
||||
}
|
||||
epicsSocketDestroy ( client->sock );
|
||||
}
|
||||
|
||||
if ( client->proto == IPPROTO_TCP ) {
|
||||
|
||||
@@ -132,9 +132,7 @@ void cast_server(void *pParm)
|
||||
recv_addr_size = sizeof(new_recv_addr);
|
||||
|
||||
if( IOC_cast_sock!=0 && IOC_cast_sock!=INVALID_SOCKET ) {
|
||||
if( (status = socket_close(IOC_cast_sock)) < 0 ) {
|
||||
epicsPrintf ("CAS: Unable to close master cast socket\n");
|
||||
}
|
||||
epicsSocketDestroy ( IOC_cast_sock );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -142,7 +140,7 @@ void cast_server(void *pParm)
|
||||
* Use ARPA Internet address format and datagram socket.
|
||||
*/
|
||||
|
||||
if ( ( IOC_cast_sock = socket (AF_INET, SOCK_DGRAM, 0) ) == INVALID_SOCKET ) {
|
||||
if ( ( IOC_cast_sock = epicsSocketCreate (AF_INET, SOCK_DGRAM, 0) ) == INVALID_SOCKET ) {
|
||||
epicsPrintf ("CAS: cast socket creation error\n");
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
@@ -198,7 +196,7 @@ void cast_server(void *pParm)
|
||||
epicsSocketConvertErrnoToString (
|
||||
sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
epicsPrintf ("CAS: UDP server port bind error was \"%s\"\n", sockErrBuf );
|
||||
socket_close (IOC_cast_sock);
|
||||
epicsSocketDestroy ( IOC_cast_sock );
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ void rsrv_online_notify_task(void *pParm)
|
||||
* Use ARPA Internet address format and datagram socket.
|
||||
* Format described in <sys/socket.h>.
|
||||
*/
|
||||
if ( (sock = socket (AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) {
|
||||
if ( (sock = epicsSocketCreate (AF_INET, SOCK_DGRAM, 0)) == INVALID_SOCKET) {
|
||||
errlogPrintf ("CAS: online socket creation error\n");
|
||||
epicsThreadSuspendSelf ();
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ int main()
|
||||
* Open the socket. Use ARPA Internet address format and stream
|
||||
* sockets. Format described in <sys/socket.h>.
|
||||
*/
|
||||
pserver->sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
pserver->sock = epicsSocketCreate(AF_INET, SOCK_STREAM, 0);
|
||||
if (pserver->sock==INVALID_SOCKET) {
|
||||
char sockErrBuf[64];
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
@@ -477,7 +477,7 @@ static void acceptNewClient ( void *pParam )
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
fprintf(stderr, "%s:%d ioctl FBIO client er %s\n",
|
||||
__FILE__, __LINE__, sockErrBuf);
|
||||
socket_close(pclient->insock);
|
||||
epicsSocketDestroy ( pclient->insock );
|
||||
free(pclient);
|
||||
return;
|
||||
}
|
||||
@@ -525,7 +525,7 @@ static void acceptNewClient ( void *pParam )
|
||||
epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
|
||||
fprintf (stderr, "%s:%d shutdown err %s\n", __FILE__, __LINE__,
|
||||
sockErrBuf);
|
||||
socket_close(pclient->insock);
|
||||
epicsSocketDestroy ( pclient->insock );
|
||||
free(pclient);
|
||||
|
||||
return;
|
||||
@@ -538,7 +538,7 @@ static void acceptNewClient ( void *pParam )
|
||||
readFromClient,
|
||||
pclient);
|
||||
if (status<0) {
|
||||
socket_close(pclient->insock);
|
||||
epicsSocketDestroy ( pclient->insock );
|
||||
free(pclient);
|
||||
fprintf(stderr, "%s:%d client fdmgr_add_callback() failed\n",
|
||||
__FILE__, __LINE__);
|
||||
@@ -740,8 +740,7 @@ static void freeLogClient(struct iocLogClient *pclient)
|
||||
__FILE__, __LINE__);
|
||||
}
|
||||
|
||||
if(socket_close(pclient->insock)<0)
|
||||
abort();
|
||||
epicsSocketDestroy ( pclient->insock );
|
||||
|
||||
free (pclient);
|
||||
|
||||
|
||||
@@ -1090,7 +1090,7 @@ int TSgetBroadcastSocket(int port, struct sockaddr_in* sin)
|
||||
sin->sin_port=htons(port);
|
||||
sin->sin_family=AF_INET;
|
||||
sin->sin_addr.s_addr=htonl(INADDR_ANY);
|
||||
if( (soc=socket(AF_INET,SOCK_DGRAM,0)) < 0 )
|
||||
if( (soc=epicsSocketCreate(AF_INET,SOCK_DGRAM,0)) < 0 )
|
||||
{ perror("socket create failed"); return -1; }
|
||||
|
||||
setsockopt(soc,SOL_SOCKET,SO_BROADCAST,(char*)&on,sizeof(on));
|
||||
@@ -1688,7 +1688,7 @@ static int TSgetSocket(int port, struct sockaddr_in* sin)
|
||||
sin->sin_port=htons(port);
|
||||
sin->sin_family=AF_INET;
|
||||
sin->sin_addr.s_addr=htonl(INADDR_ANY);
|
||||
if( (soc=socket(AF_INET,SOCK_DGRAM,0)) < 0 )
|
||||
if( (soc=epicsSocketCreate(AF_INET,SOCK_DGRAM,0)) < 0 )
|
||||
{ perror("socket create failed"); return -1; }
|
||||
Debug(5,"sizeof sin = %d\n", (int) sizeof(struct sockaddr_in));
|
||||
if( bind(soc,(struct sockaddr*)sin,sizeof(struct sockaddr_in)) < 0 )
|
||||
|
||||
Reference in New Issue
Block a user