mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 14:19: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
|
@ -14,8 +14,8 @@
|
||||||
(if (and (pair? o) (car o))
|
(if (and (pair? o) (car o))
|
||||||
(car o)
|
(car o)
|
||||||
(make-address-info address-family/inet
|
(make-address-info address-family/inet
|
||||||
socket-type/stream
|
socket-type/stream
|
||||||
ip-proto/tcp))))
|
ip-proto/tcp))))
|
||||||
|
|
||||||
;;> Opens a client net connection to @var{host}, a string,
|
;;> Opens a client net connection to @var{host}, a string,
|
||||||
;;> on port @var{service}, which can be a string such as
|
;;> on port @var{service}, which can be a string such as
|
||||||
|
@ -59,3 +59,30 @@
|
||||||
(let ((res (proc (car io) (car (cdr io)))))
|
(let ((res (proc (car io) (car (cdr io)))))
|
||||||
(close-input-port (car io))
|
(close-input-port (car io))
|
||||||
res))))
|
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)
|
(define-library (chibi net)
|
||||||
(export sockaddr? address-info? get-address-info make-address-info
|
(export sockaddr? address-info? get-address-info make-address-info
|
||||||
socket connect bind accept listen
|
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-family address-info-socket-type address-info-protocol
|
||||||
address-info-address address-info-address-length address-info-next
|
address-info-address address-info-address-length address-info-next
|
||||||
address-family/unix address-family/inet
|
address-family/unix address-family/inet
|
||||||
|
|
Loading…
Add table
Reference in a new issue