X-Git-Url: http://git.meshlink.io/?p=catta;a=blobdiff_plain;f=src%2Fcompat%2Fwindows%2Fwincompat.h;h=f611e33e581534346e81022dafb3f83759c87084;hp=6510183a870b86f95644cd6b7c64ce9bfdff9f19;hb=dd315fb0f7a90a6f154cbea0e7a7c64b550164b9;hpb=f8ac9afd843c50ab15d7645d6479f65e0ec562cc diff --git a/src/compat/windows/wincompat.h b/src/compat/windows/wincompat.h index 6510183..f611e33 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. @@ -69,6 +78,32 @@ static inline struct cmsghdr *CMSG_NXTHDR(struct msghdr *m, struct cmsghdr *c) { ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); +// ESHUTDOWN does not seem to exist on Windows, even though WSAESHUTDOWN does. +// MingW doesn't define it and MSDN doesn't list it, so we alias it to EBADF. +// cf. http://msdn.microsoft.com/en-us/library/5814770t.aspx +#ifndef ESHUTDOWN +#define ESHUTDOWN EBADF +#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.