Author: Mark
Date: Wed Apr 6 06:35:00 2005
New Revision: 2456
Modified:
trunk/include/neostats.h
trunk/src/ossocket.c
trunk/src/win32/winmain.c
Log:
winsock updates and more ossocket layer calls
Modified: trunk/include/neostats.h
==============================================================================
--- trunk/include/neostats.h (original)
+++ trunk/include/neostats.h Wed Apr 6 06:35:00 2005
@@ -1460,14 +1460,16 @@
/* Socket functions */
EXPORTFUNC int os_sock_close( OS_SOCKET sock );
EXPORTFUNC int os_sock_write( OS_SOCKET s, const char *buf, int len );
+EXPORTFUNC int os_sock_sendto( OS_SOCKET s, const char* buf, int len, int flags, const struct sockaddr* to, int tolen );
EXPORTFUNC int os_sock_read( OS_SOCKET s, char *buf, int len );
EXPORTFUNC int os_sock_set_nonblocking( OS_SOCKET s );
-int os_sock_connect( OS_SOCKET s, const struct sockaddr* name, int namelen );
-OS_SOCKET os_sock_socket(int socket_family, int socket_type, int protocol );
-int os_sock_bind(OS_SOCKET s, const struct sockaddr* name, int namelen );
-int os_sock_listen( OS_SOCKET s, int backlog );
-int os_sock_setsockopt( OS_SOCKET s, int level, int optname, const char* optval, int optlen );
-int os_sock_ioctl( OS_SOCKET s, int cmd, void* argp );
+EXPORTFUNC int os_sock_connect( OS_SOCKET s, const struct sockaddr* name, int namelen );
+EXPORTFUNC OS_SOCKET os_sock_socket(int socket_family, int socket_type, int protocol );
+EXPORTFUNC int os_sock_bind(OS_SOCKET s, const struct sockaddr* name, int namelen );
+EXPORTFUNC int os_sock_listen( OS_SOCKET s, int backlog );
+EXPORTFUNC int os_sock_setsockopt( OS_SOCKET s, int level, int optname, const char* optval, int optlen );
+EXPORTFUNC int os_sock_ioctl( OS_SOCKET s, int cmd, void* argp );
+EXPORTVAR int os_sock_errno;
/* Memory functions */
EXPORTFUNC void *os_memset( void *dest, int c, size_t count );
Modified: trunk/src/ossocket.c
==============================================================================
--- trunk/src/ossocket.c (original)
+++ trunk/src/ossocket.c Wed Apr 6 06:35:00 2005
@@ -313,6 +313,33 @@
}
/*
+ * Wrapper function for sendto
+ */
+
+int os_sock_sendto( OS_SOCKET s, const char* buf, int len, int flags, const struct sockaddr* to, int tolen )
+{
+ int ret;
+
+ /* reset local errno implementation */
+ os_sock_errno = 0;
+ ret = sendto( s, buf, len, flags, to, tolen );
+#ifdef WIN32
+ if( ret == SOCKET_ERROR )
+ {
+ os_sock_errno = WSAGetLastError();
+ nlog( LOG_ERROR, "os_sock_sendto: failed for socket %d with error %d %s", s, os_sock_errno, WinSockErrToString( os_sock_errno ) );
+ }
+#else
+ if( ret < 0 )
+ {
+ os_sock_errno = errno;
+ nlog( LOG_ERROR, "os_sock_sendto: failed for socket %d with error %s", s, strerror( errno ) );
+ }
+#endif
+ return ret;
+}
+
+/*
* Wrapper function for sock_read
*/
@@ -341,6 +368,33 @@
}
/*
+ * Wrapper function for recvfrom
+ */
+
+int os_sock_recvfrom( SOCKET s, char* buf, int len, int flags, struct sockaddr* from, int* fromlen )
+{
+ int ret;
+
+ /* reset local errno implementation */
+ os_sock_errno = 0;
+ ret = recvfrom( s, buf, len, flags, from, fromlen );
+#ifdef WIN32
+ if( ret == SOCKET_ERROR )
+ {
+ os_sock_errno = WSAGetLastError();
+ nlog( LOG_ERROR, "os_sock_recvfrom: failed for socket %d with error %d %s", s, os_sock_errno, WinSockErrToString( os_sock_errno ) );
+ }
+#else
+ if( ret < 0 )
+ {
+ os_sock_errno = errno;
+ nlog( LOG_ERROR, "os_sock_recvfrom: failed for socket %d with error %s", s, strerror( errno ) );
+ }
+#endif
+ return ret;
+}
+
+/*
* Wrapper function for sock_set_nonblocking
*/
@@ -394,6 +448,7 @@
switch( os_sock_errno )
{
case WSAEWOULDBLOCK:
+ case WSAEINPROGRESS:
return 0;
}
nlog( LOG_ERROR, "os_sock_connect: %s failed for socket %d with error %d %s", GET_CUR_MODNAME(), s, os_sock_errno, WinSockErrToString( os_sock_errno ) );
Modified: trunk/src/win32/winmain.c
==============================================================================
--- trunk/src/win32/winmain.c (original)
+++ trunk/src/win32/winmain.c Wed Apr 6 06:35:00 2005
@@ -112,11 +112,18 @@
_fmode = _O_BINARY;
hInstance = hInst;
- if( WSAStartup( MAKEWORD( 1, 1 ), &WSAData ) != 0 )
+ if( WSAStartup( MAKEWORD( 2, 0 ), &WSAData ) != 0 )
{
ErrorMessageBox( "Unable to initialize WinSock" );
+ WSACleanup();
return FALSE;
}
+ if (LOBYTE( WSAData.wVersion ) != 2 || HIBYTE( WSAData.wVersion ) != 0 ) {
+ ErrorMessageBox( "Unable to initialize WinSock, need version 2.0 or higher" );
+ WSACleanup();
+ return FALSE;
+ }
+
#ifndef NDEBUG
InitDebugConsole();
#endif
@@ -125,12 +132,14 @@
{
wsprintf( szMsg, "Error x%x", GetLastError() );
ErrorMessageBox( szMsg );
+ WSACleanup();
return FALSE;
}
if( neostats() != 0 )
{
ErrorMessageBox( "NeoStats init failed" );
+ WSACleanup();
return FALSE;
}
@@ -146,6 +155,8 @@
if( hNeoStatsThread == NULL )
{
ErrorMessageBox( "CreateThread failed." );
+ WSACleanup();
+ return FALSE;
}
while( ( GetMessage( &msg, NULL, 0, 0 ) ) != 0 )
@@ -156,5 +167,6 @@
DispatchMessage( &msg );
}
}
+ WSACleanup();
return (int) msg.wParam;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.