improved the way that socket error numbers are converted to strings
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
#define instantiateRecourceLib
|
||||
#define epicsExportSharedSymbols
|
||||
#include <epicsAssert.h>
|
||||
#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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
#define instantiateRecourceLib
|
||||
#define epicsExportSharedSymbols
|
||||
#include <epicsAssert.h>
|
||||
#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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -40,10 +40,20 @@
|
||||
#error This source is specific to WIN32
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ANSI C
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
#include "epicsVersion.h"
|
||||
/*
|
||||
* WIN32 specific
|
||||
*/
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <process.h>
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
|
||||
/*
|
||||
* Author: Jeff Hill
|
||||
*/
|
||||
|
||||
/*
|
||||
* ANSI C
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* WIN32 specific
|
||||
*/
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <process.h>
|
||||
|
||||
/*
|
||||
* 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
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user