windows: fix sb-bsd-sockets build by adding shutdown() support
[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  ;; socket shutdown flags
60  (:integer SHUT_RD "SD_RECEIVE")
61  (:integer SHUT_WR "SD_SEND")
62  (:integer SHUT_RDWR "SD_BOTH")
63
64  ;; errors
65  (:integer EADDRINUSE "WSAEADDRINUSE")
66  (:integer EAGAIN "WSAEWOULDBLOCK")
67  (:integer EBADF "WSAEBADF")
68  (:integer ECONNREFUSED "WSAECONNREFUSED")
69  (:integer ETIMEDOUT "WSAETIMEDOUT")
70  (:integer EINTR "WSAEINTR")
71  (:integer EINVAL "WSAEINVAL")
72  (:integer ENOBUFS "WSAENOBUFS")
73  (:integer ENOMEM "WSAENOBUFS")
74  (:integer EOPNOTSUPP "WSAEOPNOTSUPP")
75  (:integer EPERM "WSAENETDOWN")
76  (:integer EPROTONOSUPPORT "WSAEPROTONOSUPPORT")
77  (:integer ESOCKTNOSUPPORT "WSAESOCKTNOSUPPORT")
78  (:integer ENETUNREACH "WSAENETUNREACH")
79  (:integer ENOTCONN "WSAENOTCONN")
80  (:integer inaddr-any "INADDR_ANY")
81  (:integer FIONBIO "FIONBIO")
82
83
84  ;; for socket-receive
85  (:type socklen-t "int")
86  (:type size-t "size_t")
87  (:type ssize-t "ssize_t")
88
89  (:structure in-addr ("struct in_addr"
90                       ((array (unsigned 8)) addr "u_int32_t" "s_addr")))
91
92  (:structure sockaddr-in ("struct sockaddr_in"
93                           (integer family "sa_family_t" "sin_family")
94                           ;; These two could be in-port-t and
95                           ;; in-addr-t, but then we'd throw away the
96                           ;; convenience (and byte-order agnosticism)
97                           ;; of the old sb-grovel scheme.
98                           ((array (unsigned 8)) port "u_int16_t" "sin_port")
99                           ((array (unsigned 8)) addr "struct in_addr" "sin_addr")))
100
101  (:structure hostent ("struct hostent"
102                       (c-string-pointer name "char *" "h_name")
103                       ((* c-string) aliases "char **" "h_aliases")
104                       (integer type "int" "h_addrtype")
105                       (integer length "int" "h_length")
106                       ((* (* (unsigned 8))) addresses "char **" "h_addr_list")))
107
108  (:structure protoent ("struct protoent"
109                        (c-string-pointer name "char *" "p_name")
110                        ((* (* t)) aliases "char **" "p_aliases")
111                        (integer proto "int" "p_proto")))
112
113  (:function getprotobyname ("getprotobyname" (* protoent)
114                                              (name c-string)))
115
116  (:function getprotobynumber ("getprotobynumber" (* protoent)
117                                                  (proto int)))
118
119  ;; FIXME: We should probably grovel the windows SOCKET type and use it in
120  ;; these instead of int...
121
122  ;; KLUDGE: For historical reasons many of these prepend win32- to the symbol
123  ;; names. Life for Windows users of SBCL is already hard enough, so rather
124  ;; than break compatibility for those who directly use these, win32-sockets.lisp
125  ;; wraps them with prefixless wrappers.
126  (:function win32-bind
127             ("bind" int
128              (sockfd int)
129              (my-addr (* t))  ; KLUDGE: sockaddr-in or sockaddr-un?
130              (addrlen socklen-t)))
131
132  (:function win32-listen ("listen" int
133                     (socket int)
134                     (backlog int)))
135
136  (:function win32-accept ("accept" int
137                     (socket int)
138                     (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
139                     (addrlen int :in-out)))
140
141  (:function win32-getpeername ("getpeername" int
142                          (socket int)
143                          (her-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
144                          (addrlen socklen-t :in-out)))
145
146  (:function win32-getsockname ("getsockname" int
147                          (socket int)
148                          (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
149                          (addrlen socklen-t :in-out)))
150
151  (:function win32-connect ("connect" int
152                            (socket int)
153                            (his-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
154                            (addrlen socklen-t)))
155
156  (:function win32-close ("closesocket" int
157                          (fd int)))
158
159  (:function shutdown ("shutdown" int
160                       (socket int) ; KLUDGE: should be SOCKET, not int.
161                       (how int)))
162
163  (:function win32-recvfrom ("recvfrom" ssize-t
164                             (socket int)
165                             (buf (* t))
166                             (len integer)
167                             (flags int)
168                             (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
169                             (socklen (* socklen-t))))
170
171  (:function win32-recv ("recv" int
172                         (socket int)
173                         (buf (* t))
174                         (len integer)
175                         (flags integer)))
176
177  (:function win32-send ("send" ssize-t
178                         (socket int)
179                         (buf (* t))
180                         (len size-t)
181                         (flags int)))
182
183  (:function win32-sendto ("sendto" int
184                           (socket int)
185                           (buf (* t))
186                           (len size-t)
187                           (flags int)
188                           (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
189                           (socklen socklen-t)))
190
191  (:function gethostbyname ("gethostbyname" (* hostent) (name c-string)))
192
193  (:function gethostbyaddr ("gethostbyaddr" (* hostent)
194                                            (addr (* t))
195                                            (len int)
196                                            (af int)))
197
198 ;;; should be using getaddrinfo instead?
199
200  (:function win32-setsockopt ("setsockopt" int
201                         (socket int)
202                         (level int)
203                         (optname int)
204                         (optval (* t))
205                         (optlen int))) ;;; should be socklen-t!
206
207  (:function win32-getsockopt ("getsockopt" int
208                         (socket int)
209                         (level int)
210                         (optname int)
211                         (optval (* t))
212                         (optlen int :in-out))) ;;; should be socklen-t!
213
214  (:function win32-ioctl ("ioctlsocket"  int
215                          (socket int)
216                          (cmd int)
217                          (argp (unsigned 32) :in-out)))
218
219
220 ;;; Win32 specific cruft
221  (:function wsa-socket ("WSASocketA" int
222                         (af int)
223                         (type int)
224                         (protocol int)
225                         (lpProtocolInfo (* t))
226                         (g int)
227                         (flags int)))
228
229  (:function fd->handle ("_get_osfhandle" int
230                         (fd int)))
231
232  (:function handle->fd ("_open_osfhandle" int
233                         (osfhandle int)
234                         (flags int)))
235
236  (:structure wsa-data ("struct WSAData"
237                        (integer version "u_int16_t" "wVersion")
238                        (integer high-version "u_int16_t" "wHighVersion")
239                        (c-string description "char" "szDescription")
240                        (c-string system-status "char" "szSystemStatus")
241                        (integer max-sockets "unsigned short" "iMaxSockets")
242                        (integer max-udp-dg "unsigned short" "iMaxUdpDg")
243                        (c-string-pointer vendor-info "char *" "lpVendorInfo")))
244
245  (:function wsa-startup ("WSAStartup" int
246                         (wVersionRequested (unsigned 16))
247                         (lpWSAData wsa-data :out)))
248
249  (:function wsa-get-last-error ("WSAGetLastError" int))
250
251 )