Commit 6ef5fc31 authored by ehuelsmann's avatar ehuelsmann
Browse files

Make sockets clean up their associated wait-list, if closed correctly.

parent afe4b8c8
......@@ -63,6 +63,8 @@
;; because socket-streams are also sockets.
(defmethod socket-close ((usocket usocket))
"Close socket."
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(close (socket usocket))))
......
......@@ -245,6 +245,8 @@
;; (print (jcall (jmethod "java.net.BindException" "getMessage") native-exception))))
(defmethod socket-close ((usocket usocket))
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(jdi:do-jmethod (socket usocket) "close")))
......@@ -252,6 +254,8 @@
;; socket streams. Closing the stream flushes
;; its buffers *and* closes the socket.
(defmethod socket-close ((usocket stream-usocket))
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(close (socket-stream usocket))))
......
......@@ -96,10 +96,14 @@
;; are the same object
(defmethod socket-close ((usocket usocket))
"Close socket."
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(close (socket usocket))))
(defmethod socket-close ((usocket stream-server-usocket))
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(socket:socket-server-close (socket usocket)))
(defmethod get-local-name ((usocket usocket))
......@@ -227,6 +231,8 @@ and the address of the sender as values."
rv))
(defmethod socket-close ((usocket datagram-usocket))
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(rawsock:sock-close (socket usocket)))
)
......
......@@ -97,11 +97,15 @@
;; socket stream when closing a stream socket.
(defmethod socket-close ((usocket stream-usocket))
"Close socket."
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(close (socket-stream usocket))))
(defmethod socket-close ((usocket usocket))
"Close socket."
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(ext:close-socket (socket usocket))))
......
......@@ -117,9 +117,13 @@
;; are correctly flushed and the socket closed.
(defmethod socket-close ((usocket stream-usocket))
"Close socket."
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(close (socket-stream usocket)))
(defmethod socket-close ((usocket usocket))
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(comm::close-socket (socket usocket))))
......
......@@ -106,6 +106,8 @@
;; and their associated objects are represented
;; by the same object.
(defmethod socket-close ((usocket usocket))
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(close (socket usocket))))
......
......@@ -244,10 +244,14 @@
;; different objects. Be sure to close the stream (which
;; closes the socket too) when closing a stream-socket.
(defmethod socket-close ((usocket usocket))
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(sb-bsd-sockets:socket-close (socket usocket))))
(defmethod socket-close ((usocket stream-usocket))
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(close (socket-stream usocket))))
......
......@@ -69,11 +69,15 @@
;; are flushed and the socket is closed correctly afterwards.
(defmethod socket-close ((usocket usocket))
"Close socket."
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(ext:close-socket (socket usocket))))
(defmethod socket-close ((usocket stream-usocket))
"Close socket."
(when (wait-list usocket)
(remove-waiter (wait-list usocket) usocket))
(with-mapped-conditions (usocket)
(close (socket-stream usocket))))
......
......@@ -16,6 +16,10 @@
:initarg :socket
:accessor socket
:documentation "Implementation specific socket object instance.'")
(wait-list
:initform nil
:accessor wait-list
:documentation "WAIT-LIST the object is associated with.")
(state
:initform nil
:accessor state
......@@ -225,8 +229,8 @@ The `body' is an implied progn form."
;; Implementation specific:
;;
;; %setup-wait-list
;; add-waiter
;; remove-waiter
;; %add-waiter
;; %remove-waiter
(declaim (inline %setup-wait-list
%add-waiter
......@@ -241,17 +245,23 @@ The `body' is an implied progn form."
wl))
(defun add-waiter (wait-list input)
(setf (gethash (socket input) (wait-list-map wait-list)) input)
(setf (gethash (socket input) (wait-list-map wait-list)) input
(wait-list input) wait-list)
(pushnew input (wait-list-waiters wait-list))
(%add-waiter wait-list input))
(defun remove-waiter (wait-list input)
(%remove-waiter wait-list input)
(setf (wait-list-waiters wait-list)
(remove input (wait-list-waiters wait-list)))
(remove input (wait-list-waiters wait-list))
(wait-list input) nil)
(remhash (socket input) (wait-list-map wait-list)))
(defun remove-all-waiters (wait-list)
(dolist (waiter (wait-list-waiters wait-list))
(%remove-waiter waiter))
(setf (wait-list-waiters wait-list) nil)
(clrhash (wait-list-map wait-list)))
(defun wait-for-input (socket-or-sockets &key timeout ready-only)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment