[xiph-commits] r2881 - liboggplay/trunk/src/liboggplay

laser13 at svn.annodex.net laser13 at svn.annodex.net
Fri Jun 8 01:32:30 PDT 2007


Author: laser13
Date: 2007-06-08 01:32:30 -0700 (Fri, 08 Jun 2007)
New Revision: 2881

Modified:
   liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
Log:
Some changes to oggplay_tcp_reader so the reader timeouts works on Win32 platforms.

Modified: liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c
===================================================================
--- liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c	2007-06-08 08:31:05 UTC (rev 2880)
+++ liboggplay/trunk/src/liboggplay/oggplay_tcp_reader.c	2007-06-08 08:32:30 UTC (rev 2881)
@@ -83,6 +83,14 @@
 #define START_TIMEOUT(ref) \
   (ref) = oggplay_sys_time_in_ms()
 
+#ifdef WIN32 
+#define CHECK_ERROR(error) \
+  (WSAGetLastError() == WSA##error)
+#else
+#define CHECK_ERROR(error) \
+  (errno == error)
+#endif
+
 #define RETURN_ON_TIMEOUT_OR_CONTINUE(ref)        \
   if (oggplay_sys_time_in_ms() - (ref) > 500) {   \
     return E_OGGPLAY_TIMEOUT;                     \
@@ -107,6 +115,10 @@
   int                   remaining;
   char                  http_request_header[1024];
   ogg_int64_t           time_ref;
+#ifdef WIN32	
+  WORD                  wVersionRequested;
+  WSADATA               wsaData;
+#endif
 
   if (me == NULL) {
     return E_OGGPLAY_BAD_READER;
@@ -122,11 +134,10 @@
     assert(me->socket == INVALID_SOCKET);
 #ifdef WIN32	
 #ifdef HAVE_WINSOCK2        
-    WORD wVersionRequested = MAKEWORD(2,2);
+    wVersionRequested = MAKEWORD(2,2);
 #else
-    WORD wVersionRequested = MAKEWORD(1,1);
-#endif
-    WSADATA wsaData;
+    wVersionRequested = MAKEWORD(1,1);
+#endif    
     if (WSAStartup(wVersionRequested, &wsaData) == -1) {
       printf("Socket open error\n");
       return E_OGGPLAY_SOCKET_ERROR;
@@ -220,18 +231,18 @@
   if (me->state == OTRS_SOCKET_CREATED) {
     START_TIMEOUT(time_ref);
     while (connect(me->socket, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
-      if (errno == EINPROGRESS || errno == EALREADY
+    if (CHECK_ERROR(EINPROGRESS) || CHECK_ERROR(EALREADY)
 #ifdef WIN32
           /* see http://msdn2.microsoft.com/en-us/library/ms737625.aspx */
-          || errno == EWOULDBLOCK || errno == EINVAL
+          || CHECK_ERROR(EWOULDBLOCK) || CHECK_ERROR(EINVAL)
 #endif      
       ) {
         RETURN_ON_TIMEOUT_OR_CONTINUE(time_ref);
-      } else if (errno == EISCONN) {
+      } else if CHECK_ERROR(EISCONN) {
         break;
       }
       printf("Could not connect to host; error code is %d\n", errno);
-      return (errno == ETIMEDOUT) ? E_OGGPLAY_TIMEOUT : E_OGGPLAY_SOCKET_ERROR;
+      return CHECK_ERROR(ETIMEDOUT) ? E_OGGPLAY_TIMEOUT : E_OGGPLAY_SOCKET_ERROR;
     }
     me->state = OTRS_CONNECTED;
   }
@@ -248,13 +259,21 @@
     len = strlen(http_request_header);
     START_TIMEOUT(time_ref);
     while (1) {
-#if WIN32  
+#ifdef WIN32  
       nbytes = send(me->socket, pos, len, 0);
 #else  
       nbytes = write(me->socket, pos, len);
 #endif
       if (nbytes < 0) {
-        if (errno == EAGAIN) {
+#ifdef WIN32
+        /*
+         * INFO: based on the reference found at: http://tangentsoft.net/wskfaq/articles/bsd-compatibility.html
+         * but probably requires some testing
+         */
+        if CHECK_ERROR(EWOULDBLOCK) {
+#else
+        if CHECK_ERROR(EAGAIN) {
+#endif
           RETURN_ON_TIMEOUT_OR_CONTINUE(time_ref);
         }
         return E_OGGPLAY_SOCKET_ERROR;
@@ -281,13 +300,17 @@
     START_TIMEOUT(time_ref);
     while (1) {
       remaining = TCP_READER_MAX_BUFFER_SIZE - me->buffer_size;
-#if WIN32
+#ifdef WIN32
       nbytes = recv(me->socket, (char*)(me->buffer + me->buffer_size), remaining - 1, 0);
 #else
       nbytes = read(me->socket, (char*)(me->buffer + me->buffer_size), remaining - 1);
 #endif
       if (nbytes < 0) {
-        if (errno == EAGAIN) {
+#ifdef WIN32
+        if CHECK_ERROR(EWOULDBLOCK) {
+#else
+        if CHECK_ERROR(EAGAIN) {
+#endif
           RETURN_ON_TIMEOUT_OR_CONTINUE(time_ref);
         }
         return E_OGGPLAY_SOCKET_ERROR;
@@ -335,7 +358,11 @@
       nbytes = read(me->socket, me->buffer + me->buffer_size, remaining);
 #endif
       if (nbytes < 0) {
-        if (errno == EAGAIN) {
+#ifdef WIN32
+        if CHECK_ERROR(EWOULDBLOCK) {
+#else
+        if CHECK_ERROR(EAGAIN) {
+#endif
           RETURN_ON_TIMEOUT_OR_CONTINUE(time_ref);
         }
         return E_OGGPLAY_SOCKET_ERROR;



More information about the commits mailing list