Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'develop' into mad-dev

  • Loading branch information...
commit 4669d56acc09948b87f0728c2de43364cd3016c9 2 parents fd1d0f1 + 7262066
@zkat authored
View
4 docs/conserv.tcp.md
@@ -226,6 +226,10 @@ although this can safely be changed by `setf`ing `socket-driver` inside the `ser
Returns the number of `socket` objects connected to `server`.
+*[function]* `server-paused-p server`
+
+ Returns true when `server` is not currently accepting new connections.
+
*[function]* `server-pause server &key timeout`
Pauses read events for `server`, preventing it from accepting new connections. While paused, all
View
1  src/tcp/package.lisp
@@ -45,5 +45,6 @@
#:server-external-format-out
#:server-list-clients
#:server-count-clients
+ #:server-paused-p
#:server-pause
#:server-resume))
View
4 src/tcp/server.lisp
@@ -78,6 +78,10 @@
(let ((*server* server))
(on-server-close (server-driver server))))
+(defun server-paused-p (server)
+ "Returns true when `server` is not currently accepting new connections."
+ (socket-paused-p (server-socket server)))
+
(defun server-pause (server &key timeout)
"Pauses read events for `server`, preventing it from accepting new connections. While paused, all
`socket`s already connected to `server` continue to work normally, but new connections will not
View
72 src/tcp/socket.lisp
@@ -191,11 +191,16 @@
(external-format-out *default-external-format*))
"Establishes a TCP connection with `host`. If successful, returns a `socket` object.
- * `driver` -- an instance of a driver class that will be used to dispatch `socket-event-driver` events.
- * `host` -- Either a string representing a remote IP address or hostname, or a pathname to a local IPC socket.
+ * `driver` -- an instance of a driver class that will be used to dispatch `socket-event-driver`
+ events.
+ * `host` -- Either a string representing a remote IP address or hostname, or a pathname to a
+ local IPC socket.
* `port` -- Port number to connect to. Should not be provided if `host` is an IPC socket.
- * `external-format-in` -- Either an external format or `nil`. Used for determining the encoding of data passed to `on-socket-data`
- * `external-format-out` -- Either an external format or `nil`. Used for converting strings written to the socket. If `nil`, an error will be signaled if an attempt is made to write a string to the socket."
+ * `external-format-in` -- Either an external format or `nil`. Used for determining the encoding
+ of data passed to `on-socket-data`
+ * `external-format-out` -- Either an external format or `nil`. Used for converting strings
+ written to the socket. If `nil`, an error will be signaled if an attempt is made to write a
+ string to the socket."
(let ((socket (make-socket driver
:buffer-size buffer-size
:external-format-in external-format-in
@@ -267,35 +272,36 @@
"Resumes reads on a paused `socket`. If `socket` was not already paused, this function has no
effect."
(when (socket-paused-p socket)
- (iolib:set-io-handler (socket-event-base socket)
- (iolib:socket-os-fd (socket-internal-socket socket))
- :read (lambda (&rest ig)
- (declare (ignore ig))
- (handler-bind ((end-of-file (lambda (e &aux (*socket* socket))
- (on-socket-end-of-file
- (socket-driver socket))
- (drop-connection e)))
- (error
- (lambda (e &aux (*socket* socket))
- (on-socket-error (socket-driver socket) e))))
- (restart-case
- (let* ((buffer (socket-read-buffer socket))
- (bytes-read
- (nth-value
- 1 (iolib:receive-from (socket-internal-socket socket) :buffer buffer))))
- (when (zerop bytes-read)
- (error 'end-of-file :stream socket))
- (incf (socket-bytes-read socket) bytes-read)
- (let ((data (if-let (format (socket-external-format-in socket))
- (babel:octets-to-string buffer
- :start 0
- :end bytes-read
- :encoding format)
- (subseq buffer 0 bytes-read))))
- (let ((*socket* socket))
- (on-socket-data (socket-driver socket) data))))
- (continue () nil)
- (drop-connection () (close socket :abort t))))))
+ (iolib:set-io-handler
+ (socket-event-base socket)
+ (iolib:socket-os-fd (socket-internal-socket socket))
+ :read (lambda (&rest ig)
+ (declare (ignore ig))
+ (handler-bind ((end-of-file (lambda (e &aux (*socket* socket))
+ (on-socket-end-of-file
+ (socket-driver socket))
+ (drop-connection e)))
+ (error
+ (lambda (e &aux (*socket* socket))
+ (on-socket-error (socket-driver socket) e))))
+ (restart-case
+ (let* ((buffer (socket-read-buffer socket))
+ (bytes-read
+ (nth-value
+ 1 (iolib:receive-from (socket-internal-socket socket) :buffer buffer))))
+ (when (zerop bytes-read)
+ (error 'end-of-file :stream socket))
+ (incf (socket-bytes-read socket) bytes-read)
+ (let ((data (if-let (format (socket-external-format-in socket))
+ (babel:octets-to-string buffer
+ :start 0
+ :end bytes-read
+ :encoding format)
+ (subseq buffer 0 bytes-read))))
+ (let ((*socket* socket))
+ (on-socket-data (socket-driver socket) data))))
+ (continue () nil)
+ (drop-connection () (close socket :abort t))))))
(setf (socket-reading-p socket) t)))
;;; Writing
Please sign in to comment.
Something went wrong with that request. Please try again.