sb-bsd-sockets: Implement NON-BLOCKING-MODE on Windows
[sbcl.git] / contrib / sb-bsd-sockets / win32-constants.lisp
1 ;;; -*- Lisp -*-
2
3 ;;; This isn't really lisp, but it's definitely a source file.  we
4 ;;; name it thus to avoid having to mess with the clc lpn translations
5
6 ;;; first, the headers necessary to find definitions of everything
7 ("winsock2.h")
8
9 ;;; then the stuff we're looking for
10 ((:integer af-inet "AF_INET" "IP Protocol family")
11  (:integer af-unspec "AF_UNSPEC" "Unspecified")
12  (:integer sock-stream "SOCK_STREAM"
13            "Sequenced, reliable, connection-based byte streams.")
14  (:integer sock-dgram "SOCK_DGRAM"
15            "Connectionless, unreliable datagrams of fixed maximum length.")
16  (:integer sock-raw "SOCK_RAW"
17            "Raw protocol interface.")
18  (:integer sock-rdm "SOCK_RDM"
19            "Reliably-delivered messages.")
20  (:integer sock-seqpacket "SOCK_SEQPACKET"
21            "Sequenced, reliable, connection-based, datagrams of fixed maximum length.")
22
23  (:integer sol-socket "SOL_SOCKET")
24
25  ;; some of these may be linux-specific
26  (:integer so-debug "SO_DEBUG"
27    "Enable debugging in underlying protocol modules")
28  (:integer so-reuseaddr "SO_REUSEADDR" "Enable local address reuse")
29  (:integer so-type "SO_TYPE")                  ;get only
30  (:integer so-error "SO_ERROR")                 ;get only (also clears)
31  (:integer so-dontroute "SO_DONTROUTE"
32            "Bypass routing facilities: instead send direct to appropriate network interface for the network portion of the destination address")
33  (:integer so-broadcast "SO_BROADCAST" "Request permission to send broadcast datagrams")
34  (:integer so-sndbuf "SO_SNDBUF")
35  (:integer so-rcvbuf "SO_RCVBUF")
36  (:integer so-keepalive "SO_KEEPALIVE"
37            "Send periodic keepalives: if peer does not respond, we get SIGPIPE")
38  (:integer so-oobinline "SO_OOBINLINE"
39            "Put out-of-band data into the normal input queue when received")
40  (:integer so-linger "SO_LINGER"
41            "For reliable streams, pause a while on closing when unsent messages are queued")
42  (:integer so-sndlowat "SO_SNDLOWAT")
43  (:integer so-rcvlowat "SO_RCVLOWAT")
44  (:integer so-sndtimeo "SO_SNDTIMEO")
45  (:integer so-rcvtimeo "SO_RCVTIMEO")
46
47  (:integer tcp-nodelay "TCP_NODELAY")
48
49  (:integer HOST-NOT-FOUND "HOST_NOT_FOUND" "Authoritative Answer Host not found.")
50  (:integer TRY-AGAIN "TRY_AGAIN" "Non-Authoritative Host not found, or SERVERFAIL.")
51  (:integer NO-RECOVERY "NO_RECOVERY" "Non recoverable errors, FORMERR, REFUSED, NOTIMP.")
52  (:integer NO-DATA "NO_DATA" "Valid name, no data record of requested type.")
53  (:integer NO-ADDRESS "NO_ADDRESS" "No address, look for MX record.")
54
55  (:integer msg-oob "MSG_OOB")
56  (:integer msg-peek "MSG_PEEK")
57  (:integer msg-dontroute "MSG_DONTROUTE")
58
59
60  (:integer EADDRINUSE "WSAEADDRINUSE")
61  (:integer EAGAIN "WSAEWOULDBLOCK")
62  (:integer EBADF "WSAEBADF")
63  (:integer ECONNREFUSED "WSAECONNREFUSED")
64  (:integer ETIMEDOUT "WSAETIMEDOUT")
65  (:integer EINTR "WSAEINTR")
66  (:integer EINVAL "WSAEINVAL")
67  (:integer ENOBUFS "WSAENOBUFS")
68  (:integer ENOMEM "WSAENOBUFS")
69  (:integer EOPNOTSUPP "WSAEOPNOTSUPP")
70  (:integer EPERM "WSAENETDOWN")
71  (:integer EPROTONOSUPPORT "WSAEPROTONOSUPPORT")
72  (:integer ESOCKTNOSUPPORT "WSAESOCKTNOSUPPORT")
73  (:integer ENETUNREACH "WSAENETUNREACH")
74  (:integer ENOTCONN "WSAENOTCONN")
75  (:integer inaddr-any "INADDR_ANY")
76  (:integer FIONBIO "FIONBIO")
77
78
79  ;; for socket-receive
80  (:type socklen-t "int")
81  (:type size-t "size_t")
82  (:type ssize-t "ssize_t")
83
84  (:structure in-addr ("struct in_addr"
85                       ((array (unsigned 8)) addr "u_int32_t" "s_addr")))
86
87  (:structure sockaddr-in ("struct sockaddr_in"
88                           (integer family "sa_family_t" "sin_family")
89                           ;; These two could be in-port-t and
90                           ;; in-addr-t, but then we'd throw away the
91                           ;; convenience (and byte-order agnosticism)
92                           ;; of the old sb-grovel scheme.
93                           ((array (unsigned 8)) port "u_int16_t" "sin_port")
94                           ((array (unsigned 8)) addr "struct in_addr" "sin_addr")))
95
96  (:structure hostent ("struct hostent"
97                       (c-string-pointer name "char *" "h_name")
98                       ((* c-string) aliases "char **" "h_aliases")
99                       (integer type "int" "h_addrtype")
100                       (integer length "int" "h_length")
101                       ((* (* (unsigned 8))) addresses "char **" "h_addr_list")))
102
103  (:structure protoent ("struct protoent"
104                        (c-string-pointer name "char *" "p_name")
105                        ((* (* t)) aliases "char **" "p_aliases")
106                        (integer proto "int" "p_proto")))
107
108  (:function getprotobyname ("getprotobyname" (* protoent)
109                                              (name c-string)))
110
111  (:function getprotobynumber ("getprotobynumber" (* protoent)
112                                                  (proto int)))
113
114  (:function win32-bind
115             ("bind" int
116              (sockfd int)
117              (my-addr (* t))  ; KLUDGE: sockaddr-in or sockaddr-un?
118              (addrlen socklen-t)))
119
120  (:function win32-listen ("listen" int
121                     (socket int)
122                     (backlog int)))
123
124  (:function win32-accept ("accept" int
125                     (socket int)
126                     (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
127                     (addrlen int :in-out)))
128
129  (:function win32-getpeername ("getpeername" int
130                          (socket int)
131                          (her-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
132                          (addrlen socklen-t :in-out)))
133
134  (:function win32-getsockname ("getsockname" int
135                          (socket int)
136                          (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
137                          (addrlen socklen-t :in-out)))
138
139  (:function win32-connect ("connect" int
140                            (socket int)
141                            (his-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
142                            (addrlen socklen-t)))
143
144  (:function win32-close ("closesocket" int
145                          (fd int)))
146
147  (:function win32-recvfrom ("recvfrom" ssize-t
148                             (socket int)
149                             (buf (* t))
150                             (len integer)
151                             (flags int)
152                             (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
153                             (socklen (* socklen-t))))
154
155  (:function win32-recv ("recv" int
156                         (socket int)
157                         (buf (* t))
158                         (len integer)
159                         (flags integer)))
160
161  (:function win32-send ("send" ssize-t
162                         (socket int)
163                         (buf (* t))
164                         (len size-t)
165                         (flags int)))
166
167  (:function win32-sendto ("sendto" int
168                           (socket int)
169                           (buf (* t))
170                           (len size-t)
171                           (flags int)
172                           (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
173                           (socklen socklen-t)))
174
175  (:function gethostbyname ("gethostbyname" (* hostent) (name c-string)))
176
177  (:function gethostbyaddr ("gethostbyaddr" (* hostent)
178                                            (addr (* t))
179                                            (len int)
180                                            (af int)))
181
182 ;;; should be using getaddrinfo instead?
183
184  (:function win32-setsockopt ("setsockopt" int
185                         (socket int)
186                         (level int)
187                         (optname int)
188                         (optval (* t))
189                         (optlen int))) ;;; should be socklen-t!
190
191  (:function win32-getsockopt ("getsockopt" int
192                         (socket int)
193                         (level int)
194                         (optname int)
195                         (optval (* t))
196                         (optlen int :in-out))) ;;; should be socklen-t!
197
198  (:function win32-ioctl ("ioctlsocket"  int
199                          (socket int)
200                          (cmd int)
201                          (argp (unsigned 32) :in-out)))
202
203
204 ;;; Win32 specific cruft
205  (:function wsa-socket ("WSASocketA" int
206                         (af int)
207                         (type int)
208                         (protocol int)
209                         (lpProtocolInfo (* t))
210                         (g int)
211                         (flags int)))
212
213  (:function fd->handle ("_get_osfhandle" int
214                         (fd int)))
215
216  (:function handle->fd ("_open_osfhandle" int
217                         (osfhandle int)
218                         (flags int)))
219
220  (:structure wsa-data ("struct WSAData"
221                        (integer version "u_int16_t" "wVersion")
222                        (integer high-version "u_int16_t" "wHighVersion")
223                        (c-string description "char" "szDescription")
224                        (c-string system-status "char" "szSystemStatus")
225                        (integer max-sockets "unsigned short" "iMaxSockets")
226                        (integer max-udp-dg "unsigned short" "iMaxUdpDg")
227                        (c-string-pointer vendor-info "char *" "lpVendorInfo")))
228
229  (:function wsa-startup ("WSAStartup" int
230                         (wVersionRequested (unsigned 16))
231                         (lpWSAData wsa-data :out)))
232
233  (:function wsa-get-last-error ("WSAGetLastError" int))
234
235 )