Wininet vs. winsock.h
Francois Gouget
fgouget at free.fr
Fri Aug 24 10:32:22 CDT 2001
Wininet includes winsock.h but does not actually link with it. In
fact it seems it does so only to get the INVALID_SOCKET and SOCKET_ERROR
macros thus mixing winsock stuff with Unix socket stuff. It should
either link with winsock (2/32/whichever), or not use it at all. This
patch makes it completely independent from winsock.
Changelog:
* dlls/wininet/internet.h,
dlls/wininet/ftp.c,
dlls/wininet/http.c,
dlls/wininet/internet.c,
dlls/wininet/utility.c
Made independent from winsock
Include the needed headers directly in internet.h
Aside:
I recently discovered that xemacs does colorization of diffs when
they have a .diff extension. So I changed the naming convention for my
patches. Also if you modify '/etc/mime.types' to contain 'text/plain txt
text diff' (soon to be the default in Debian) you can read such files
without problem from within pine.
--
Francois Gouget fgouget at free.fr http://fgouget.free.fr/
I haven't lost my mind, it's backed up on tape around here somewhere...
-------------- next part --------------
Index: dlls/wininet/internet.h
===================================================================
RCS file: /home/wine/wine/dlls/wininet/internet.h,v
retrieving revision 1.4
diff -u -r1.4 internet.h
--- dlls/wininet/internet.h 2001/02/15 21:24:07 1.4
+++ dlls/wininet/internet.h 2001/08/24 13:29:31
@@ -2,6 +2,12 @@
#define _WINE_INTERNET_H_
#include <time.h>
+#ifdef HAVE_NETDB_H
+# include <netdb.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
typedef enum
{
Index: dlls/wininet/ftp.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/ftp.c,v
retrieving revision 1.17
diff -u -r1.17 ftp.c
--- dlls/wininet/ftp.c 2001/07/25 00:43:32 1.17
+++ dlls/wininet/ftp.c 2001/08/24 13:29:29
@@ -12,9 +12,6 @@
#include "config.h"
#include <errno.h>
-#ifdef HAVE_NETDB_H
-# include <netdb.h>
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -27,9 +24,6 @@
#ifdef HAVE_NETINET_IN_SYSTM_H
# include <netinet/in_systm.h>
#endif
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
#ifdef HAVE_NETINET_IP_H
# include <netinet/ip.h>
#endif
@@ -39,7 +33,6 @@
#include "winuser.h"
#include "wininet.h"
#include "winerror.h"
-#include "winsock.h"
#include "debugtools.h"
#include "internet.h"
@@ -236,7 +229,7 @@
}
lend:
- if (lpwfs->lstnSocket != INVALID_SOCKET)
+ if (lpwfs->lstnSocket != -1)
close(lpwfs->lstnSocket);
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC && hIC->lpfnStatusCB)
@@ -564,7 +557,7 @@
}
lend:
- if (lpwfs->lstnSocket != INVALID_SOCKET)
+ if (lpwfs->lstnSocket != -1)
close(lpwfs->lstnSocket);
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC && hIC->lpfnStatusCB)
@@ -811,7 +804,7 @@
hFile->nDataSocket = nDataSocket;
}
- if (lpwfs->lstnSocket != INVALID_SOCKET)
+ if (lpwfs->lstnSocket != -1)
close(lpwfs->lstnSocket);
hIC = (LPWININETAPPINFOA) lpwfs->hdr.lpwhparent;
@@ -948,7 +941,7 @@
}
lend:
- if (lpwfs->lstnSocket != INVALID_SOCKET)
+ if (lpwfs->lstnSocket != -1)
close(lpwfs->lstnSocket);
if (hFile)
@@ -1276,7 +1269,7 @@
{
struct sockaddr_in socketAddr;
struct hostent *phe = NULL;
- INT nsocket = INVALID_SOCKET, sock_namelen;
+ INT nsocket = -1, sock_namelen;
LPWININETAPPINFOA hIC = NULL;
BOOL bSuccess = FALSE;
LPWININETFTPSESSIONA lpwfs = NULL;
@@ -1313,7 +1306,8 @@
hIC->lpfnStatusCB(hInternet, dwContext, INTERNET_STATUS_NAME_RESOLVED,
(LPSTR) lpszServerName, strlen(lpszServerName));
- if (INVALID_SOCKET == (nsocket = socket(AF_INET,SOCK_STREAM,0)))
+ nsocket = socket(AF_INET,SOCK_STREAM,0);
+ if (nsocket == -1)
{
INTERNET_SetLastError(ERROR_INTERNET_CANNOT_CONNECT);
goto lerror;
@@ -1380,7 +1374,7 @@
}
lerror:
- if (!bSuccess && INVALID_SOCKET != nsocket)
+ if (!bSuccess && nsocket == -1)
close(nsocket);
if (!bSuccess && lpwfs)
@@ -1483,7 +1477,7 @@
bParamHasLen ? lpszParam : "", szCRLF);
TRACE("Sending (%s) len(%ld)\n", buf, len);
- while((nBytesSent < len) && (nRC != SOCKET_ERROR))
+ while((nBytesSent < len) && (nRC != -1))
{
nRC = send(nSocket, buf+nBytesSent, len - nBytesSent, 0);
nBytesSent += nRC;
@@ -1496,7 +1490,7 @@
&nBytesSent, sizeof(DWORD));
TRACE("Sent %ld bytes\n", nBytesSent);
- return (nRC != SOCKET_ERROR);
+ return (nRC != -1);
}
@@ -1679,10 +1673,10 @@
}
lend:
- if (!bSuccess && INVALID_SOCKET != lpwfs->lstnSocket)
+ if (!bSuccess && lpwfs->lstnSocket != -1)
{
close(lpwfs->lstnSocket);
- lpwfs->lstnSocket = INVALID_SOCKET;
+ lpwfs->lstnSocket = -1;
}
return bSuccess;
@@ -1707,7 +1701,7 @@
TRACE("\n");
lpwfs->lstnSocket = socket(PF_INET, SOCK_STREAM, 0);
- if (INVALID_SOCKET == lpwfs->lstnSocket)
+ if (lpwfs->lstnSocket == -1)
{
TRACE("Unable to create listening socket\n");
goto lend;
@@ -1719,26 +1713,26 @@
/* and get the system to assign us a port */
lpwfs->lstnSocketAddress.sin_port = htons((u_short) 0);
- if (SOCKET_ERROR == bind(lpwfs->lstnSocket,(struct sockaddr *) &lpwfs->lstnSocketAddress, sizeof(struct sockaddr_in)))
+ if (bind(lpwfs->lstnSocket,(struct sockaddr *) &lpwfs->lstnSocketAddress, sizeof(struct sockaddr_in)) == -1)
{
TRACE("Unable to bind socket\n");
goto lend;
}
- if (SOCKET_ERROR == listen(lpwfs->lstnSocket, MAX_BACKLOG))
+ if (listen(lpwfs->lstnSocket, MAX_BACKLOG) == -1)
{
TRACE("listen failed\n");
goto lend;
}
- if (SOCKET_ERROR != getsockname(lpwfs->lstnSocket, (struct sockaddr *) &lpwfs->lstnSocketAddress, &namelen))
+ if (getsockname(lpwfs->lstnSocket, (struct sockaddr *) &lpwfs->lstnSocketAddress, &namelen) != -1)
bSuccess = TRUE;
lend:
- if (!bSuccess && INVALID_SOCKET == lpwfs->lstnSocket)
+ if (!bSuccess && lpwfs->lstnSocket == -1)
{
close(lpwfs->lstnSocket);
- lpwfs->lstnSocket = INVALID_SOCKET;
+ lpwfs->lstnSocket = -1;
}
return bSuccess;
@@ -1860,7 +1854,7 @@
int f[6];
int i;
char *pAddr, *pPort;
- INT nsocket = INVALID_SOCKET;
+ INT nsocket = -1;
struct sockaddr_in dataSocketAddress;
p = lpszResponseBuffer+4; /* skip status code */
@@ -1898,7 +1892,8 @@
pPort[0] = f[4];
pPort[1] = f[5];
- if (INVALID_SOCKET == (nsocket = socket(AF_INET,SOCK_STREAM,0)))
+ nsocket = socket(AF_INET,SOCK_STREAM,0);
+ if (nsocket == -1)
goto lend;
if (connect(nsocket, (struct sockaddr *)&dataSocketAddress, sizeof(dataSocketAddress)))
@@ -1961,9 +1956,9 @@
{
*nDataSocket = accept(lpwfs->lstnSocket, (struct sockaddr *) &saddr, &addrlen);
close(lpwfs->lstnSocket);
- lpwfs->lstnSocket = INVALID_SOCKET;
+ lpwfs->lstnSocket = -1;
}
- return *nDataSocket != INVALID_SOCKET;
+ return *nDataSocket != -1;
}
@@ -2017,7 +2012,7 @@
DATA_PACKET_SIZE : nBytesToSend;
nRC = send(nDataSocket, lpszBuffer, nLen, 0);
- if (nRC != SOCKET_ERROR)
+ if (nRC != -1)
{
nBytesSent += nRC;
nTotalSent += nRC;
@@ -2038,7 +2033,7 @@
nTotalSent, fi.nFileSizeLow, nTotalSent*100/fi.nFileSizeLow, nSeconds,
(fi.nFileSizeLow - nTotalSent) * nSeconds / nTotalSent);
}
- } while (nRC != SOCKET_ERROR);
+ } while (nRC != -1);
TRACE("file transfer complete!\n");
@@ -2104,10 +2099,10 @@
}
lend:
- if (0 == nResult && INVALID_SOCKET != lpwfs->lstnSocket)
+ if (0 == nResult && lpwfs->lstnSocket != -1)
{
close(lpwfs->lstnSocket);
- lpwfs->lstnSocket = INVALID_SOCKET;
+ lpwfs->lstnSocket = -1;
}
return nResult;
@@ -2143,10 +2138,10 @@
return FALSE;
}
- while (nBytesReceived < nBytes && nRC != SOCKET_ERROR)
+ while (nBytesReceived < nBytes && nRC != -1)
{
nRC = recv(nDataSocket, lpszBuffer, DATA_PACKET_SIZE, 0);
- if (nRC != SOCKET_ERROR)
+ if (nRC != -1)
{
/* other side closed socket. */
if (nRC == 0)
@@ -2164,7 +2159,7 @@
HeapFree(GetProcessHeap(), 0, lpszBuffer);
recv_end:
- return (nRC != SOCKET_ERROR);
+ return (nRC != -1);
}
@@ -2180,10 +2175,10 @@
*/
BOOL FTP_CloseSessionHandle(LPWININETFTPSESSIONA lpwfs)
{
- if (INVALID_SOCKET != lpwfs->sndSocket)
+ if (lpwfs->sndSocket != -1)
close(lpwfs->sndSocket);
- if (INVALID_SOCKET != lpwfs->lstnSocket)
+ if (lpwfs->lstnSocket != -1)
close(lpwfs->lstnSocket);
if (lpwfs->lpszPassword)
Index: dlls/wininet/http.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/http.c,v
retrieving revision 1.16
diff -u -r1.16 http.c
--- dlls/wininet/http.c 2001/06/20 23:03:16 1.16
+++ dlls/wininet/http.c 2001/08/24 13:29:30
@@ -14,16 +14,12 @@
#include "wininet.h"
#include "debugtools.h"
#include "winerror.h"
-#include "winsock.h"
#include "shlwapi.h"
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
-#ifdef HAVE_NETDB_H
-# include <netdb.h>
-#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -223,7 +219,7 @@
lpwhr->hdr.lpwhparent = hHttpSession;
lpwhr->hdr.dwFlags = dwFlags;
lpwhr->hdr.dwContext = dwContext;
- lpwhr->nSocketFD = INVALID_SOCKET;
+ lpwhr->nSocketFD = -1;
if (NULL != lpszObjectName && strlen(lpszObjectName)) {
DWORD needed = 0;
@@ -847,7 +843,7 @@
lpwhs = (LPWININETHTTPSESSIONA)lpwhr->hdr.lpwhparent;
lpwhr->nSocketFD = socket(lpwhs->phostent->h_addrtype,SOCK_STREAM,0);
- if (INVALID_SOCKET == lpwhr->nSocketFD)
+ if (lpwhr->nSocketFD == -1)
{
WARN("Socket creation failed\n");
goto lend;
@@ -856,7 +852,7 @@
result = connect(lpwhr->nSocketFD, (struct sockaddr *)&lpwhs->socketAddress,
sizeof(lpwhs->socketAddress));
- if (SOCKET_ERROR == result)
+ if (result == -1)
{
WARN("Unable to connect to host (%s)\n", strerror(errno));
goto lend;
@@ -890,7 +886,7 @@
TRACE("\n");
- if (INVALID_SOCKET == lpwhr->nSocketFD)
+ if (lpwhr->nSocketFD == -1)
goto lend;
/*
@@ -1213,10 +1209,10 @@
*/
VOID HTTP_CloseConnection(LPWININETHTTPREQA lpwhr)
{
- if (lpwhr->nSocketFD != INVALID_SOCKET)
+ if (lpwhr->nSocketFD != -1)
{
close(lpwhr->nSocketFD);
- lpwhr->nSocketFD = INVALID_SOCKET;
+ lpwhr->nSocketFD = -1;
}
}
@@ -1233,7 +1229,7 @@
TRACE("\n");
- if (lpwhr->nSocketFD != INVALID_SOCKET)
+ if (lpwhr->nSocketFD != -1)
HTTP_CloseConnection(lpwhr);
if (lpwhr->lpszPath)
Index: dlls/wininet/internet.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/internet.c,v
retrieving revision 1.21
diff -u -r1.21 internet.c
--- dlls/wininet/internet.c 2001/07/11 17:24:39 1.21
+++ dlls/wininet/internet.c 2001/08/24 13:29:31
@@ -24,7 +24,6 @@
#include "wininet.h"
#include "debugtools.h"
#include "winerror.h"
-#include "winsock.h"
#include "shlwapi.h"
#include "internet.h"
@@ -784,7 +783,7 @@
DWORD dwNumOfBytesToWrite, LPDWORD lpdwNumOfBytesWritten)
{
BOOL retval = FALSE;
- int nSocket = INVALID_SOCKET;
+ int nSocket = -1;
LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hFile;
TRACE("\n");
@@ -805,7 +804,7 @@
break;
}
- if (INVALID_SOCKET != nSocket)
+ if (nSocket != -1)
{
*lpdwNumOfBytesWritten = INTERNET_WriteDataToStream(nSocket, lpBuffer, dwNumOfBytesToWrite);
if (*lpdwNumOfBytesWritten < 0)
@@ -832,7 +831,7 @@
DWORD dwNumOfBytesToRead, LPDWORD dwNumOfBytesRead)
{
BOOL retval = FALSE;
- int nSocket = INVALID_SOCKET;
+ int nSocket = -1;
LPWININETHANDLEHEADER lpwh = (LPWININETHANDLEHEADER) hFile;
TRACE("\n");
@@ -853,7 +852,7 @@
break;
}
- if (INVALID_SOCKET != nSocket)
+ if (nSocket != -1)
{
*dwNumOfBytesRead = INTERNET_ReadDataFromStream(nSocket, lpBuffer, dwNumOfBytesToRead);
if (*dwNumOfBytesRead < 0)
@@ -1063,8 +1062,8 @@
*/
int INTERNET_WriteDataToStream(int nDataSocket, LPCVOID Buffer, DWORD BytesToWrite)
{
- if (INVALID_SOCKET == nDataSocket)
- return SOCKET_ERROR;
+ if (nDataSocket == -1)
+ return -1;
return send(nDataSocket, Buffer, BytesToWrite, 0);
}
@@ -1082,8 +1081,8 @@
*/
int INTERNET_ReadDataFromStream(int nDataSocket, LPVOID Buffer, DWORD BytesToRead)
{
- if (INVALID_SOCKET == nDataSocket)
- return SOCKET_ERROR;
+ if (nDataSocket == -1)
+ return -1;
return recv(nDataSocket, Buffer, BytesToRead, 0);
}
Index: dlls/wininet/utility.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/utility.c,v
retrieving revision 1.4
diff -u -r1.4 utility.c
--- dlls/wininet/utility.c 2000/11/30 01:31:29 1.4
+++ dlls/wininet/utility.c 2001/08/24 13:29:32
@@ -17,7 +17,6 @@
#include "winbase.h"
#include "wininet.h"
#include "winerror.h"
-#include "winsock.h"
#include "debugtools.h"
#include "internet.h"
More information about the wine-patches
mailing list