X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fcompat%2Fwindows%2Fwincompat.h;h=7fe21f4a8bf410a9ab459a193f8a548c218157f0;hb=a71541c2252bd51fb5f02480d8aa902efcf3e858;hp=f76dbc4835a1012160d863060f2928dda145ce82;hpb=473963ea000bfe23a0d4754988223e4e6e2fb3f2;p=catta diff --git a/src/compat/windows/wincompat.h b/src/compat/windows/wincompat.h index f76dbc4..7fe21f4 100644 --- a/src/compat/windows/wincompat.h +++ b/src/compat/windows/wincompat.h @@ -16,6 +16,15 @@ #include +// wrappers around WSAStartup/WSACleanup to avoid clutter +void winsock_init(void); +void winsock_exit(void); + + +// the equivalent of strerror(errno) for Windows sockets +char *errnostrsocket(void); + + // Winsock doesn't have recvmsg/sendmsg but offers the same functionality // with WSARecvMsg/WSASendMsg, so we implement the former in terms of the // latter. @@ -47,14 +56,14 @@ struct msghdr { 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); } 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); } @@ -77,6 +86,25 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); #endif +// Windows doesn't have ioctl but offers ioctlsocket for some socket-related +// functions. Unfortunately, argument types differ, so we implement a +// (restricted) wrapper. +int ioctl(int d, unsigned long request, int *p); + + +// Windows lacks poll, but WSAPoll is good enough for us. +#define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout) + +// Windows lacks pipe. It has an equivalent CreatePipe but we really need +// 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. struct utsname {