Re: net.lisp basic sbcl sb-bsd-sockets support
Philippe Brochard <[email protected]> Wed, 21 Jun 2006 22:53:30 +0200
| Newsgroups | gmane.lisp.clocc.general |
|---|---|
| Organization | GNU/Linux Home |
| Message-ID | <[email protected]> |
--=-=-=
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Philippe Brochard a =E9crit :
> Hi all,
>
> here is a patch to clocc/net.lisp to support sbcl/sb-bsd-sockets.
>
> open-socket-server, socket-accept, open-socket,
> socket-server-close and socket-server-host/port seems to work for
> me. But I don't know how to write socket-host/port.
>
I answer to myself, here is a new patch to have the wait option in
socket-accept.
And socket-accept return two values: the stream and the real
socket. So socket-host/port works with this second value.
I use it like this (it's a little bit uggly):
(multiple-value-bind (sock #+(and sbcl sb-bsd-sockets) real-sock)
(port:socket-accept sock-server :wait 0.5)
...
(port:socket-host/port #-(and sbcl sb-bsd-sockets) sock
#+(and sbcl sb-bsd-sockets) real-sock)
...)
Regards,
Philippe
--=20
Philippe Brochard <[email protected]>
http://hocwp.free.fr
-=3D-=3D http://www.gnu.org/home.fr.html =3D-=3D-
--=-=-=
Content-Disposition: inline; filename=net.lisp.diff
Index: net.lisp
===================================================================
RCS file: /cvsroot/clocc/clocc/src/port/net.lisp,v
retrieving revision 1.59
diff -r1.59 net.lisp
20c20,24
< #+lispworks (require "comm"))
---
> #+lispworks (require "comm")
> #+(and sbcl (not (or db-sockets net.sbcl.sockets)))
> (progn
> (require :sb-bsd-sockets)
> (pushnew :sb-bsd-sockets *features*)))
63c67
< ;#+(and sbcl db-sockets)
---
> ;#+(and sbcl (or db-sockets sb-bsd-sockets))
66c70
< #+(and sbcl db-sockets)
---
> #+(and sbcl (or db-sockets sb-bsd-sockets))
73c77
< ;#+(and sbcl db-sockets)
---
> ;#+(and sbcl (or db-sockets sb-bsd-sockets))
76c80
< #+(and sbcl db-sockets)
---
> #+(and sbcl (or db-sockets sb-bsd-sockets))
181a186
> #+(and sbcl sb-bsd-sockets) 'sb-sys:fd-stream
183c188
< (and sbcl (or db-sockets net.sbcl.sockets)) scl) 'stream)
---
> (and sbcl (or db-sockets net.sbcl.sockets sb-bsd-sockets)) scl) 'stream)
223a229,238
> #+(and sbcl sb-bsd-sockets)
> (let ((socket (make-instance 'sb-bsd-sockets:inet-socket
> :type :stream :protocol :tcp)))
> (sb-bsd-sockets:socket-connect socket
> (sb-bsd-sockets::host-ent-address
> (sb-bsd-sockets:get-host-by-name host))
> port)
> (sb-bsd-sockets:socket-make-stream
> socket :input t :output t :buffering (if bin :none :line)
> :element-type (if bin '(unsigned-byte 8) 'character)))
225c240
< (and sbcl (or net.sbcl.sockets db-sockets)) scl)
---
> (and sbcl (or net.sbcl.sockets db-sockets sb-bsd-sockets)) scl)
237a253
> #-(and sbcl sb-bsd-sockets)
281a298,304
> #+(and sbcl sb-bsd-sockets)
> (multiple-value-bind (remote remote-port) (sb-bsd-sockets:socket-peername sock)
> (multiple-value-bind (local local-port) (sb-bsd-sockets:socket-name sock)
> (values (ipaddr-to-dotted (vector-to-ipaddr remote))
> remote-port
> (ipaddr-to-dotted (vector-to-ipaddr local))
> local-port)))
283c306
< (and sbcl (or net.sbcl.sockets db-sockets)) scl)
---
> (and sbcl (or net.sbcl.sockets db-sockets sb-bsd-sockets)) scl)
309a333
> #+(and sbcl sb-bsd-sockets) 'sb-bsd-sockets:inet-socket
338a363,370
> #+(and sbcl sb-bsd-sockets)
> (let ((sock (make-instance 'sb-bsd-sockets:inet-socket
> :type :stream
> :protocol :tcp)))
> (setf (sb-bsd-sockets:sockopt-reuse-address sock) t)
> (sb-bsd-sockets:socket-bind sock (vector 0 0 0 0) (or port 0))
> (sb-bsd-sockets:socket-listen sock 15)
> sock)
340c372
< (and sbcl (or net.sbcl.sockets db-sockets)) scl)
---
> (and sbcl (or net.sbcl.sockets db-sockets sb-bsd-sockets)) scl)
349c381,382
< Returns a socket stream or NIL."
---
> Returns a socket stream or NIL.
> Note: with sbcl and sb-bsd-sockets, the socket is returned as second value"
406a440,450
> #+(and sbcl sb-bsd-sockets)
> (progn
> (setf (sb-bsd-sockets:non-blocking-mode serv) wait)
> (let ((s (sb-bsd-sockets:socket-accept serv)))
> (if s
> (values (sb-bsd-sockets:socket-make-stream s
> :input t :output t
> :element-type (if bin '(unsigned-byte 8) 'character)
> :buffering :full)
> s)
> (sleep wait))))
408c452
< (and sbcl (or net.sbcl.sockets db-sockets)) scl)
---
> (and sbcl (or net.sbcl.sockets db-sockets sb-bsd-sockets)) scl)
423a468
> #+(and sbcl sb-bsd-sockets) (sb-bsd-sockets:socket-close server)
425c470
< (and sbcl (or net.sbcl.sockets db-sockets)) scl)
---
> (and sbcl (or net.sbcl.sockets db-sockets sb-bsd-sockets)) scl)
453a499,501
> #+(and sbcl sb-bsd-sockets)
> (multiple-value-bind (addr port) (sb-bsd-sockets:socket-name server)
> (values (ipaddr-to-dotted (vector-to-ipaddr addr)) port))
455c503
< (and sbcl (or net.sbcl.sockets db-sockets)) scl)
---
> (and sbcl (or net.sbcl.sockets db-sockets sb-bsd-sockets)) scl)
--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
clocc-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clocc-list
--=-=-=--