EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: CA server bind failure on Windows
From: <[email protected]>
To: <[email protected]>
Date: Thu, 12 Jan 2017 18:04:36 +0000
Hi,

I've had instances of both an IOC and a CAS being unable to create a channel access port. The servers attempt to bind to the usual channel access server port number, but rather than EADDRINUSE being returned on failure they are seeing EACCES. Looking at https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx suggests another application/service might have bound to the port already with SO_EXCLUSIVEADDRUSE and this appears to be the situation (the National Instruments network variables server process in this case). If I change things to request a dynamic port allocation after any bind() failure (rather than only on EADDRINUSE) as per the attached patch then everything works fine

Regards,

Freddie

diff --git a/src/cas/io/bsdSocket/casIntfIO.cc b/src/cas/io/bsdSocket/casIntfIO.cc
index 16cd908..7580173 100644
--- a/src/cas/io/bsdSocket/casIntfIO.cc
+++ b/src/cas/io/bsdSocket/casIntfIO.cc
@@ -61,18 +61,16 @@ casIntfIO::casIntfIO ( const caNetAddr & addrIn ) :
                       reinterpret_cast <sockaddr *> (&this->addr),
                       sizeof(this->addr) );
 	if (status<0) {
-		if (SOCKERRNO == SOCK_EADDRINUSE) {
 			//
 			// enable assignment of a default port
 			// (so the getsockname() call below will
 			// work correctly)
 			//
-			this->addr.sin_port = ntohs (0);
+			this->addr.sin_port = htons (0);
 			status = bind(
                     this->sock,
                     reinterpret_cast <sockaddr *> (&this->addr),
                     sizeof(this->addr) );
-		}
 		if (status<0) {
             char sockErrBuf[64];
             epicsSocketConvertErrnoToString ( sockErrBuf, sizeof ( sockErrBuf ) );
diff --git a/src/rsrv/caservertask.c b/src/rsrv/caservertask.c
index 51b7e99..b4cbe1b 100644
--- a/src/rsrv/caservertask.c
+++ b/src/rsrv/caservertask.c
@@ -106,16 +106,14 @@ static void req_server (void *pParm)
     /* get server's Internet address */
     status = bind ( IOC_sock, (struct sockaddr *) &serverAddr, sizeof ( serverAddr ) );
 	if ( status < 0 ) {
-		if ( SOCKERRNO == SOCK_EADDRINUSE ) {
 			/*
 			 * enable assignment of a default port
 			 * (so the getsockname() call below will
 			 * work correctly)
 			 */
-			serverAddr.sin_port = ntohs (0);
+			serverAddr.sin_port = htons (0);
 			status = bind ( IOC_sock, 
                 (struct sockaddr *) &serverAddr, sizeof ( serverAddr ) );
-		}
 		if ( status < 0 ) {
             char sockErrBuf[64];
             epicsSocketConvertErrnoToString ( 

Replies:
Re: CA server bind failure on Windows Ben Franksen
Re: CA server bind failure on Windows Andrew Johnson

Navigate by Date:
Prev: RE: Problems with vxWorks IOCs on base 3.14.12.6 Mark Rivers
Next: Problems with seq 2.2.4 on Windows Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Support for Queensgate NPC-D-5110DS piezo controller edmund.warrick
Next: Re: CA server bind failure on Windows Ben Franksen
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  2014  2015  2016  <20172018  2019  2020  2021  2022  2023  2024 
ANJ, 21 Dec 2017 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·