root / trunk / src / dot / proxy / mingw.h
| Revision 7618, 5.4 kB (checked in by BradNeuberg, 22 months ago) |
|---|
| Line | |
|---|---|
| 1 | /* |
| 2 | Copyright (c) 2006 by Dan Kennedy. |
| 3 | Copyright (c) 2006 by Juliusz Chroboczek. |
| 4 | |
| 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | of this software and associated documentation files (the "Software"), to deal |
| 7 | in the Software without restriction, including without limitation the rights |
| 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | copies of the Software, and to permit persons to whom the Software is |
| 10 | furnished to do so, subject to the following conditions: |
| 11 | |
| 12 | The above copyright notice and this permission notice shall be included in |
| 13 | all copies or substantial portions of the Software. |
| 14 | |
| 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 21 | THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * Polipo was originally designed to run on Unix-like systems. This |
| 26 | * header file (and it's accompanying implementation file mingw.c) contain |
| 27 | * code that allows polipo to run on Microsoft Windows too. |
| 28 | * |
| 29 | * The target MS windows compiler is Mingw (MINimal Gnu for Windows). The |
| 30 | * code in this file probably get's us pretty close to MSVC also, but |
| 31 | * this has not been tested. To build polipo for Mingw, define the MINGW |
| 32 | * symbol. For Unix or Unix-like systems, leave it undefined. |
| 33 | */ |
| 34 | |
| 35 | #ifdef MINGW |
| 36 | |
| 37 | /* Unfortunately, there's no hiding it. */ |
| 38 | #define HAVE_WINSOCK 1 |
| 39 | |
| 40 | /* At time of writing, a fair bit of stuff doesn't work under Mingw. |
| 41 | * Hopefully they will be fixed later (especially the disk-cache). |
| 42 | */ |
| 43 | #define NO_IPv6 1 |
| 44 | |
| 45 | #include <io.h> |
| 46 | |
| 47 | #define S_IROTH S_IREAD |
| 48 | |
| 49 | /* Pull in winsock.h for (almost) berkeley sockets. */ |
| 50 | #include <winsock.h> |
| 51 | #define ENOTCONN WSAENOTCONN |
| 52 | #define EWOULDBLOCK WSAEWOULDBLOCK |
| 53 | #define ENOBUFS WSAENOBUFS |
| 54 | #define ECONNRESET WSAECONNRESET |
| 55 | #define ESHUTDOWN WSAESHUTDOWN |
| 56 | #define EAFNOSUPPORT WSAEAFNOSUPPORT |
| 57 | #define EPROTONOSUPPORT WSAEPROTONOSUPPORT |
| 58 | #define EINPROGRESS WSAEINPROGRESS |
| 59 | #define EISCONN WSAEISCONN |
| 60 | |
| 61 | /* winsock doesn't feature poll(), so there is a version implemented |
| 62 | * in terms of select() in mingw.c. The following definitions |
| 63 | * are copied from linux man pages. A poll() macro is defined to |
| 64 | * call the version in mingw.c. |
| 65 | */ |
| 66 | #define POLLIN 0x0001 /* There is data to read */ |
| 67 | #define POLLPRI 0x0002 /* There is urgent data to read */ |
| 68 | #define POLLOUT 0x0004 /* Writing now will not block */ |
| 69 | #define POLLERR 0x0008 /* Error condition */ |
| 70 | #define POLLHUP 0x0010 /* Hung up */ |
| 71 | #define POLLNVAL 0x0020 /* Invalid request: fd not open */ |
| 72 | struct pollfd { |
| 73 | SOCKET fd; /* file descriptor */ |
| 74 | short events; /* requested events */ |
| 75 | short revents; /* returned events */ |
| 76 | }; |
| 77 | #define poll(x, y, z) mingw_poll(x, y, z) |
| 78 | |
| 79 | /* These wrappers do nothing special except set the global errno variable if |
| 80 | * an error occurs (winsock doesn't do this by default). They set errno |
| 81 | * to unix-like values (i.e. WSAEWOULDBLOCK is mapped to EAGAIN), so code |
| 82 | * outside of this file "shouldn't" have to worry about winsock specific error |
| 83 | * handling. |
| 84 | */ |
| 85 | #define socket(x, y, z) mingw_socket(x, y, z) |
| 86 | #define connect(x, y, z) mingw_connect(x, y, z) |
| 87 | #define accept(x, y, z) mingw_accept(x, y, z) |
| 88 | #define shutdown(x, y) mingw_shutdown(x, y) |
| 89 | #define getpeername(x, y, z) mingw_getpeername(x, y, z) |
| 90 | |
| 91 | /* Wrapper macros to call misc. functions mingw is missing */ |
| 92 | #define sleep(x) mingw_sleep(x) |
| 93 | #define inet_aton(x, y) mingw_inet_aton(x, y) |
| 94 | #define gettimeofday(x, y) mingw_gettimeofday(x, y) |
| 95 | #define stat(x, y) mingw_stat(x, y) |
| 96 | |
| 97 | #define mkdir(x, y) mkdir(x) |
| 98 | |
| 99 | /* Winsock uses int instead of the usual socklen_t */ |
| 100 | typedef int socklen_t; |
| 101 | |
| 102 | /* Function prototypes for functions in mingw.c */ |
| 103 | unsigned int mingw_sleep(unsigned int); |
| 104 | int mingw_inet_aton(const char *, struct in_addr *); |
| 105 | int mingw_gettimeofday(struct timeval *, char *); |
| 106 | int mingw_poll(struct pollfd *, unsigned int, int); |
| 107 | SOCKET mingw_socket(int, int, int); |
| 108 | int mingw_connect(SOCKET, struct sockaddr*, socklen_t); |
| 109 | SOCKET mingw_accept(SOCKET, struct sockaddr*, socklen_t *); |
| 110 | int mingw_shutdown(SOCKET, int); |
| 111 | int mingw_getpeername(SOCKET, struct sockaddr*, socklen_t *); |
| 112 | |
| 113 | /* Three socket specific macros */ |
| 114 | #define READ(x, y, z) mingw_read_socket(x, y, z) |
| 115 | #define WRITE(x, y, z) mingw_write_socket(x, y, z) |
| 116 | #define CLOSE(x) mingw_close_socket(x) |
| 117 | |
| 118 | int mingw_read_socket(SOCKET, void *, int); |
| 119 | int mingw_write_socket(SOCKET, void *, int); |
| 120 | int mingw_close_socket(SOCKET); |
| 121 | |
| 122 | int mingw_setnonblocking(SOCKET, int); |
| 123 | int mingw_stat(const char*, struct stat*); |
| 124 | #endif |
| 125 | |
| 126 | #ifndef HAVE_READV_WRITEV |
| 127 | /* |
| 128 | * The HAVE_READV_WRITEV symbol should be defined if the system features |
| 129 | * the vector IO functions readv() and writev() and those functions may |
| 130 | * be legally used with sockets. |
| 131 | */ |
| 132 | struct iovec { |
| 133 | void *iov_base; /* Starting address */ |
| 134 | size_t iov_len; /* Number of bytes */ |
| 135 | }; |
| 136 | #define WRITEV(x, y, z) polipo_writev(x, y, z) |
| 137 | #define READV(x, y, z) polipo_readv(x, y, z) |
| 138 | int polipo_readv(int fd, const struct iovec *vector, int count); |
| 139 | int polipo_writev(int fd, const struct iovec *vector, int count); |
| 140 | #endif |
Note: See TracBrowser
for help on using the browser.