diff --git a/src/libCom/Makefile.Host b/src/libCom/Makefile.Host index 7e8fb48f6..addea3dac 100644 --- a/src/libCom/Makefile.Host +++ b/src/libCom/Makefile.Host @@ -92,7 +92,7 @@ LIBSRCS += $(patsubst %,fdManager.cc,$(strip $(CPLUSPLUS))) # WIN32 has no getopt, we add it to the Com lib, # special initialisation is done in winmain.c -LIBSRCS_WIN32 := getopt.c getLastWSAErrorAsString.c +LIBSRCS_WIN32 := getopt.c LIBSRCS_WIN32 += $(patsubst %,dllmain.cc,$(strip $(CPLUSPLUS))) # Library to build: diff --git a/src/libCom/bsdSocketResource.h b/src/libCom/bsdSocketResource.h index f9ab30193..bd4016049 100644 --- a/src/libCom/bsdSocketResource.h +++ b/src/libCom/bsdSocketResource.h @@ -92,8 +92,12 @@ epicsShareFunc int epicsShareAPI bsdSockAttach(); /* returns T if success, else */ epicsShareFunc void epicsShareAPI bsdSockRelease(); +/* + * convert socket error number to a string + */ +epicsShareFunc const char * epicsShareAPI convertSocketErrorToString (int errnoIn); + #ifdef _WIN32 -epicsShareFunc const char * epicsShareAPI getLastWSAErrorAsString(); epicsShareFunc unsigned epicsShareAPI wsaMajorVersion(); #endif diff --git a/src/libCom/fdManager.cc b/src/libCom/fdManager.cc index de8a257cc..2dad2a6f6 100644 --- a/src/libCom/fdManager.cc +++ b/src/libCom/fdManager.cc @@ -47,7 +47,7 @@ #define instantiateRecourceLib #define epicsExportSharedSymbols -#include +#include "epicsAssert.h" #include "osiTimer.h" #include "osiSleep.h" #include "tsMinMax.h" @@ -193,10 +193,11 @@ epicsShareFunc void fdManager::process (double delay) return; } else if (status<0) { - if (SOCKERRNO != SOCK_EINTR) { + int errnoCpy = SOCKERRNO; + if (errnoCpy != SOCK_EINTR) { fprintf(stderr, - "fdManager: select failed because errno=%d=\"%s\"\n", - SOCKERRNO, SOCKERRSTR); + "fdManager: select failed because \"%s\"\n", + SOCKERRSTR(errnoCpy)); } this->processInProg = 0; return; diff --git a/src/libCom/fdmgr.c b/src/libCom/fdmgr.c index 8f38c009f..6eae448f4 100644 --- a/src/libCom/fdmgr.c +++ b/src/libCom/fdmgr.c @@ -71,6 +71,9 @@ * we eliminate delete ambiguity (chance of the same * being reused). * $Log$ + * Revision 1.30 1998/06/16 02:03:22 jhill + * recover from winsock select differences + * * Revision 1.29 1998/02/27 01:34:12 jhill * cleaned up the DLL symbol export * @@ -890,18 +893,21 @@ struct timeval *ptimeout return labor_performed; } else if(status < 0){ - if(SOCKERRNO == SOCK_EINTR) - ; - else if(SOCKERRNO == SOCK_EINVAL) - fdmgrPrintf( - "fdmgr: bad select args ? %d %d %d\n", - pfdctx->maxfd, - ptimeout->tv_sec, - ptimeout->tv_usec); - else - fdmgrPrintf( - "fdmgr: error from select %d=%s\n", - SOCKERRNO, SOCKERRSTR); + int errnoCpy = SOCKERRNO; + if (errnoCpy != SOCK_EINTR) { + if(errnoCpy == SOCK_EINVAL) { + fdmgrPrintf( + "fdmgr: bad select args ? %d %d %d\n", + pfdctx->maxfd, + ptimeout->tv_sec, + ptimeout->tv_usec); + } + else { + fdmgrPrintf( + "fdmgr: error from select %s\n", + SOCKERRSTR(errnoCpy)); + } + } return labor_performed; } diff --git a/src/libCom/fdmgr/fdManager.cpp b/src/libCom/fdmgr/fdManager.cpp index de8a257cc..2dad2a6f6 100644 --- a/src/libCom/fdmgr/fdManager.cpp +++ b/src/libCom/fdmgr/fdManager.cpp @@ -47,7 +47,7 @@ #define instantiateRecourceLib #define epicsExportSharedSymbols -#include +#include "epicsAssert.h" #include "osiTimer.h" #include "osiSleep.h" #include "tsMinMax.h" @@ -193,10 +193,11 @@ epicsShareFunc void fdManager::process (double delay) return; } else if (status<0) { - if (SOCKERRNO != SOCK_EINTR) { + int errnoCpy = SOCKERRNO; + if (errnoCpy != SOCK_EINTR) { fprintf(stderr, - "fdManager: select failed because errno=%d=\"%s\"\n", - SOCKERRNO, SOCKERRSTR); + "fdManager: select failed because \"%s\"\n", + SOCKERRSTR(errnoCpy)); } this->processInProg = 0; return; diff --git a/src/libCom/os/VMS/osiSleep.c b/src/libCom/os/VMS/osiSleep.c index 22e76f095..5a40c01fc 100644 --- a/src/libCom/os/VMS/osiSleep.c +++ b/src/libCom/os/VMS/osiSleep.c @@ -22,6 +22,6 @@ epicsShareFunc void epicsShareAPI osiSleep (unsigned sec, unsigned uSec) status = select (0, NULL, NULL, NULL, &tval); if (status<0) { fprintf (stderr, "error from select in osiDelayMicroSec() was %s\n", - SOCKERRSTR); + SOCKERRSTR(SOCKERRNO)); } } \ No newline at end of file diff --git a/src/libCom/os/WIN32/bsdSockResource.c b/src/libCom/os/WIN32/bsdSockResource.c index 6704ccfee..d1472f0c3 100644 --- a/src/libCom/os/WIN32/bsdSockResource.c +++ b/src/libCom/os/WIN32/bsdSockResource.c @@ -40,10 +40,20 @@ #error This source is specific to WIN32 #endif +/* + * ANSI C + */ #include -#include "epicsVersion.h" +/* + * WIN32 specific + */ +#include +#include +#include + #define epicsExportSharedSymbols +#include "epicsVersion.h" #include "bsdSocketResource.h" static unsigned nAttached = 0; @@ -173,3 +183,38 @@ epicsShareFunc int epicsShareAPI hostToIPAddr return -1; } +/* + * convertSocketErrorToString() + */ +epicsShareFunc const char * epicsShareAPI convertSocketErrorToString (int errnoIn) +{ + static char errString[128]; + static int init = 0; + + /* + * unfortunately, this does not work ... + * and there is no obvious replacement ... + */ +#if 0 + DWORD W32status; + + W32status = FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + errnoIn, + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ + errString, + sizeof(errString)/sizeof(errString[0]), + NULL + ); + + if (W32status==0) { + sprintf (errString, "WIN32 Socket Library Error %d", errnoIn); + } + return errString; +#else + sprintf (errString, "WIN32 Socket Library Error %d", errnoIn); + return errString; +#endif +} + diff --git a/src/libCom/os/WIN32/getLastWSAErrorAsString.c b/src/libCom/os/WIN32/getLastWSAErrorAsString.c deleted file mode 100644 index 4f493d58c..000000000 --- a/src/libCom/os/WIN32/getLastWSAErrorAsString.c +++ /dev/null @@ -1,60 +0,0 @@ - -/* - * Author: Jeff Hill - */ - -/* - * ANSI C - */ -#include - -/* - * WIN32 specific - */ -#include -#include -#include - -/* - * this does specify that winsock should be exported, - * but instead that EPICS winsock specific functions - * should be exported. - */ -#define epicsExportSharedSymbols -#include "bsdSocketResource.h" - -/* - * getLastWSAErrorAsString() - */ -epicsShareFunc const char * epicsShareAPI getLastWSAErrorAsString() -{ - static char errString[128]; - static int init = 0; - - - /* - * unfortunately, this does not work ... - * and there is no obvious replacement ... - */ -#if 0 - DWORD W32status; - - W32status = FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - WSAGetLastError (), - MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ - errString, - sizeof(errString)/sizeof(errString[0]), - NULL - ); - - if (W32status==0) { - sprintf (errString, "WIN32 Socket Library Error %d", WSAGetLastError ()); - } - return errString; -#else - sprintf (errString, "WIN32 Socket Library Error %d", WSAGetLastError ()); - return errString; -#endif -} \ No newline at end of file diff --git a/src/libCom/os/generic/osiSleep.c b/src/libCom/os/generic/osiSleep.c index 01cfd5d1c..79e6e5535 100644 --- a/src/libCom/os/generic/osiSleep.c +++ b/src/libCom/os/generic/osiSleep.c @@ -21,6 +21,6 @@ epicsShareFunc void epicsShareAPI osiSleep (unsigned sec, unsigned uSec) status = select (0, NULL, NULL, NULL, &tval); if (status<0) { fprintf (stderr, "error from select in osiDelayMicroSec() was %s\n", - SOCKERRSTR); + SOCKERRSTR(SOCKERRNO)); } } \ No newline at end of file diff --git a/src/util/iocLogServer.c b/src/util/iocLogServer.c index 6301c7b49..84d3e39e6 100644 --- a/src/util/iocLogServer.c +++ b/src/util/iocLogServer.c @@ -47,6 +47,9 @@ * .09 050494 pg HPUX port changes. * .10 021694 joh ANSI C * $Log$ + * Revision 1.32 1999/08/31 15:51:00 jhill + * move to proper date in file if open old log + * * Revision 1.31 1999/08/11 00:24:11 jhill * dont increment file pos on error * @@ -219,7 +222,7 @@ int main() */ pserver->sock = socket(AF_INET, SOCK_STREAM, 0); if (pserver->sock==INVALID_SOCKET) { - fprintf(stderr, "iocLogServer: %d=%s\n", SOCKERRNO, SOCKERRSTR); + fprintf(stderr, "iocLogServer: sock create err: %s\n", SOCKERRSTR(SOCKERRNO)); return IOCLS_ERROR; } @@ -230,7 +233,7 @@ int main() (char *) &optval, sizeof(optval)); if(status<0){ - fprintf(stderr, "iocLogServer: %d=%s\n", SOCKERRNO, SOCKERRSTR); + fprintf(stderr, "iocLogServer: setsockopt err %s\n", SOCKERRSTR(SOCKERRNO)); return IOCLS_ERROR; } @@ -244,17 +247,17 @@ int main() (struct sockaddr *)&serverAddr, sizeof (serverAddr) ); if (status<0) { - fprintf(stderr, + fprintf(stderr, "iocLogServer: bind err: %s\n", SOCKERRSTR(SOCKERRNO) ); + fprintf (stderr, "iocLogServer: a server is already installed on port %u?\n", (unsigned)ioc_log_port); - fprintf(stderr, "iocLogServer: %d=%s\n", SOCKERRNO, SOCKERRSTR); return IOCLS_ERROR; } /* listen and accept new connections */ status = listen(pserver->sock, 10); if (status<0) { - fprintf(stderr, "iocLogServer: %d=%s\n", SOCKERRNO, SOCKERRSTR); + fprintf(stderr, "iocLogServer: listen err %s\n", SOCKERRSTR(SOCKERRNO)); return IOCLS_ERROR; } @@ -268,7 +271,7 @@ int main() FIONBIO, &optval); if(status<0){ - fprintf(stderr, "iocLogServer: %d=%s\n", SOCKERRNO, SOCKERRSTR); + fprintf(stderr, "iocLogServer: ioctl FIONBIO err %s\n", SOCKERRSTR(SOCKERRNO)); return IOCLS_ERROR; } @@ -532,10 +535,10 @@ static void acceptNewClient(void *pParam) FIONBIO, &optval); if(status<0){ + fprintf(stderr, "%s:%d ioctl FBIO client er %s\n", + __FILE__, __LINE__, SOCKERRSTR(SOCKERRNO)); socket_close(pclient->insock); free(pclient); - fprintf(stderr, "%s:%d %s\n", - __FILE__, __LINE__, SOCKERRSTR); return; } @@ -578,10 +581,11 @@ static void acceptNewClient(void *pParam) # define SOCKET_SHUTDOWN_WRITE_SIDE 1 status = shutdown(pclient->insock, SOCKET_SHUTDOWN_WRITE_SIDE); if(status<0){ - socket_close(pclient->insock); + fprintf (stderr, "%s:%d shutdown err %s\n", __FILE__, __LINE__, + SOCKERRSTR(SOCKERRNO)); + socket_close(pclient->insock); free(pclient); - printf("%s:%d %s\n", __FILE__, __LINE__, - SOCKERRSTR); + return; } @@ -623,18 +627,19 @@ static void readFromClient(void *pParam) 0); if (recvLength <= 0) { if (recvLength<0) { - if (SOCKERRNO==SOCK_EWOULDBLOCK || SOCKERRNO==SOCK_EINTR) { + int errnoCpy = SOCKERRNO; + if (errnoCpy==SOCK_EWOULDBLOCK || errnoCpy==SOCK_EINTR) { return; } - if ( SOCKERRNO != SOCK_ECONNRESET && - SOCKERRNO != SOCK_ECONNABORTED && - SOCKERRNO != SOCK_EPIPE && - SOCKERRNO != SOCK_ETIMEDOUT + if (errnoCpy != SOCK_ECONNRESET && + errnoCpy != SOCK_ECONNABORTED && + errnoCpy != SOCK_EPIPE && + errnoCpy != SOCK_ETIMEDOUT ) { fprintf(stderr, - "%s:%d socket=%d size=%d read error=%s errno=%d\n", + "%s:%d socket=%d size=%d read error=%s\n", __FILE__, __LINE__, pclient->insock, - size, SOCKERRSTR, SOCKERRNO); + size, SOCKERRSTR(errnoCpy)); } } /*