fixed base to use close on exec options whenever creating a socket

on posix compliant systems
This commit is contained in:
Jeff Hill
2003-07-16 17:45:09 +00:00
parent a907bc4df3
commit b697fc2acc
30 changed files with 170 additions and 131 deletions
+4 -4
View File
@@ -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;
}
-1
View File
@@ -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;
-1
View File
@@ -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;
-1
View File
@@ -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)
-1
View File
@@ -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;
+18
View File
@@ -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
*/
-1
View File
@@ -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;
-1
View File
@@ -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;
-1
View File
@@ -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;
-1
View File
@@ -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
-1
View File
@@ -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;
-1
View File
@@ -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;
-1
View File
@@ -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;
+23
View File
@@ -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
*/
-1
View File
@@ -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
+20 -25
View File
@@ -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