| 1 | /* |
|---|
| 2 | Copyright (C) 2008-2010 Tomash Brechko. All rights reserved. |
|---|
| 3 | |
|---|
| 4 | When used to build Perl module: |
|---|
| 5 | |
|---|
| 6 | This library is free software; you can redistribute it and/or modify |
|---|
| 7 | it under the same terms as Perl itself, either Perl version 5.8.8 |
|---|
| 8 | or, at your option, any later version of Perl 5 you may have |
|---|
| 9 | available. |
|---|
| 10 | |
|---|
| 11 | When used as a standalone library: |
|---|
| 12 | |
|---|
| 13 | This library is free software; you can redistribute it and/or modify |
|---|
| 14 | it under the terms of the GNU Lesser General Public License as |
|---|
| 15 | published by the Free Software Foundation; either version 2.1 of the |
|---|
| 16 | License, or (at your option) any later version. |
|---|
| 17 | |
|---|
| 18 | This library is distributed in the hope that it will be useful, but |
|---|
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 21 | Lesser General Public License for more details. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | #ifndef SOCKET_WIN32_H |
|---|
| 25 | #define SOCKET_WIN32_H 1 |
|---|
| 26 | |
|---|
| 27 | #include <winsock2.h> |
|---|
| 28 | #include <ws2tcpip.h> |
|---|
| 29 | #include <sys/types.h> |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | #define get_iov_max() 64 |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | #if _WIN32_WINNT >= 0x0501 |
|---|
| 36 | |
|---|
| 37 | #include <wspiapi.h> |
|---|
| 38 | |
|---|
| 39 | #else /* ! (_WIN32_WINNT >= 0x0501) */ |
|---|
| 40 | |
|---|
| 41 | #include "addrinfo_hostent.h" |
|---|
| 42 | |
|---|
| 43 | #endif /* ! (_WIN32_WINNT >= 0x0501) */ |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | #if _WIN32_WINNT >= 0x0600 |
|---|
| 47 | |
|---|
| 48 | #define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout) |
|---|
| 49 | |
|---|
| 50 | #else /* ! (_WIN32_WINNT >= 0x0600) */ |
|---|
| 51 | |
|---|
| 52 | #include "poll_select.h" |
|---|
| 53 | |
|---|
| 54 | #define poll(fds, nfds, timeout) poll_select(fds, nfds, timeout) |
|---|
| 55 | |
|---|
| 56 | #endif /* ! (_WIN32_WINNT >= 0x0600) */ |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | /* |
|---|
| 60 | On Win32 FD_SETSIZE is not the limit on the max fd value, but |
|---|
| 61 | instead the limit on the total number of fds that select() can |
|---|
| 62 | handle. So can_poll_fd() should return 1 in any case, any fd is |
|---|
| 63 | select()'able or WSAPoll()'able. By default FD_SETSIZE is 64. If |
|---|
| 64 | you plan to use more memcached servers, you may redefine it to a |
|---|
| 65 | larger value before including <winsock2.h>. |
|---|
| 66 | */ |
|---|
| 67 | #define can_poll_fd(fd) 1 |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | #undef errno |
|---|
| 71 | #define errno WSAGetLastError() |
|---|
| 72 | |
|---|
| 73 | #undef EINTR |
|---|
| 74 | #define EINTR WSAEINTR |
|---|
| 75 | #undef EWOULDBLOCK |
|---|
| 76 | #define EWOULDBLOCK WSAEWOULDBLOCK |
|---|
| 77 | #undef EAGAIN |
|---|
| 78 | #define EAGAIN WSAEWOULDBLOCK |
|---|
| 79 | #undef EINPROGRESS |
|---|
| 80 | #define EINPROGRESS WSAEINPROGRESS |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | #define connect_unix(path, path_len) -1 |
|---|
| 84 | |
|---|
| 85 | #define connect(fd, addr, addrlen) win32_connect(fd, addr, addrlen) |
|---|
| 86 | |
|---|
| 87 | #define read(fd, buf, size) recv(fd, buf, size, 0) |
|---|
| 88 | |
|---|
| 89 | #define close(fd) closesocket(fd) |
|---|
| 90 | |
|---|
| 91 | #define win32_socket_library_release WSACleanup |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | extern |
|---|
| 95 | int |
|---|
| 96 | win32_socket_library_acquire(); |
|---|
| 97 | |
|---|
| 98 | extern |
|---|
| 99 | int |
|---|
| 100 | set_nonblock(SOCKET fd); |
|---|
| 101 | |
|---|
| 102 | extern |
|---|
| 103 | int |
|---|
| 104 | win32_connect(SOCKET fd, const struct sockaddr *addr, int addrlen); |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | /* Define struct iovec the same way as WSABUF is defined. */ |
|---|
| 108 | struct iovec |
|---|
| 109 | { |
|---|
| 110 | u_long iov_len; |
|---|
| 111 | char FAR *iov_base; |
|---|
| 112 | }; |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | extern |
|---|
| 116 | ssize_t |
|---|
| 117 | readv(SOCKET fd, const struct iovec *iov, int iovcnt); |
|---|
| 118 | |
|---|
| 119 | extern |
|---|
| 120 | ssize_t |
|---|
| 121 | writev(SOCKET fd, const struct iovec *iov, int iovcnt); |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | #endif /* ! SOCKET_WIN32_H */ |
|---|