wininet: Use a helper to receive data and take care of EINTR

Bruno Jesus 00cpxxx at gmail.com
Thu Jun 12 00:24:45 CDT 2014


-------------- next part --------------
diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index 5576de9..855aee0 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -1195,7 +1195,7 @@ static DWORD FTPFILE_ReadFile(object_header_t *hdr, void *buffer, DWORD size, DW
         return ERROR_INTERNET_DISCONNECTED;
 
     /* FIXME: FTP should use NETCON_ stuff */
-    res = recv(file->nDataSocket, buffer, size, MSG_WAITALL);
+    res = sock_recv(file->nDataSocket, buffer, size, MSG_WAITALL);
     *read = res>0 ? res : 0;
 
     error = res >= 0 ? ERROR_SUCCESS : INTERNET_ERROR_BASE; /* FIXME */
@@ -1234,7 +1234,7 @@ static void FTP_ReceiveRequestData(ftp_file_t *file, BOOL first_notif)
 
     TRACE("%p\n", file);
 
-    available = recv(file->nDataSocket, buffer, sizeof(buffer), MSG_PEEK);
+    available = sock_recv(file->nDataSocket, buffer, sizeof(buffer), MSG_PEEK);
 
     if(available != -1) {
         iar.dwResult = (DWORD_PTR)file->hdr.hInternet;
@@ -1277,7 +1277,7 @@ static DWORD FTPFILE_QueryDataAvailable(object_header_t *hdr, DWORD *available,
 
         *available = 0;
 
-        retval = recv(file->nDataSocket, &byte, 1, MSG_PEEK);
+        retval = sock_recv(file->nDataSocket, &byte, 1, MSG_PEEK);
         if(retval > 0) {
             task_header_t *task;
 
@@ -3368,7 +3368,7 @@ static BOOL FTP_RetrieveFileData(ftp_session_t *lpwfs, INT nDataSocket, HANDLE h
 
     while (nRC != -1)
     {
-        nRC = recv(nDataSocket, lpszBuffer, DATA_PACKET_SIZE, 0);
+        nRC = sock_recv(nDataSocket, lpszBuffer, DATA_PACKET_SIZE, 0);
         if (nRC != -1)
         {
             /* other side closed socket. */
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index 4389c98..bb46a43 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -3928,7 +3928,7 @@ LPSTR INTERNET_GetNextLine(INT nSocket, LPDWORD dwLen)
     {
         if (poll(&pfd,1, RESPONSE_TIMEOUT * 1000) > 0)
         {
-            if (recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
+            if (sock_recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
             {
                 INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
                 goto lend;
diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h
index 87369c6..b823e43 100644
--- a/dlls/wininet/internet.h
+++ b/dlls/wininet/internet.h
@@ -458,6 +458,7 @@ int NETCON_GetCipherStrength(netconn_t*) DECLSPEC_HIDDEN;
 DWORD NETCON_set_timeout(netconn_t *connection, BOOL send, DWORD value) DECLSPEC_HIDDEN;
 int sock_get_error(int) DECLSPEC_HIDDEN;
 int sock_send(int fd, const void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
+int sock_recv(int fd, void *msg, size_t len, int flags) DECLSPEC_HIDDEN;
 
 server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL,BOOL);
 
diff --git a/dlls/wininet/netconnection.c b/dlls/wininet/netconnection.c
index 595dd71..483dba4 100644
--- a/dlls/wininet/netconnection.c
+++ b/dlls/wininet/netconnection.c
@@ -507,6 +507,17 @@ int sock_send(int fd, const void *msg, size_t len, int flags)
     return ret;
 }
 
+int sock_recv(int fd, void *msg, size_t len, int flags)
+{
+    int ret;
+    do
+    {
+        ret = recv(fd, msg, len, flags);
+    }
+    while(ret == -1 && errno == EINTR);
+    return ret;
+}
+
 static void set_socket_blocking(int socket, blocking_mode_t mode)
 {
 #if defined(__MINGW32__) || defined (_MSC_VER)
@@ -596,7 +607,7 @@ static DWORD netcon_secure_connect_setup(netconn_t *connection, BOOL compat_mode
             read_buf_size += 1024;
         }
 
-        size = recv(connection->socket, read_buf+in_bufs[0].cbBuffer, read_buf_size-in_bufs[0].cbBuffer, 0);
+        size = sock_recv(connection->socket, read_buf+in_bufs[0].cbBuffer, read_buf_size-in_bufs[0].cbBuffer, 0);
         if(size < 1) {
             WARN("recv error\n");
             res = ERROR_INTERNET_SECURITY_CHANNEL_ERROR;
@@ -799,7 +810,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, blocking
 
     tmp_mode = buf_len ? BLOCKING_DISALLOW : mode;
     set_socket_blocking(conn->socket, tmp_mode);
-    size = recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, tmp_mode == BLOCKING_ALLOW ? 0 : WINE_MSG_DONTWAIT);
+    size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, tmp_mode == BLOCKING_ALLOW ? 0 : WINE_MSG_DONTWAIT);
     if(size < 0) {
         if(!buf_len) {
             if(errno == EAGAIN || errno == EWOULDBLOCK) {
@@ -840,7 +851,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, blocking
             assert(buf_len < ssl_buf_size);
 
             set_socket_blocking(conn->socket, mode);
-            size = recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, mode == BLOCKING_ALLOW ? 0 : WINE_MSG_DONTWAIT);
+            size = sock_recv(conn->socket, conn->ssl_buf+buf_len, ssl_buf_size-buf_len, mode == BLOCKING_ALLOW ? 0 : WINE_MSG_DONTWAIT);
             if(size < 1) {
                 if(size < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
                     TRACE("would block\n");
@@ -924,7 +935,7 @@ DWORD NETCON_recv(netconn_t *connection, void *buf, size_t len, blocking_mode_t
         }
 
         set_socket_blocking(connection->socket, mode);
-	*recvd = recv(connection->socket, buf, len, flags);
+	*recvd = sock_recv(connection->socket, buf, len, flags);
 	return *recvd == -1 ? sock_get_error(errno) :  ERROR_SUCCESS;
     }
     else
@@ -1012,7 +1023,7 @@ BOOL NETCON_is_alive(netconn_t *netconn)
     ssize_t len;
     BYTE b;
 
-    len = recv(netconn->socket, &b, 1, MSG_PEEK|MSG_DONTWAIT);
+    len = sock_recv(netconn->socket, &b, 1, MSG_PEEK|MSG_DONTWAIT);
     return len == 1 || (len == -1 && errno == EWOULDBLOCK);
 #elif defined(__MINGW32__) || defined(_MSC_VER)
     ULONG mode;
@@ -1023,7 +1034,7 @@ BOOL NETCON_is_alive(netconn_t *netconn)
     if(!ioctlsocket(netconn->socket, FIONBIO, &mode))
         return FALSE;
 
-    len = recv(netconn->socket, &b, 1, MSG_PEEK);
+    len = sock_recv(netconn->socket, &b, 1, MSG_PEEK);
 
     mode = 0;
     if(!ioctlsocket(netconn->socket, FIONBIO, &mode))


More information about the wine-patches mailing list