From: Ronnie Sahlberg Date: Tue, 13 Sep 2011 05:10:45 +0000 (+1000) Subject: Merge remote branch 'memphiz/win32' X-Git-Tag: upstream/1.9.6^2~301 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1e1b70a24a025f6102357d1c6293e3064d31ee2a;hp=584108f43e97072c631fdea54ab73a51f195d5c6;p=deb_libnfs.git Merge remote branch 'memphiz/win32' --- diff --git a/README b/README index 79f49eb..001e6b4 100644 --- a/README +++ b/README @@ -45,7 +45,7 @@ MacOSX: - tested with SDK 10.4 (under Snow Leopard) - should also work with late iOS: - tested with iOS SDK 4.2 - running on iOS 4.3.x FreeBSD:- tested with 8.2 OpenSolaris -Windows:- tested on Windows 7 using Visual Studio 10 +Windows:- tested on Windows 7 64 and Windows XP 32 using Visual Studio 10 (see README.win32.txt for build instructions) Cygwin diff --git a/README.win32.txt b/README.win32.txt index 7df1745..298045e 100644 --- a/README.win32.txt +++ b/README.win32.txt @@ -4,8 +4,7 @@ package should work with some effort. 1. checkout git://github.com/Memphiz/oncrpc-win32.git project (branch hyper!) -2. build oncrpc-win32 project (see README.win32 in the projects dir) -3. checkout libnfs (branch win32) -4. adapt oncrpc-win32 path in win32/win32build.bat -4. build libnfs with cd win32;win32build.bat -5. copy lib/libnfs.dll and /win32/bin/liboncrpc.dll to the dir where the executable is... +2. build oncrpc-win32 project (see README.libnfs in the projects dir) +3. checkout libnfs ("parallel" to oncrpc-win32) +4. load vs2010 project from win32/libnfs/libnfs.sln +5. build libnfs and nfsclient-sync diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index c769835..97d5a61 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -47,8 +47,6 @@ #include #endif -#include -#include #include "libnfs.h" #include "libnfs-raw.h" #include "libnfs-raw-mount.h" @@ -716,11 +714,8 @@ static void statvfs_cb(int status, struct nfs_context *nfs, void *data, void *pr nfs_set_error(nfs, "statvfs call failed with \"%s\"", (char *)data); return; } -#ifndef WIN32 + memcpy(cb_data->return_data, data, sizeof(struct statvfs)); -#else - cb_data->return_data=NULL; -#endif/**/ } int nfs_statvfs(struct nfs_context *nfs, const char *path, struct statvfs *svfs) @@ -1189,7 +1184,6 @@ void mount_free_export_list(struct exportnode *exports) -#if !defined(WIN32) void free_nfs_srvr_list(struct nfs_server_list *srv) { while (srv != NULL) { @@ -1260,7 +1254,138 @@ void callit_cb(struct rpc_context *rpc, int status, void *data _U_, void *privat srv_data->srvrs = srvr; } -#ifndef WIN32 +#ifdef WIN32 + +static int send_nfsd_probes(struct rpc_context *rpc, INTERFACE_INFO *InterfaceList, int numIfs, struct nfs_list_data *data) +{ + int i=0; + + for(i = 0; i < numIfs; i++) + { + SOCKADDR *pAddress; + char bcdd[16]; + unsigned long nFlags = 0; + + pAddress = (SOCKADDR *) & (InterfaceList[i].iiBroadcastAddress); + + if(pAddress->sa_family != AF_INET) + continue; + + nFlags = InterfaceList[i].iiFlags; + + if (!(nFlags & IFF_UP)) + { + continue; + } + + if (nFlags & IFF_LOOPBACK) + { + continue; + } + + if (!(nFlags & IFF_BROADCAST)) + { + continue; + } + + if (getnameinfo(pAddress, sizeof(struct sockaddr_in), &bcdd[0], sizeof(bcdd), NULL, 0, NI_NUMERICHOST) < 0) + { + continue; + } + + if (rpc_set_udp_destination(rpc, bcdd, 111, 1) < 0) + { + return -1; + } + + if (rpc_pmap_callit_async(rpc, MOUNT_PROGRAM, 2, 0, NULL, 0, callit_cb, data) < 0) + { + return -1; + } + } + return 0; +} + +struct nfs_server_list *nfs_find_local_servers(void) +{ + struct rpc_context *rpc; + struct nfs_list_data data = {0, NULL}; + struct timeval tv_start, tv_current; + int loop; + struct pollfd pfd; + INTERFACE_INFO InterfaceList[20]; + unsigned long nBytesReturned; + int nNumInterfaces = 0; + + rpc = rpc_init_udp_context(); + if (rpc == NULL) + { + return NULL; + } + + if (rpc_bind_udp(rpc, "0.0.0.0", 0) < 0) + { + rpc_destroy_context(rpc); + return NULL; + } + + if (WSAIoctl(rpc_get_fd(rpc), SIO_GET_INTERFACE_LIST, 0, 0, &InterfaceList, sizeof(InterfaceList), &nBytesReturned, 0, 0) == SOCKET_ERROR) + { + return NULL; + } + + nNumInterfaces = nBytesReturned / sizeof(INTERFACE_INFO); + + for (loop=0; loop<3; loop++) + { + if (send_nfsd_probes(rpc, InterfaceList, nNumInterfaces, &data) != 0) + { + rpc_destroy_context(rpc); + return NULL; + } + + win32_gettimeofday(&tv_start, NULL); + for(;;) + { + int mpt; + + pfd.fd = rpc_get_fd(rpc); + pfd.events = rpc_which_events(rpc); + + win32_gettimeofday(&tv_current, NULL); + mpt = 1000 + - (tv_current.tv_sec *1000 + tv_current.tv_usec / 1000) + + (tv_start.tv_sec *1000 + tv_start.tv_usec / 1000); + + if (poll(&pfd, 1, mpt) < 0) + { + free_nfs_srvr_list(data.srvrs); + rpc_destroy_context(rpc); + return NULL; + } + if (pfd.revents == 0) + { + break; + } + + if (rpc_service(rpc, pfd.revents) < 0) + { + break; + } + } + } + + rpc_destroy_context(rpc); + + if (data.status != 0) + { + free_nfs_srvr_list(data.srvrs); + return NULL; + } + return data.srvrs; +} +#else + static int send_nfsd_probes(struct rpc_context *rpc, struct ifconf *ifc, struct nfs_list_data *data) { char *ptr; @@ -1312,13 +1437,11 @@ static int send_nfsd_probes(struct rpc_context *rpc, struct ifconf *ifc, struct return 0; } -#endif/*WIN32 TODO implement this with win32api FIXME*/ struct nfs_server_list *nfs_find_local_servers(void) { struct rpc_context *rpc; struct nfs_list_data data = {0, NULL}; -#ifndef WIN32 struct timeval tv_start, tv_current; struct ifconf ifc; int size, loop; @@ -1395,7 +1518,6 @@ struct nfs_server_list *nfs_find_local_servers(void) free_nfs_srvr_list(data.srvrs); return NULL; } -#endif/*WIN32 - FIXME redef it when send_nfsd_probes is implemented for win32*/ return data.srvrs; } -#endif +#endif//WIN32 diff --git a/lib/libnfs-win32.def b/lib/libnfs-win32.def index e758a35..f553e71 100644 --- a/lib/libnfs-win32.def +++ b/lib/libnfs-win32.def @@ -3,6 +3,8 @@ EXPORTS mount_free_export_list mount_getexports mount_getexports_async +nfs_find_local_servers +free_nfs_srvr_list nfs_access nfs_access_async nfs_chmod diff --git a/lib/libnfs.c b/lib/libnfs.c index ba7b648..29a276f 100644 --- a/lib/libnfs.c +++ b/lib/libnfs.c @@ -2002,9 +2002,7 @@ static void nfs_statvfs_1_cb(struct rpc_context *rpc _U_, int status, void *comm FSSTAT3res *res; struct nfs_cb_data *data = private_data; struct nfs_context *nfs = data->nfs; -#ifndef WIN32 struct statvfs svfs; -#endif/*WIN32*/ if (status == RPC_STATUS_ERROR) { data->cb(-EFAULT, nfs, command_data, data->private_data); @@ -2025,7 +2023,6 @@ static void nfs_statvfs_1_cb(struct rpc_context *rpc _U_, int status, void *comm return; } -#ifndef WIN32 svfs.f_bsize = 4096; svfs.f_frsize = 4096; svfs.f_blocks = res->FSSTAT3res_u.resok.tbytes/4096; @@ -2039,9 +2036,6 @@ static void nfs_statvfs_1_cb(struct rpc_context *rpc _U_, int status, void *comm svfs.f_namemax = 256; data->cb(0, nfs, &svfs, data->private_data); -#else - data->cb(0, nfs,NULL, data->private_data); -#endif/*WIN32*/ free_nfs_cb_data(data); } @@ -3208,35 +3202,3 @@ const char *nfs_get_export(struct nfs_context *nfs) { return nfs->export; } - -#if defined(WIN32) -int poll(struct pollfd *fds, int nfsd, int timeout) -{ - fd_set rfds, wfds, efds; - int ret; - - FD_ZERO(&rfds); - FD_ZERO(&wfds); - FD_ZERO(&efds); - if (fds->events & POLLIN) { - FD_SET(fds->fd, &rfds); - } - if (fds->events & POLLOUT) { - FD_SET(fds->fd, &wfds); - } - FD_SET(fds->fd, &efds); - select(fds->fd + 1, &rfds, &wfds, &efds, NULL); - fds->revents = 0; - if (FD_ISSET(fds->fd, &rfds)) { - fds->revents |= POLLIN; - } - if (FD_ISSET(fds->fd, &wfds)) { - fds->revents |= POLLOUT; - } - if (FD_ISSET(fds->fd, &efds)) { - fds->revents |= POLLHUP; - } - return 1; -} -#endif - diff --git a/lib/socket.c b/lib/socket.c index 6e162a8..bc101e7 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -25,21 +25,6 @@ #include #endif/*WIN32*/ -#if defined(WIN32) -#include -#include -#include -#define ssize_t SSIZE_T -#define MSG_DONTWAIT 0 -#else -#include -#include -#include -#include -#include -#include -#endif - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -62,6 +47,12 @@ #include "libnfs-private.h" #include "slist.h" +#ifdef WIN32 +//has to be included after stdlib!! +#include "win32_errnowrapper.h" +#endif + + static int rpc_disconnect_requeue(struct rpc_context *rpc); static void set_nonblocking(int fd) @@ -267,7 +258,11 @@ static int rpc_read_from_socket(struct rpc_context *rpc) int rpc_service(struct rpc_context *rpc, int revents) { if (revents & POLLERR) { +#ifdef WIN32 char err = 0; +#else + int err = 0; +#endif socklen_t err_size = sizeof(err); if (getsockopt(rpc->fd, SOL_SOCKET, SO_ERROR, @@ -414,7 +409,7 @@ int rpc_connect_async(struct rpc_context *rpc, const char *server, int port, rpc set_nonblocking(rpc->fd); #if defined(WIN32) - if (connect(rpc->fd, (struct sockaddr *)&s, socksize) == 0 && GetLastError() != WSAEINPROGRESS ) + if (connect(rpc->fd, (struct sockaddr *)&s, socksize) == 0 && errno != EINPROGRESS ) #else if (connect(rpc->fd, (struct sockaddr *)&s, socksize) != 0 && errno != EINPROGRESS) #endif diff --git a/nfs/nfs.c b/nfs/nfs.c index 50836ca..9d8086f 100644 --- a/nfs/nfs.c +++ b/nfs/nfs.c @@ -31,10 +31,6 @@ #include "libnfs-private.h" #include "libnfs-raw-nfs.h" -#ifdef WIN32 -#define bzero(a,b) memset((a),(0),(b)) -#endif/*WIN32*/ - char *nfsstat3_to_str(int error) { switch (error) { diff --git a/nfs/nfsacl.c b/nfs/nfsacl.c index ba1ca12..e48db02 100644 --- a/nfs/nfsacl.c +++ b/nfs/nfsacl.c @@ -20,10 +20,6 @@ #include #endif/*WIN32*/ -#if defined(WIN32) -#include -#endif - #include #include #include diff --git a/portmap/portmap.c b/portmap/portmap.c index 29f13d0..f8c434d 100644 --- a/portmap/portmap.c +++ b/portmap/portmap.c @@ -18,10 +18,6 @@ #include "win32_compat.h" #endif/*WIN32*/ -#if defined(WIN32) -#include -#endif - #include #include #include diff --git a/rquota/rquota.c b/rquota/rquota.c index fa528c2..549f2ff 100644 --- a/rquota/rquota.c +++ b/rquota/rquota.c @@ -18,10 +18,6 @@ #include "win32_compat.h" #endif/*WIN32*/ -#if defined(WIN32) -#include -#endif - #include #include #include diff --git a/win32/libnfs/libnfs.vcxproj b/win32/libnfs/libnfs.vcxproj index fadcd0c..e46c074 100644 --- a/win32/libnfs/libnfs.vcxproj +++ b/win32/libnfs/libnfs.vcxproj @@ -19,13 +19,13 @@ DynamicLibrary true - Unicode + MultiByte DynamicLibrary false true - Unicode + MultiByte @@ -53,7 +53,7 @@ Level3 Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;_U_=;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;_U_=;_USE_32BIT_TIME_T;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions) ..\..\..\oncrpc-win32\win32\include;..\..\include;..\..\.;..\..\win32;..\..\mount;..\..\nfs;..\..\lib Default 4996 @@ -63,6 +63,7 @@ true ..\..\lib\libnfs-win32.def oncrpc.lib;ws2_32.lib;%(AdditionalDependencies) + MSVCRT copy $(ProjectDir)..\..\nfs\nfs.x $(ProjectDir)..\..\nfs\libnfs-raw-nfs.x @@ -90,7 +91,7 @@ rpcgen.exe -c $(ProjectDir)..\..\mount\libnfs-raw-mount.x > $(ProjectDir)..\ MaxSpeed true true - WIN32;NDEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;_U_=;%(PreprocessorDefinitions) + WIN32;NDEBUG;_WINDOWS;_USRDLL;_WIN32_WINNT=0x0501;_U_=;_USE_32BIT_TIME_T;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions) ..\..\..\oncrpc-win32\win32\include;..\..\include;..\..\.;..\..\win32;..\..\mount;..\..\nfs;..\..\lib 4996 diff --git a/win32/win32_compat.c b/win32/win32_compat.c index 65450eb..fe2ca05 100644 --- a/win32/win32_compat.c +++ b/win32/win32_compat.c @@ -29,6 +29,8 @@ static int dummy ATTRIBUTE((unused)); #include "win32_compat.h" #include #include +#include < time.h > + #undef poll #undef socket #undef connect @@ -39,7 +41,6 @@ static int dummy ATTRIBUTE((unused)); #undef inet_aton #undef gettimeofday #undef stat -#define bzero(a,b) memset((a),(0),(b)) #define assert(a) /* Windows needs this header file for the implementation of inet_aton() */ @@ -47,239 +48,154 @@ static int dummy ATTRIBUTE((unused)); int win32_inet_pton(int af, const char * src, void * dst) { - int temp = sizeof(struct sockaddr_in); - int ret = -1; - int len = strlen(src) + 1; - wchar_t *srcNonConst = (wchar_t *)malloc(len); - memset(srcNonConst, 0, len); - MultiByteToWideChar(CP_ACP, NULL, src, -1, srcNonConst, len); - - if( WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)dst,&temp) == 0 ) - { - ret = 1; - } - else - { - if( WSAGetLastError() == WSAEINVAL ) - { - ret = -1; - } - } - //free(srcNonConst); - return ret; -} - -/* - * Check whether "cp" is a valid ascii representation of an Internet address - * and convert to a binary address. Returns 1 if the address is valid, 0 if - * not. This replaces inet_addr, the return value from which cannot - * distinguish between failure and a local broadcast address. - * - * This implementation of the standard inet_aton() function was copied - * (with trivial modifications) from the OpenBSD project. - */ -int -win32_inet_aton(const char *cp, struct in_addr *addr) -{ - register unsigned int val; - register int base, n; - register char c; - unsigned int parts[4]; - register unsigned int *pp = parts; - - assert(sizeof(val) == 4); - - c = *cp; - while(1) { - /* - * Collect number up to ``.''. - * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. - */ - if(!isdigit(c)) - return (0); - val = 0; base = 10; - if(c == '0') { - c = *++cp; - if(c == 'x' || c == 'X') - base = 16, c = *++cp; - else - base = 8; - } - while(1) { - if(isascii(c) && isdigit(c)) { - val = (val * base) + (c - '0'); - c = *++cp; - } else if(base == 16 && isascii(c) && isxdigit(c)) { - val = (val << 4) | - (c + 10 - (islower(c) ? 'a' : 'A')); - c = *++cp; - } else - break; - } - if(c == '.') { - /* - * Internet format: - * a.b.c.d - * a.b.c (with c treated as 16 bits) - * a.b (with b treated as 24 bits) - */ - if(pp >= parts + 3) - return (0); - *pp++ = val; - c = *++cp; - } else - break; - } - /* - * Check for trailing characters. - */ - if(c != '\0' && (!isascii(c) || !isspace(c))) - return (0); - /* - * Concoct the address according to - * the number of parts specified. - */ - n = pp - parts + 1; - switch(n) { - - case 0: - return (0); /* initial nondigit */ - - case 1: /* a -- 32 bits */ - break; - - case 2: /* a.b -- 8.24 bits */ - if((val > 0xffffff) || (parts[0] > 0xff)) - return (0); - val |= parts[0] << 24; - break; - - case 3: /* a.b.c -- 8.8.16 bits */ - if((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16); - break; - - case 4: /* a.b.c.d -- 8.8.8.8 bits */ - if((val > 0xff) || (parts[0] > 0xff) || - (parts[1] > 0xff) || (parts[2] > 0xff)) - return (0); - val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); - break; - } - if(addr) - addr->s_addr = htonl(val); - return (1); -} - -unsigned int -win32_sleep(unsigned int seconds) -{ - Sleep(seconds * 1000); - return 0; -} - -int win32_poll(struct pollfd *fds, int nfsd, int timeout) -{ - fd_set rfds, wfds, efds; - int ret; + struct sockaddr_in sa; + int len = sizeof(SOCKADDR); + int ret = -1; + int strLen = strlen(src) + 1; +#ifdef UNICODE + wchar_t *srcNonConst = (wchar_t *)malloc(strLen*sizeof(wchar_t)); + memset(srcNonConst, 0, strLen); + MultiByteToWideChar(CP_ACP, 0, src, -1, srcNonConst, strLen); +#else + char *srcNonConst = (char *)malloc(strLen); + memset(srcNonConst, 0, strLen); + strncpy(srcNonConst, src, strLen); +#endif - FD_ZERO(&rfds); - FD_ZERO(&wfds); - FD_ZERO(&efds); - if (fds->events & POLLIN) - { - FD_SET(fds->fd, &rfds); - } - if (fds->events & POLLOUT) - { - FD_SET(fds->fd, &wfds); - } - FD_SET(fds->fd, &efds); - ret = select(fds->fd + 1, &rfds, &wfds, &efds, NULL); - fds->revents = 0; - - if (FD_ISSET(fds->fd, &rfds)) - { - fds->revents |= POLLIN; - } - - if (FD_ISSET(fds->fd, &wfds)) + if( WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)&sa,&len) == 0 ) { - fds->revents |= POLLOUT; + ret = 1; } - - if (FD_ISSET(fds->fd, &efds)) + else { - fds->revents |= POLLHUP; + if( WSAGetLastError() == WSAEINVAL ) + { + ret = -1; + } } + free(srcNonConst); + memcpy(dst, &sa.sin_addr, sizeof(struct in_addr)); return ret; } -/*int win32_poll(struct pollfd *fds, unsigned int nfds, int timo) +int win32_poll(struct pollfd *fds, unsigned int nfds, int timo) { - struct timeval timeout, *toptr; - fd_set ifds, ofds, efds, *ip, *op; - int i, rc; - - // Set up the file-descriptor sets in ifds, ofds and efds. - FD_ZERO(&ifds); - FD_ZERO(&ofds); - FD_ZERO(&efds); - for (i = 0, op = ip = 0; i < nfds; ++i) { - fds[i].revents = 0; - if(fds[i].events & (POLLIN|POLLPRI)) { - ip = &ifds; - FD_SET(fds[i].fd, ip); - } - if(fds[i].events & POLLOUT) { - op = &ofds; - FD_SET(fds[i].fd, op); - } - FD_SET(fds[i].fd, &efds); - } - - // Set up the timeval structure for the timeout parameter - if(timo < 0) { - toptr = 0; - } else { - toptr = &timeout; - timeout.tv_sec = timo / 1000; - timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; + struct timeval timeout, *toptr; + fd_set ifds, ofds, efds, *ip, *op; + unsigned int i; + int rc; + + // Set up the file-descriptor sets in ifds, ofds and efds. + FD_ZERO(&ifds); + FD_ZERO(&ofds); + FD_ZERO(&efds); + for (i = 0, op = ip = 0; i < nfds; ++i) + { + fds[i].revents = 0; + if(fds[i].events & (POLLIN|POLLPRI)) + { + ip = &ifds; + FD_SET(fds[i].fd, ip); + } + if(fds[i].events & POLLOUT) + { + op = &ofds; + FD_SET(fds[i].fd, op); } + FD_SET(fds[i].fd, &efds); + } + + // Set up the timeval structure for the timeout parameter + if(timo < 0) + { + toptr = 0; + } + else + { + toptr = &timeout; + timeout.tv_sec = timo / 1000; + timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000; + } #ifdef DEBUG_POLL - printf("Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n", - (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, (long)op); + printf("Entering select() sec=%ld usec=%ld ip=%lx op=%lx\n", + (long)timeout.tv_sec, (long)timeout.tv_usec, (long)ip, (long)op); #endif - rc = select(0, ip, op, &efds, toptr); + rc = select(0, ip, op, &efds, toptr); #ifdef DEBUG_POLL - printf("Exiting select rc=%d\n", rc); + printf("Exiting select rc=%d\n", rc); #endif - if(rc <= 0) - return rc; + if(rc <= 0) + return rc; - if(rc > 0) { - for (i = 0; i < nfds; ++i) { - int fd = fds[i].fd; - if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) - fds[i].revents |= POLLIN; - if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds)) - fds[i].revents |= POLLOUT; - if(FD_ISSET(fd, &efds)) - // Some error was detected ... should be some way to know. - fds[i].revents |= POLLHUP; + if(rc > 0) + { + for (i = 0; i < nfds; ++i) + { + int fd = fds[i].fd; + if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds)) + fds[i].revents |= POLLIN; + if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds)) + fds[i].revents |= POLLOUT; + if(FD_ISSET(fd, &efds)) // Some error was detected ... should be some way to know. + fds[i].revents |= POLLHUP; #ifdef DEBUG_POLL - printf("%d %d %d revent = %x\n", - FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds), - fds[i].revents - ); + printf("%d %d %d revent = %x\n", + FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds), + fds[i].revents + ); #endif - } } - return rc; + } + return rc; } -*/ + +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) + #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +#else + #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +#endif + +struct timezone +{ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; + +int win32_gettimeofday(struct timeval *tv, struct timezone *tz) +{ + FILETIME ft; + unsigned __int64 tmpres = 0; + static int tzflag; + + if (NULL != tv) + { + GetSystemTimeAsFileTime(&ft); + + tmpres |= ft.dwHighDateTime; + tmpres <<= 32; + tmpres |= ft.dwLowDateTime; + + /*converting file time to unix epoch*/ + tmpres -= DELTA_EPOCH_IN_MICROSECS; + tmpres /= 10; /*convert into microseconds*/ + tv->tv_sec = (long)(tmpres / 1000000UL); + tv->tv_usec = (long)(tmpres % 1000000UL); + } + + if (NULL != tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; +} + #endif diff --git a/win32/win32_compat.h b/win32/win32_compat.h index 2ddb0ff..9972e5d 100644 --- a/win32/win32_compat.h +++ b/win32/win32_compat.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include #include +#include #include #include #include @@ -37,7 +38,6 @@ typedef int uid_t; typedef int gid_t; typedef int socklen_t; - #define S_IRUSR 0000400 #define S_IWUSR 0000200 #define S_IXUSR 0000100 @@ -74,11 +74,10 @@ struct pollfd { /* Wrapper macros to call misc. functions win32 is missing */ #define poll(x, y, z) win32_poll(x, y, z) -#define inet_aton(x, y) win32_inet_aton(x, y) #define inet_pton(x,y,z) win32_inet_pton(x,y,z) -int win32_inet_aton(const char *, struct in_addr *); int win32_inet_pton(int af, const char * src, void * dst); -int win32_poll(struct pollfd *fds, int nfsd, int timeout); +int win32_poll(struct pollfd *fds, unsigned int nfsd, int timeout); +int win32_gettimeofday(struct timeval *tv, struct timezone *tz); #endif//win32_COMPAT_H_ #endif//WIN32 diff --git a/win32/win32_errnowrapper.h b/win32/win32_errnowrapper.h new file mode 100644 index 0000000..4477d3f --- /dev/null +++ b/win32/win32_errnowrapper.h @@ -0,0 +1,15 @@ +#ifndef WIN32_ERRNOWRAPPER_H_ +#define WIN32_ERRNOWRAPPER_H_ + +#undef errno +#define errno WSAGetLastError() +#undef EAGAIN +#undef EWOULDBLOCK +#undef EINTR +#undef EINPROGRESS + +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EAGAIN WSAEWOULDBLOCK //same on windows +#define EINTR WSAEINTR +#define EINPROGRESS WSAEINPROGRESS +#endif //WIN32_ERRNOWRAPPER_H_