windows: fix sb-bsd-sockets build by adding shutdown() support
[sbcl.git] / contrib / sb-bsd-sockets / win32-constants.lisp
index e9b2596..5b4ed07 100644 (file)
-(in-package :sockint)\r
-\r
-(defconstant af-unix 1)\r
-(defconstant af-inet 2)\r
-(defconstant af-local af-unix)\r
-(defconstant msg-oob 1)\r
-(defconstant msg-peek 2)\r
-(defconstant msg-trunc #x8000)\r
-(defconstant msg-waitall 0)\r
-\r
-(defconstant ip-options 1)\r
-(defconstant so-debug 1)\r
-(defconstant so-acceptconn 2)\r
-(defconstant so-reuseaddr 4)\r
-(defconstant so-keepalive 8)\r
-(defconstant so-dontroute 16)\r
-(defconstant so-broadcast 32)\r
-(defconstant so-useloopback 64)\r
-(defconstant so-linger 128)\r
-(defconstant so-oobinline 256)\r
-(defconstant so-dontlinger (lognot so-linger))\r
-(defconstant so-excludiveaddruse (lognot so-reuseaddr))\r
-(defconstant so-sndbuf #x1001)\r
-(defconstant so-rcvbuf #x1002)\r
-(defconstant so-sndlowat #x1003)\r
-(defconstant so-rcvlowat #x1004)\r
-(defconstant so-sndtimeo #x1005)\r
-(defconstant so-rcvtimeo #x1006)\r
-(defconstant so-error #x1007)\r
-(defconstant so-type #x1008)\r
-\r
-(defconstant socket-error -1)\r
-(defconstant sock-stream 1)\r
-(defconstant sock-dgram 2)\r
-(defconstant sock-raw 3)\r
-(defconstant sock-rdm 4)\r
-(defconstant sock-seqpacket 5)\r
-(defconstant tcp-nodelay #x0001)\r
-(defconstant o-append #x0008)\r
-\r
-;; some other windows error code\r
-(defconstant ERROR_NOT_ENOUGH_MEMORY 8)\r
-\r
-;; misc unixy error codes\r
-(defconstant ENOMEM ERROR_NOT_ENOUGH_MEMORY)\r
-(defconstant EPERM 1)\r
-\r
-;; basic socket errors\r
-(defconstant WSABASEERR 10000)\r
-(defconstant EINTR (+ WSABASEERR 4))\r
-(defconstant EBADF (+ WSABASEERR 9))\r
-(defconstant EACCES (+ WSABASEERR 13))\r
-(defconstant EFAULT (+ WSABASEERR 14))\r
-(defconstant EINVAL (+ WSABASEERR 22))\r
-(defconstant EMFILE (+ WSABASEERR 24))\r
-(defconstant EWOULDBLOCK (+ WSABASEERR 35))\r
-(defconstant EAGAIN EWOULDBLOCK)\r
-(defconstant EINPROGRESS (+ WSABASEERR 36))\r
-(defconstant EALREADY (+ WSABASEERR 37))\r
-(defconstant ENOTSOCK (+ WSABASEERR 38))\r
-(defconstant EDESTADDRREQ (+ WSABASEERR 39))\r
-(defconstant EMSGSIZE (+ WSABASEERR 40))\r
-(defconstant EPROTOTYPE (+ WSABASEERR 41))\r
-(defconstant ENOPROTOOPT (+ WSABASEERR 42))\r
-(defconstant EPROTONOSUPPORT (+ WSABASEERR 43))\r
-(defconstant ESOCKTNOSUPPORT (+ WSABASEERR 44))\r
-(defconstant EOPNOTSUPP (+ WSABASEERR 45))\r
-(defconstant EPFNOSUPPORT (+ WSABASEERR 46))\r
-(defconstant EAFNOSUPPORT (+ WSABASEERR 47))\r
-(defconstant EADDRINUSE (+ WSABASEERR 48))\r
-(defconstant EADDRNOTAVAIL (+ WSABASEERR 49))\r
-(defconstant ENETDOWN (+ WSABASEERR 50))\r
-(defconstant ENETUNREACH (+ WSABASEERR 51))\r
-(defconstant ENETRESET (+ WSABASEERR 52))\r
-(defconstant ECONNABORTED (+ WSABASEERR 53))\r
-(defconstant ECONNRESET (+ WSABASEERR 54))\r
-(defconstant ENOBUFS (+ WSABASEERR 55))\r
-(defconstant EISCONN (+ WSABASEERR 56))\r
-(defconstant ENOTCONN (+ WSABASEERR 57))\r
-(defconstant ESHUTDOWN (+ WSABASEERR 58))\r
-(defconstant ETOOMANYREFS (+ WSABASEERR 59))\r
-(defconstant ETIMEDOUT (+ WSABASEERR 60))\r
-(defconstant ECONNREFUSED (+ WSABASEERR 61))\r
-(defconstant ELOOP (+ WSABASEERR 62))\r
-(defconstant ENAMETOOLONG (+ WSABASEERR 63))\r
-(defconstant EHOSTDOWN (+ WSABASEERR 64))\r
-(defconstant EHOSTUNREACH (+ WSABASEERR 65))\r
-(defconstant ENOTEMPTY (+ WSABASEERR 66))\r
-(defconstant EPROCLIM (+ WSABASEERR 67))\r
-(defconstant EUSERS (+ WSABASEERR 68))\r
-(defconstant EDQUOT (+ WSABASEERR 69))\r
-(defconstant ESTALE (+ WSABASEERR 70))\r
-(defconstant EREMOTE (+ WSABASEERR 71))\r
-(defconstant EDISCON (+ WSABASEERR 101))\r
-(defconstant SYSNOTREADY (+ WSABASEERR 91))\r
-(defconstant VERNOTSUPPORTED (+ WSABASEERR 92))\r
-(defconstant NOTINITIALISED (+ WSABASEERR 93))\r
-(defconstant HOST_NOT_FOUND (+ WSABASEERR 1001))\r
-(defconstant TRY_AGAIN (+ WSABASEERR 1002))\r
-(defconstant NO_RECOVERY (+ WSABASEERR 1003))\r
-(defconstant NO_DATA (+ WSABASEERR 1004))\r
-(defconstant WSAENOMORE (+ WSABASEERR 102))\r
-(defconstant WSAECANCELLED (+ WSABASEERR 103))\r
-(defconstant WSAEINVALIDPROCTABLE (+ WSABASEERR 104))\r
-(defconstant WSAEINVALIDPROVIDER (+ WSABASEERR 105))\r
-(defconstant WSAEPROVIDERFAILEDINIT (+ WSABASEERR 106))\r
-(defconstant WSASYSCALLFAILURE (+ WSABASEERR 107))\r
-(defconstant WSASERVICE_NOT_FOUND (+ WSABASEERR 108))\r
-(defconstant WSATYPE_NOT_FOUND (+ WSABASEERR 109))\r
-(defconstant WSA_E_NO_MORE (+ WSABASEERR 110))\r
-(defconstant WSA_E_CANCELLED (+ WSABASEERR 111))\r
-(defconstant WSAEREFUSED (+ WSABASEERR 112))\r
-(defconstant WSA_QOS_RECEIVERS (+ WSABASEERR 1005))\r
-(defconstant WSA_QOS_SENDERS (+ WSABASEERR 1006))\r
-(defconstant WSA_QOS_NO_SENDERS (+ WSABASEERR 1007))\r
-(defconstant WSA_QOS_NO_RECEIVERS (+ WSABASEERR 1008))\r
-(defconstant WSA_QOS_REQUEST_CONFIRMED (+ WSABASEERR 1009))\r
-(defconstant WSA_QOS_ADMISSION_FAILURE (+ WSABASEERR 1010))\r
-(defconstant WSA_QOS_POLICY_FAILURE (+ WSABASEERR 1011))\r
-(defconstant WSA_QOS_BAD_STYLE (+ WSABASEERR 1012))\r
-(defconstant WSA_QOS_BAD_OBJECT (+ WSABASEERR 1013))\r
-(defconstant WSA_QOS_TRAFFIC_CTRL_ERROR (+ WSABASEERR 1014))\r
-(defconstant WSA_QOS_GENERIC_ERROR (+ WSABASEERR 1015))\r
-(defconstant WSA_QOS_ESERVICETYPE (+ WSABASEERR 1016))\r
-(defconstant WSA_QOS_EFLOWSPEC (+ WSABASEERR 1017))\r
-(defconstant WSA_QOS_EPROVSPECBUF (+ WSABASEERR 1018))\r
-(defconstant WSA_QOS_EFILTERSTYLE (+ WSABASEERR 1019))\r
-(defconstant WSA_QOS_EFILTERTYPE (+ WSABASEERR 1020))\r
-(defconstant WSA_QOS_EFILTERCOUNT (+ WSABASEERR 1021))\r
-(defconstant WSA_QOS_EOBJLENGTH (+ WSABASEERR 1022))\r
-(defconstant WSA_QOS_EFLOWCOUNT (+ WSABASEERR 1023))\r
-(defconstant WSA_QOS_EUNKOWNPSOBJ (+ WSABASEERR 1024))\r
-(defconstant WSA_QOS_EPOLICYOBJ (+ WSABASEERR 1025))\r
-(defconstant WSA_QOS_EFLOWDESC (+ WSABASEERR 1026))\r
-(defconstant WSA_QOS_EPSFLOWSPEC (+ WSABASEERR 1027))\r
-(defconstant WSA_QOS_EPSFILTERSPEC (+ WSABASEERR 1028))\r
-(defconstant WSA_QOS_ESDMODEOBJ (+ WSABASEERR 1029))\r
-(defconstant WSA_QOS_ESHAPERATEOBJ (+ WSABASEERR 1030))\r
-(defconstant WSA_QOS_RESERVED_PETYPE (+ WSABASEERR 1031))\r
-\r
-(defconstant HOST-NOT-FOUND (+ WSABASEERR 1001))\r
-(defconstant TRY-AGAIN (+ WSABASEERR 1002))\r
-(defconstant NO-RECOVERY (+ WSABASEERR 1003))\r
-(defconstant NO-ADDRESS NO_DATA)\r
-(defconstant SOL-SOCKET #xffff)
\ No newline at end of file
+;;; -*- Lisp -*-
+
+;;; This isn't really lisp, but it's definitely a source file.  we
+;;; name it thus to avoid having to mess with the clc lpn translations
+
+;;; first, the headers necessary to find definitions of everything
+("winsock2.h")
+
+;;; then the stuff we're looking for
+((:integer af-inet "AF_INET" "IP Protocol family")
+ (:integer af-unspec "AF_UNSPEC" "Unspecified")
+ (:integer sock-stream "SOCK_STREAM"
+           "Sequenced, reliable, connection-based byte streams.")
+ (:integer sock-dgram "SOCK_DGRAM"
+           "Connectionless, unreliable datagrams of fixed maximum length.")
+ (:integer sock-raw "SOCK_RAW"
+           "Raw protocol interface.")
+ (:integer sock-rdm "SOCK_RDM"
+           "Reliably-delivered messages.")
+ (:integer sock-seqpacket "SOCK_SEQPACKET"
+           "Sequenced, reliable, connection-based, datagrams of fixed maximum length.")
+
+ (:integer sol-socket "SOL_SOCKET")
+
+ ;; some of these may be linux-specific
+ (:integer so-debug "SO_DEBUG"
+   "Enable debugging in underlying protocol modules")
+ (:integer so-reuseaddr "SO_REUSEADDR" "Enable local address reuse")
+ (:integer so-type "SO_TYPE")                  ;get only
+ (:integer so-error "SO_ERROR")                 ;get only (also clears)
+ (:integer so-dontroute "SO_DONTROUTE"
+           "Bypass routing facilities: instead send direct to appropriate network interface for the network portion of the destination address")
+ (:integer so-broadcast "SO_BROADCAST" "Request permission to send broadcast datagrams")
+ (:integer so-sndbuf "SO_SNDBUF")
+ (:integer so-rcvbuf "SO_RCVBUF")
+ (:integer so-keepalive "SO_KEEPALIVE"
+           "Send periodic keepalives: if peer does not respond, we get SIGPIPE")
+ (:integer so-oobinline "SO_OOBINLINE"
+           "Put out-of-band data into the normal input queue when received")
+ (:integer so-linger "SO_LINGER"
+           "For reliable streams, pause a while on closing when unsent messages are queued")
+ (:integer so-sndlowat "SO_SNDLOWAT")
+ (:integer so-rcvlowat "SO_RCVLOWAT")
+ (:integer so-sndtimeo "SO_SNDTIMEO")
+ (:integer so-rcvtimeo "SO_RCVTIMEO")
+
+ (:integer tcp-nodelay "TCP_NODELAY")
+
+ (:integer HOST-NOT-FOUND "HOST_NOT_FOUND" "Authoritative Answer Host not found.")
+ (:integer TRY-AGAIN "TRY_AGAIN" "Non-Authoritative Host not found, or SERVERFAIL.")
+ (:integer NO-RECOVERY "NO_RECOVERY" "Non recoverable errors, FORMERR, REFUSED, NOTIMP.")
+ (:integer NO-DATA "NO_DATA" "Valid name, no data record of requested type.")
+ (:integer NO-ADDRESS "NO_ADDRESS" "No address, look for MX record.")
+
+ (:integer msg-oob "MSG_OOB")
+ (:integer msg-peek "MSG_PEEK")
+ (:integer msg-dontroute "MSG_DONTROUTE")
+
+ ;; socket shutdown flags
+ (:integer SHUT_RD "SD_RECEIVE")
+ (:integer SHUT_WR "SD_SEND")
+ (:integer SHUT_RDWR "SD_BOTH")
+
+ ;; errors
+ (:integer EADDRINUSE "WSAEADDRINUSE")
+ (:integer EAGAIN "WSAEWOULDBLOCK")
+ (:integer EBADF "WSAEBADF")
+ (:integer ECONNREFUSED "WSAECONNREFUSED")
+ (:integer ETIMEDOUT "WSAETIMEDOUT")
+ (:integer EINTR "WSAEINTR")
+ (:integer EINVAL "WSAEINVAL")
+ (:integer ENOBUFS "WSAENOBUFS")
+ (:integer ENOMEM "WSAENOBUFS")
+ (:integer EOPNOTSUPP "WSAEOPNOTSUPP")
+ (:integer EPERM "WSAENETDOWN")
+ (:integer EPROTONOSUPPORT "WSAEPROTONOSUPPORT")
+ (:integer ESOCKTNOSUPPORT "WSAESOCKTNOSUPPORT")
+ (:integer ENETUNREACH "WSAENETUNREACH")
+ (:integer ENOTCONN "WSAENOTCONN")
+ (:integer inaddr-any "INADDR_ANY")
+ (:integer FIONBIO "FIONBIO")
+
+
+ ;; for socket-receive
+ (:type socklen-t "int")
+ (:type size-t "size_t")
+ (:type ssize-t "ssize_t")
+
+ (:structure in-addr ("struct in_addr"
+                      ((array (unsigned 8)) addr "u_int32_t" "s_addr")))
+
+ (:structure sockaddr-in ("struct sockaddr_in"
+                          (integer family "sa_family_t" "sin_family")
+                          ;; These two could be in-port-t and
+                          ;; in-addr-t, but then we'd throw away the
+                          ;; convenience (and byte-order agnosticism)
+                          ;; of the old sb-grovel scheme.
+                          ((array (unsigned 8)) port "u_int16_t" "sin_port")
+                          ((array (unsigned 8)) addr "struct in_addr" "sin_addr")))
+
+ (:structure hostent ("struct hostent"
+                      (c-string-pointer name "char *" "h_name")
+                      ((* c-string) aliases "char **" "h_aliases")
+                      (integer type "int" "h_addrtype")
+                      (integer length "int" "h_length")
+                      ((* (* (unsigned 8))) addresses "char **" "h_addr_list")))
+
+ (:structure protoent ("struct protoent"
+                       (c-string-pointer name "char *" "p_name")
+                       ((* (* t)) aliases "char **" "p_aliases")
+                       (integer proto "int" "p_proto")))
+
+ (:function getprotobyname ("getprotobyname" (* protoent)
+                                             (name c-string)))
+
+ (:function getprotobynumber ("getprotobynumber" (* protoent)
+                                                 (proto int)))
+
+ ;; FIXME: We should probably grovel the windows SOCKET type and use it in
+ ;; these instead of int...
+
+ ;; KLUDGE: For historical reasons many of these prepend win32- to the symbol
+ ;; names. Life for Windows users of SBCL is already hard enough, so rather
+ ;; than break compatibility for those who directly use these, win32-sockets.lisp
+ ;; wraps them with prefixless wrappers.
+ (:function win32-bind
+            ("bind" int
+             (sockfd int)
+             (my-addr (* t))  ; KLUDGE: sockaddr-in or sockaddr-un?
+             (addrlen socklen-t)))
+
+ (:function win32-listen ("listen" int
+                    (socket int)
+                    (backlog int)))
+
+ (:function win32-accept ("accept" int
+                    (socket int)
+                    (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
+                    (addrlen int :in-out)))
+
+ (:function win32-getpeername ("getpeername" int
+                         (socket int)
+                         (her-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
+                         (addrlen socklen-t :in-out)))
+
+ (:function win32-getsockname ("getsockname" int
+                         (socket int)
+                         (my-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
+                         (addrlen socklen-t :in-out)))
+
+ (:function win32-connect ("connect" int
+                           (socket int)
+                           (his-addr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
+                           (addrlen socklen-t)))
+
+ (:function win32-close ("closesocket" int
+                         (fd int)))
+
+ (:function shutdown ("shutdown" int
+                      (socket int) ; KLUDGE: should be SOCKET, not int.
+                      (how int)))
+
+ (:function win32-recvfrom ("recvfrom" ssize-t
+                            (socket int)
+                            (buf (* t))
+                            (len integer)
+                            (flags int)
+                            (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
+                            (socklen (* socklen-t))))
+
+ (:function win32-recv ("recv" int
+                        (socket int)
+                        (buf (* t))
+                        (len integer)
+                        (flags integer)))
+
+ (:function win32-send ("send" ssize-t
+                        (socket int)
+                        (buf (* t))
+                        (len size-t)
+                        (flags int)))
+
+ (:function win32-sendto ("sendto" int
+                          (socket int)
+                          (buf (* t))
+                          (len size-t)
+                          (flags int)
+                          (sockaddr (* t)) ; KLUDGE: sockaddr-in or sockaddr-un?
+                          (socklen socklen-t)))
+
+ (:function gethostbyname ("gethostbyname" (* hostent) (name c-string)))
+
+ (:function gethostbyaddr ("gethostbyaddr" (* hostent)
+                                           (addr (* t))
+                                           (len int)
+                                           (af int)))
+
+;;; should be using getaddrinfo instead?
+
+ (:function win32-setsockopt ("setsockopt" int
+                        (socket int)
+                        (level int)
+                        (optname int)
+                        (optval (* t))
+                        (optlen int))) ;;; should be socklen-t!
+
+ (:function win32-getsockopt ("getsockopt" int
+                        (socket int)
+                        (level int)
+                        (optname int)
+                        (optval (* t))
+                        (optlen int :in-out))) ;;; should be socklen-t!
+
+ (:function win32-ioctl ("ioctlsocket"  int
+                         (socket int)
+                         (cmd int)
+                         (argp (unsigned 32) :in-out)))
+
+
+;;; Win32 specific cruft
+ (:function wsa-socket ("WSASocketA" int
+                        (af int)
+                        (type int)
+                        (protocol int)
+                        (lpProtocolInfo (* t))
+                        (g int)
+                        (flags int)))
+
+ (:function fd->handle ("_get_osfhandle" int
+                        (fd int)))
+
+ (:function handle->fd ("_open_osfhandle" int
+                        (osfhandle int)
+                        (flags int)))
+
+ (:structure wsa-data ("struct WSAData"
+                       (integer version "u_int16_t" "wVersion")
+                       (integer high-version "u_int16_t" "wHighVersion")
+                       (c-string description "char" "szDescription")
+                       (c-string system-status "char" "szSystemStatus")
+                       (integer max-sockets "unsigned short" "iMaxSockets")
+                       (integer max-udp-dg "unsigned short" "iMaxUdpDg")
+                       (c-string-pointer vendor-info "char *" "lpVendorInfo")))
+
+ (:function wsa-startup ("WSAStartup" int
+                        (wVersionRequested (unsigned 16))
+                        (lpWSAData wsa-data :out)))
+
+ (:function wsa-get-last-error ("WSAGetLastError" int))
+
+)
\ No newline at end of file