X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fcompat%2Fwindows%2Fwincompat.h;h=ac151c9ecf7bca078e185e41793db801234bd48f;hb=5f77c7c2c4e2013e75cc39de4de32eddd3227d33;hp=8f62240c68be2e3cc9f9c57bfc1b98f283d503a2;hpb=4ac8d5e93bf09c86e8352cdc2099b35ec89ba3a9;p=catta diff --git a/src/compat/windows/wincompat.h b/src/compat/windows/wincompat.h index 8f62240..ac151c9 100644 --- a/src/compat/windows/wincompat.h +++ b/src/compat/windows/wincompat.h @@ -14,6 +14,7 @@ #include #include #include +#include // wrappers around WSAStartup/WSACleanup to avoid clutter @@ -47,34 +48,67 @@ struct msghdr { // MSDN says this struct is called wsacmsghdr but MingW uses _WSACMSGHDR. // TODO: Verify what it is on actual Windows. // cf. http://msdn.microsoft.com/en-us/library/ms741645(v=vs.85).aspx +// --> +// MingW32 x86 4.8.1 uses wsacmsghdr, MingW x86_x64 uses _WSACMSGHDR and Visual Studio 2015 RC (ws2def.h) defines: +// #if(_WIN32_WINNT >= 0x0600) +// #define _WSACMSGHDR cmsghdr +// #endif //(_WIN32_WINNT>=0x0600) +// typedef struct _WSACMSGHDR { +// SIZE_T cmsg_len; +// INT cmsg_level; +// INT cmsg_type; +// /* followed by UCHAR cmsg_data[] */ +// } WSACMSGHDR, *PWSACMSGHDR, FAR *LPWSACMSGHDR; #ifdef __MINGW32__ -#define cmsghdr _WSACMSGHDR // as in 'struct cmsghdr' -#else -#define cmsghdr wsacmsghdr // as in 'struct cmsghdr' + #ifdef __MINGW64_VERSION_MAJOR + #define cmsghdr _WSACMSGHDR // as in 'struct cmsghdr' + #else + #define cmsghdr wsacmsghdr // as in 'struct cmsghdr' + #endif +#elif (_WIN32_WINNT < 0x0600) + #define cmsghdr _WSACMSGHDR #endif +// VS2015 ws2def.h already defines: #define CMSG_FIRSTHDR WSA_CMSG_FIRSTHDR +#ifdef CMSG_FIRSTHDR +#undef CMSG_FIRSTHDR +#endif static inline struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *m) { WSAMSG wm; wm.Control.len = m->msg_controllen; - wm.Control.buf = m->msg_control; + wm.Control.buf = (char*)m->msg_control; return WSA_CMSG_FIRSTHDR(&wm); } +// VS2015 ws2def.h already defines: #define CMSG_NXTHDR WSA_CMSG_NXTHDR +#ifdef CMSG_NXTHDR +#undef CMSG_NXTHDR +#endif static inline struct cmsghdr *CMSG_NXTHDR(struct msghdr *m, struct cmsghdr *c) { WSAMSG wm; wm.Control.len = m->msg_controllen; - wm.Control.buf = m->msg_control; + wm.Control.buf = (char*)m->msg_control; return WSA_CMSG_NXTHDR(&wm, c); } -#define CMSG_SPACE(len) WSA_CMSG_SPACE(len) -#define CMSG_LEN(len) WSA_CMSG_LEN(len) +#ifndef CMSG_SPACE + #define CMSG_SPACE(len) WSA_CMSG_SPACE(len) +#endif +#ifndef CMSG_LEN + #define CMSG_LEN(len) WSA_CMSG_LEN(len) +#endif // we're going to be naughty and redefine CMSG_DATA as an alias even though it // is also a constant defined in wincrypt.h which we don't care about. #undef CMSG_DATA #define CMSG_DATA(c) WSA_CMSG_DATA(c) +// VS2012 and up has no ssize_t defined, before it was defined as unsigned int +#ifndef _SSIZE_T +#define _SSIZE_T +typedef signed int ssize_t; +#endif + ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); @@ -99,6 +133,11 @@ int ioctl(int d, unsigned long request, int *p); // something to give to WSAPoll, so we fake it with a local TCP socket. (ugh) int pipe(int pipefd[2]); +// pipe(socket)-specific read/write/close equivalents +#define closepipe closesocket +#define writepipe(s,buf,len) send(s, buf, len, 0) +#define readpipe(s,buf,len) recv(s, buf, len, 0) + // Windows logically doesn't have uname, so we supply a replacement.