root / trunk / src / dot / proxy / mingw.h

Revision 7618, 5.4 kB (checked in by BradNeuberg, 22 months ago)

Local and remote SVN repositories somehow became out of sync and corrupted -- re-adding these in

Line 
1/*
2Copyright (c) 2006 by Dan Kennedy.
3Copyright (c) 2006 by Juliusz Chroboczek.
4
5Permission is hereby granted, free of charge, to any person obtaining a copy
6of this software and associated documentation files (the "Software"), to deal
7in the Software without restriction, including without limitation the rights
8to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9copies of the Software, and to permit persons to whom the Software is
10furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21THE 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 */
72struct 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 */
100typedef int socklen_t;
101
102/* Function prototypes for functions in mingw.c */
103unsigned int mingw_sleep(unsigned int);
104int     mingw_inet_aton(const char *, struct in_addr *);
105int     mingw_gettimeofday(struct timeval *, char *);
106int     mingw_poll(struct pollfd *, unsigned int, int);
107SOCKET  mingw_socket(int, int, int);
108int     mingw_connect(SOCKET, struct sockaddr*, socklen_t);
109SOCKET  mingw_accept(SOCKET, struct sockaddr*, socklen_t *);
110int     mingw_shutdown(SOCKET, int);
111int     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
118int mingw_read_socket(SOCKET, void *, int);
119int mingw_write_socket(SOCKET, void *, int);
120int mingw_close_socket(SOCKET);
121
122int mingw_setnonblocking(SOCKET, int);
123int 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 */
132struct 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)
138int polipo_readv(int fd, const struct iovec *vector, int count);
139int polipo_writev(int fd, const struct iovec *vector, int count);
140#endif
Note: See TracBrowser for help on using the browser.