mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 06:09:18 +02:00
adding make-listener-socket
This commit is contained in:
parent
adef7b2116
commit
05d01639eb
2 changed files with 30 additions and 3 deletions
|
@ -59,3 +59,30 @@
|
|||
(let ((res (proc (car io) (car (cdr io)))))
|
||||
(close-input-port (car io))
|
||||
res))))
|
||||
|
||||
;;> @subsubsubsection{@scheme{(make-listener-socket addrinfo [max-conn])}}
|
||||
|
||||
;;> Convenience wrapper to call socket, bind and listen to return
|
||||
;;> a socket suitable for accepting connections on the given
|
||||
;;> @var{addrinfo}. @var{max-conn} is the maximum number of pending
|
||||
;;> connections, and defaults to 128.
|
||||
|
||||
(define (make-listener-socket addrinfo . o)
|
||||
(let* ((max-connections (if (pair? o) (car o) 128))
|
||||
(sock (socket (address-info-family addrinfo)
|
||||
(address-info-socket-type addrinfo)
|
||||
(address-info-protocol addrinfo))))
|
||||
(cond
|
||||
((negative? sock)
|
||||
(error "couldn't create socket for: " addrinfo))
|
||||
((negative? (bind sock
|
||||
(address-info-address addrinfo)
|
||||
(address-info-address-length addrinfo)))
|
||||
(close-file-descriptor sock)
|
||||
(error "couldn't bind socket for: " addrinfo))
|
||||
((negative? (listen sock 100))
|
||||
(close-file-descriptor sock)
|
||||
(error "couldn't listen on socket for: " addrinfo))
|
||||
(else
|
||||
(set-file-descriptor-status! sock open/non-block)
|
||||
sock))))
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
(define-library (chibi net)
|
||||
(export sockaddr? address-info? get-address-info make-address-info
|
||||
socket connect bind accept listen
|
||||
with-net-io open-net-io
|
||||
with-net-io open-net-io make-listener-socket
|
||||
address-info-family address-info-socket-type address-info-protocol
|
||||
address-info-address address-info-address-length address-info-next
|
||||
address-family/unix address-family/inet
|
||||
|
|
Loading…
Add table
Reference in a new issue