axis-c-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pim Philipse (JIRA)" <j...@apache.org>
Subject [jira] Commented: (AXIS2C-1109) axutil_network_handler_open_socket incorrectly assumes that all legal descriptors are >=0
Date Thu, 17 Apr 2008 07:35:21 GMT

    [ https://issues.apache.org/jira/browse/AXIS2C-1109?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12589854#action_12589854
] 

Pim Philipse commented on AXIS2C-1109:
--------------------------------------

Dinesh,

I don't have a complete solution. There are other winsock functions that return socket values,
and I see now that the windows SOCKET is an unsigned type, since

PlatformSDK\Include\WinSock.h:typedef UINT_PTR        SOCKET;

and

PlatformSDK\Include\BaseTsd.h:    typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;

so the issue is really that checking if a SOCKET is <0 is nonsensical under windows.

The functions that return a SOCKET appear to be socket() and accept(), so the return from
these calls should be tested differently on the windows platform. Something like

#if defined(WIN32)
#define IS_SOCKET_INVALID(s) ((s)==INVALID_SOCKET)
#else
#define IS_SOCKET_INVALID(s) ((s)<0)
#endif
...
  if (IS_SOCKET_INVALID(sock = socket(AF_INET, SOCK_STREAM, 0)) ) 
...
    if (IS_SOCKET_INVALID(sock))
...
    if (IS_SOCKET_INVALID(cli_socket))

Sorry, I have no idea how to create a patch.





> axutil_network_handler_open_socket incorrectly assumes that all legal descriptors are
>=0
> -----------------------------------------------------------------------------------------
>
>                 Key: AXIS2C-1109
>                 URL: https://issues.apache.org/jira/browse/AXIS2C-1109
>             Project: Axis2-C
>          Issue Type: Bug
>    Affects Versions: 1.3.0
>         Environment: windows xp, VS.2005
>            Reporter: Pim Philipse
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> The line
>     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
> does not work as expected under Windows, since winsock socket() returns INVALID_SOCKET
on error, which happens to be 0.
> As a result, the next call to winsock fails, which is most confusing when trying to resolve
a problem.
> Additionally, the error reporting is very terse. I have added a diagnostic function that
gives the specific error (under windows):
> #define ERRBUFSIZE 300
> void 
> get_socket_error(char *buf)
> {
> 	LPVOID lpMsgBuf;
> 	int rc = WSAGetLastError();
> 	sprintf( buf, "Winsock error %d: ", rc );
> 	FormatMessage( 
> 		 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
> 		 NULL,
> 		 rc,
> 		 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
> 		 (LPTSTR) &lpMsgBuf,
> 		 0,
> 		 NULL 
> 	);
> 	strncat( buf, (char*)lpMsgBuf, ERRBUFSIZE - strlen( buf ) - 1 );
> 	LocalFree( lpMsgBuf );
> }
> and then the error handling is invoked as, f.e.:
>     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == AXIS2_INVALID_SOCKET)
>         /*nnn AF_INET is not defined in sys/socket.h but PF_INET*/
>     {
>         char buf[ERRBUFSIZE];
>         AXIS2_ERROR_SET(env->error, AXIS2_ERROR_SOCKET_ERROR, AXIS2_FAILURE);
>         get_socket_error(buf);
>         AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, buf);
>         return AXIS2_INVALID_SOCKET;
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-c-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-c-dev-help@ws.apache.org


Mime
View raw message