From 9dc4c973371492625c22c15c6bfc9369d3dee636 Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Thu, 17 Apr 2008 02:26:48 +0200 Subject: [PATCH] Add keyword args WAIT and TIMEOUT to ACCEPT-CONNECTION. Signed-off-by: Stelian Ionescu --- net.sockets/base-sockets.lisp | 2 ++ net.sockets/socket-methods.lisp | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/net.sockets/base-sockets.lisp b/net.sockets/base-sockets.lisp index c9d35b3..c943837 100644 --- a/net.sockets/base-sockets.lisp +++ b/net.sockets/base-sockets.lisp @@ -168,6 +168,8 @@ Returns the number of bytes sent.")) (defgeneric accept-connection (passive-socket &key &allow-other-keys) (:documentation "Returns one connection from the queue of pending connections on `SOCKET'. +If `WAIT' is true, waits until a connection is received or `TIMEOUT' expires in which case returns NIL. +If `WAIT' is false and there are no pending connections return NIL. `EXTERNAL-FORMAT' optionally specifies the external format of the new socket - the default being that of `SOCKET'. Buffer sizes for the new socket can also be specified using `INPUT-BUFFER-SIZE' and `OUTPUT-BUFFER-SIZE'.")) diff --git a/net.sockets/socket-methods.lisp b/net.sockets/socket-methods.lisp index 29437c7..02fed30 100644 --- a/net.sockets/socket-methods.lisp +++ b/net.sockets/socket-methods.lisp @@ -263,7 +263,8 @@ (error "You can't accept connections on active sockets.")) (defmethod accept-connection ((socket passive-socket) &key external-format - input-buffer-size output-buffer-size) + input-buffer-size output-buffer-size + (wait t) (timeout nil)) (flet ((make-client-socket (fd) (make-instance (active-class socket) :file-descriptor fd @@ -271,10 +272,11 @@ (external-format-of socket)) :input-buffer-size input-buffer-size :output-buffer-size output-buffer-size))) - (with-sockaddr-storage-and-socklen (ss size) - (handler-case - (make-client-socket (%accept (fd-of socket) ss size)) - (nix:ewouldblock ()))))) + (ignore-some-conditions (iomux:poll-timeout) + (when wait (iomux:wait-until-fd-ready (fd-of socket) :read timeout t)) + (with-sockaddr-storage-and-socklen (ss size) + (ignore-some-conditions (nix:ewouldblock) + (make-client-socket (%accept (fd-of socket) ss size))))))) ;;;; CONNECT -- 2.11.4.GIT