7aa765a134e0048aa49c74bba58f84e88fd7e8a3
[sbcl.git] / contrib / sb-bsd-sockets / win32-sockets.lisp
1 ;;;; win32 socket operations
2 ;;;; these have all been done by hand since I can't seem
3 ;;;; to get my head around the sb-grovel stuff
4
5 ;;;; Winsock requires us to convert HANDLES to/from
6 ;;;; file descriptors, so I've added an additional
7 ;;;; package for the actual winsock alien defs, and then
8 ;;;; in the sockint package, we implement wrappers that
9 ;;;; handle the conversion.
10
11 ;;; these are all of the basic structure alien defs
12 (in-package :sockint)
13
14 ;;;; we are now going back to the normal sockint
15 ;;;; package where we will redefine all of the above
16 ;;;; functions, converting between HANDLES and fds
17
18 (defun socket (af type proto)
19   (let* ((handle (wsa-socket af type proto nil 0 0))
20          (fd (handle->fd handle 0)))
21     fd))
22
23 (defun bind (fd &rest options)
24   (let ((handle (fd->handle fd)))
25     (apply #'win32-bind handle options)))
26
27 (defun getsockname (fd &rest options)
28   (apply #'win32-getsockname (fd->handle fd) options))
29
30 (defun listen (fd &rest options)
31   (apply #'win32-listen (fd->handle fd) options))
32
33 (defun accept (fd &rest options)
34   (handle->fd
35    (apply #'win32-accept (fd->handle fd) options)
36    0))
37
38 (defun recv (fd &rest options)
39   (apply #'win32-recv (fd->handle fd) options))
40
41 (defun recvfrom (fd &rest options)
42   (apply #'win32-recvfrom (fd->handle fd) options))
43
44 (defun send (fd &rest options)
45   (apply #'win32-send (fd->handle fd) options))
46
47 (defun sendto (fd &rest options)
48   (apply #'win32-sendto (fd->handle fd) options))
49
50 (defun close (fd &rest options)
51   (apply #'win32-close (fd->handle fd) options))
52
53 (defun connect (fd &rest options)
54   (apply #'win32-connect (fd->handle fd) options))
55
56 (defun getpeername (fd &rest options)
57   (apply #'win32-getpeername (fd->handle fd) options))
58
59 (defun ioctl (fd &rest options)
60   (apply #'win32-ioctl (fd->handle fd) options))
61
62 (defun setsockopt (fd &rest options)
63   (apply #'win32-setsockopt (fd->handle fd) options))
64
65 (defun getsockopt (fd &rest options)
66   (apply #'win32-getsockopt (fd->handle fd) options))
67
68 (defun make-wsa-version (major minor)
69   (dpb minor (byte 8 8) major))
70
71 (defvar *wsa-startup-call* nil)
72
73 (defun call-wsa-startup ()
74   (setf *wsa-startup-call* (wsa-startup (make-wsa-version 2 2))))
75
76 ;;; Startup!
77 (call-wsa-startup)
78
79 ;;; Ensure startup for saved cores as well.
80 (push 'call-wsa-startup sb-ext:*init-hooks*)
81
82 ;; not implemented on win32
83 (defconstant af-local 0)
84 (defconstant msg-dontwait 0)
85 (defconstant msg-trunc 0)
86 (defconstant msg-eor 0)
87 (defconstant msg-nosignal 0)
88 (defconstant msg-waitall 0)
89 (defconstant msg-eor 0)
90 (defconstant size-of-sockaddr-un 0)
91 (defun (setf sockaddr-un-family) (addr family) ())
92 (defun (setf sockaddr-un-path) (addr family) ())
93 (defun sockaddr-un-path (addr) ())
94 (defun free-sockaddr-un (addr) ())
95 (defun allocate-sockaddr-un () ())
96
97