From c91ae456b8b4804de359673652042908bfad08e5 Mon Sep 17 00:00:00 2001 From: Steven Edwards Date: Fri, 3 Sep 2004 18:57:19 +0000 Subject: [PATCH] Use Windows sockets when building Wininet on Mingw. --- configure | 8 ++++++-- configure.ac | 6 ++++-- dlls/wininet/Makefile.in | 2 +- dlls/wininet/ftp.c | 30 +++++++++++++++--------------- dlls/wininet/internet.h | 6 ++++++ dlls/wininet/netconnection.c | 6 +++--- include/winsock.h | 3 +++ 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/configure b/configure index 58dbf88d7e5..9c765793131 100755 --- a/configure +++ b/configure @@ -311,7 +311,7 @@ ac_includes_default="\ # include #endif" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS WIN16_FILES WIN16_INSTALL build build_cpu build_vendor build_os host host_cpu host_vendor host_os SET_MAKE CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CPPBIN ac_ct_CPPBIN TOOLSDIR CPP X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS LEX LEXLIB LEX_OUTPUT_ROOT XLEX BISON AS ac_ct_AS LD ac_ct_LD AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP WINDRES ac_ct_WINDRES LN_S LN EGREP LDCONFIG INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LINT LINTFLAGS DB2HTML DB2PDF DB2PS DB2TXT FONTFORGE LIBPTHREAD XLIB XFILES OPENGLFILES GLU32FILES OPENGL_LIBS GLUT_LIBS GLUT32FILES NASLIBS CURSESLIBS sane_devel SANELIBS SANEINCL ICULIBS ft_devel ft_devel2 FREETYPELIBS FREETYPEINCL FONTSSUBDIRS ARTSCCONFIG ARTSLIBS ARTSINCL ALSALIBS AUDIOIOLIBS CAPI4LINUXLIBS EXTRACFLAGS DLLEXT DLLFLAGS DLLIBS LDSHARED LDDLLFLAGS LIBEXT IMPLIBEXT DLLTOOL ac_ct_DLLTOOL DLLWRAP ac_ct_DLLWRAP LDEXECFLAGS LDLIBWINEFLAGS COREFOUNDATIONLIB IOKITLIB CROSSTEST CROSSCC CROSSWINDRES LDPATH CRTLIBS WINE_BINARIES MAIN_BINARY LDD ALLOCA LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS WIN16_FILES WIN16_INSTALL build build_cpu build_vendor build_os host host_cpu host_vendor host_os SET_MAKE CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CXX CXXFLAGS ac_ct_CXX CPPBIN ac_ct_CPPBIN TOOLSDIR CPP X_CFLAGS X_PRE_LIBS X_LIBS X_EXTRA_LIBS LEX LEXLIB LEX_OUTPUT_ROOT XLEX BISON AS ac_ct_AS LD ac_ct_LD AR ac_ct_AR RANLIB ac_ct_RANLIB STRIP ac_ct_STRIP WINDRES ac_ct_WINDRES LN_S LN EGREP LDCONFIG INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA LINT LINTFLAGS DB2HTML DB2PDF DB2PS DB2TXT FONTFORGE LIBPTHREAD XLIB XFILES OPENGLFILES GLU32FILES OPENGL_LIBS GLUT_LIBS GLUT32FILES NASLIBS CURSESLIBS sane_devel SANELIBS SANEINCL ICULIBS ft_devel ft_devel2 FREETYPELIBS FREETYPEINCL FONTSSUBDIRS ARTSCCONFIG ARTSLIBS ARTSINCL ALSALIBS AUDIOIOLIBS CAPI4LINUXLIBS EXTRACFLAGS DLLEXT DLLFLAGS DLLIBS LDSHARED LDDLLFLAGS LIBEXT IMPLIBEXT DLLTOOL ac_ct_DLLTOOL DLLWRAP ac_ct_DLLWRAP LDEXECFLAGS LDLIBWINEFLAGS COREFOUNDATIONLIB IOKITLIB CROSSTEST CROSSCC CROSSWINDRES LDPATH CRTLIBS SOCKETLIBS WINE_BINARIES MAIN_BINARY LDD ALLOCA LIBOBJS LTLIBOBJS' ac_subst_files='MAKE_RULES MAKE_DLL_RULES MAKE_TEST_RULES MAKE_LIB_RULES MAKE_PROG_RULES' # Initialize some variables set by options. @@ -14217,7 +14217,10 @@ esac case $host_os in mingw32*) CRTLIBS="-lmsvcrt" - ;; + + SOCKETLIBS="-lws2_32" + + ;; esac case $host_os in @@ -20998,6 +21001,7 @@ s,@CROSSCC@,$CROSSCC,;t t s,@CROSSWINDRES@,$CROSSWINDRES,;t t s,@LDPATH@,$LDPATH,;t t s,@CRTLIBS@,$CRTLIBS,;t t +s,@SOCKETLIBS@,$SOCKETLIBS,;t t s,@WINE_BINARIES@,$WINE_BINARIES,;t t s,@MAIN_BINARY@,$MAIN_BINARY,;t t s,@LDD@,$LDD,;t t diff --git a/configure.ac b/configure.ac index 71467ab70ad..7a9499d3289 100644 --- a/configure.ac +++ b/configure.ac @@ -984,10 +984,12 @@ case $build_os in AC_SUBST(LDPATH,"LD_LIBRARY_PATH=\"\$(TOOLSDIR)/libs/unicode:\$\$LD_LIBRARY_PATH\"") ;; esac -dnl Mingw needs explicit msvcrt for linking libwine +dnl Mingw needs explicit msvcrt for linking libwine and winsock for wininet case $host_os in mingw32*) - AC_SUBST(CRTLIBS,"-lmsvcrt") ;; + AC_SUBST(CRTLIBS,"-lmsvcrt") + AC_SUBST(SOCKETLIBS,"-lws2_32") + ;; esac case $host_os in diff --git a/dlls/wininet/Makefile.in b/dlls/wininet/Makefile.in index edefa87d396..cea2a82a299 100644 --- a/dlls/wininet/Makefile.in +++ b/dlls/wininet/Makefile.in @@ -5,7 +5,7 @@ SRCDIR = @srcdir@ VPATH = @srcdir@ MODULE = wininet.dll IMPORTS = mpr shlwapi shell32 user32 advapi32 kernel32 ntdll -EXTRALIBS = $(LIBUNICODE) +EXTRALIBS = $(LIBUNICODE) @SOCKETLIBS@ C_SRCS = \ cookie.c \ diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c index d1a8ec6af38..5ae04b9a111 100644 --- a/dlls/wininet/ftp.c +++ b/dlls/wininet/ftp.c @@ -272,7 +272,7 @@ BOOL WINAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile, if (FTP_GetDataSocket(lpwfs, &nDataSocket)) { FTP_SendData(lpwfs, nDataSocket, hFile); - close(nDataSocket); + closesocket(nDataSocket); nResCode = FTP_ReceiveResponse(lpwfs, dwContext); if (nResCode) { @@ -286,7 +286,7 @@ BOOL WINAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile, lend: if (lpwfs->lstnSocket != -1) - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC && hIC->lpfnStatusCB) { @@ -691,7 +691,7 @@ HINTERNET WINAPI FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW lpwfs, if (FTP_GetDataSocket(lpwfs, &nDataSocket)) { hFindNext = FTP_ReceiveFileList(lpwfs, nDataSocket, lpszSearchFile, lpFindFileData, dwContext); - close(nDataSocket); + closesocket(nDataSocket); nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext); if (nResCode != 226 && nResCode != 250) INTERNET_SetLastError(ERROR_NO_MORE_FILES); @@ -703,7 +703,7 @@ HINTERNET WINAPI FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW lpwfs, lend: if (lpwfs->lstnSocket != -1) - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC && hIC->lpfnStatusCB) { @@ -1034,7 +1034,7 @@ HINTERNET FTP_FtpOpenFileW(LPWININETFTPSESSIONW lpwfs, } if (lpwfs->lstnSocket != -1) - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); hIC = (LPWININETAPPINFOW) lpwfs->hdr.lpwhparent; if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC && hIC->lpfnStatusCB) @@ -1207,13 +1207,13 @@ BOOL WINAPI FTP_FtpGetFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile, else FTP_SetResponseError(nResCode); } - close(nDataSocket); + closesocket(nDataSocket); } } lend: if (lpwfs->lstnSocket != -1) - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); if (hFile) CloseHandle(hFile); @@ -1741,7 +1741,7 @@ HINTERNET FTP_Connect(LPWININETAPPINFOW hIC, LPCWSTR lpszServerName, lerror: if (!bSuccess && nsocket == -1) - close(nsocket); + closesocket(nsocket); if (!bSuccess && lpwfs) { @@ -2066,7 +2066,7 @@ BOOL FTP_SendStore(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile, DWORD dwT lend: if (!bSuccess && lpwfs->lstnSocket != -1) { - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); lpwfs->lstnSocket = -1; } @@ -2122,7 +2122,7 @@ BOOL FTP_InitListenSocket(LPWININETFTPSESSIONW lpwfs) lend: if (!bSuccess && lpwfs->lstnSocket == -1) { - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); lpwfs->lstnSocket = -1; } @@ -2386,7 +2386,7 @@ BOOL FTP_GetDataSocket(LPWININETFTPSESSIONW lpwfs, LPINT nDataSocket) else { *nDataSocket = accept(lpwfs->lstnSocket, (struct sockaddr *) &saddr, &addrlen); - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); lpwfs->lstnSocket = -1; } return *nDataSocket != -1; @@ -2518,7 +2518,7 @@ DWORD FTP_SendRetrieve(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile, DWORD lend: if (0 == nResult && lpwfs->lstnSocket != -1) { - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); lpwfs->lstnSocket = -1; } @@ -2600,10 +2600,10 @@ static void FTP_CloseSessionHandle(LPWININETHANDLEHEADER hdr) lpwfs->download_in_progress->session_deleted = TRUE; if (lpwfs->sndSocket != -1) - close(lpwfs->sndSocket); + closesocket(lpwfs->sndSocket); if (lpwfs->lstnSocket != -1) - close(lpwfs->lstnSocket); + closesocket(lpwfs->lstnSocket); if (lpwfs->lpszPassword) HeapFree(GetProcessHeap(), 0, lpwfs->lpszPassword); @@ -2668,7 +2668,7 @@ static void FTP_CloseFileTransferHandle(LPWININETHANDLEHEADER hdr) nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext); if (lpwh->nDataSocket != -1) - close(lpwh->nDataSocket); + closesocket(lpwh->nDataSocket); HeapFree(GetProcessHeap(), 0, lpwh); } diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h index ccbab953a53..95daf6ddd7e 100644 --- a/dlls/wininet/internet.h +++ b/dlls/wininet/internet.h @@ -45,6 +45,12 @@ # include #endif +#ifdef __MINGW32__ +#include "winsock2.h" +#else +#define closesocket close +#endif /* __MINGW32__ */ + /* used for netconnection.c stuff */ typedef struct { diff --git a/dlls/wininet/netconnection.c b/dlls/wininet/netconnection.c index 6b338a0a337..4b055d3f567 100644 --- a/dlls/wininet/netconnection.c +++ b/dlls/wininet/netconnection.c @@ -228,7 +228,7 @@ BOOL NETCON_close(WININET_NETCONNECTION *connection) if (!connection->useSSL) { int result; - result = close(connection->socketFD); + result = closesocket(connection->socketFD); connection->socketFD = -1; if (result == -1) return FALSE; @@ -237,7 +237,7 @@ BOOL NETCON_close(WININET_NETCONNECTION *connection) else { #ifdef HAVE_OPENSSL_SSL_H - close(connection->ssl_sock); + closesocket(connection->ssl_sock); connection->ssl_sock = -1; /* FIXME should we call SSL_shutdown here?? Probably on whatever is the * opposite of NETCON_init.... */ @@ -262,7 +262,7 @@ BOOL NETCON_connect(WININET_NETCONNECTION *connection, const struct sockaddr *se result = connect(connection->socketFD, serv_addr, addrlen); if (result == -1) { - close(connection->socketFD); + closesocket(connection->socketFD); connection->socketFD = -1; return FALSE; } diff --git a/include/winsock.h b/include/winsock.h index 7f5c5c3f633..eeb3c345e99 100644 --- a/include/winsock.h +++ b/include/winsock.h @@ -408,11 +408,14 @@ typedef struct WS(fd_set) # endif } WS(fd_set), FD_SET, *PFD_SET, *LPFD_SET; +#ifndef _TIMEVAL_DEFINED +#define _TIMEVAL_DEFINED typedef struct WS(timeval) { long tv_sec; /* seconds */ long tv_usec; /* and microseconds */ } TIMEVAL, *PTIMEVAL, *LPTIMEVAL; +#endif #define WINE_FD_CLR(fd, set, cast) do { \ u_int __i; \