Unverified Commit 8175f485 authored by Eugene Zaikonnikov's avatar Eugene Zaikonnikov Committed by GitHub
Browse files

Socket keepalive (#73)

* add TCP keepalive option set
* add SO_KEEPALIVE handling for LispWorks
* add TCP keepalive options for various implementations
parent b9a27398
......@@ -106,6 +106,11 @@
#+linux 6
"Socket broadcast")
(defconstant *sockopt_so_keepalive*
#-linux #x0008
#+linux 9
"Socket keepalive")
;;; ssize_t
;;; recvfrom(int socket, void *restrict buffer, size_t length, int flags,
;;; struct sockaddr *restrict address, socklen_t *restrict address_len);
......@@ -317,6 +322,33 @@
(fli:size-of :int)))
new-value)))
(defun get-socket-keepalive (socket-fd)
"Get socket option: SO_KEEPALIVE, return value is a fixnum (0 or 1)"
(declare (type integer socket-fd))
(fli:with-dynamic-foreign-objects ((zero-or-one :int)
(len :int))
(if (zerop (comm::getsockopt socket-fd
comm::*sockopt_sol_socket*
*sockopt_so_keepalive*
(fli:copy-pointer zero-or-one
:type '(:pointer #+win32 :char #-win32 :void))
len))
zero-or-one 0)))
(defun set-socket-keepalive (socket-fd new-value)
"Set socket option: SO_KEEPALIVE, argument is a fixnum (0 or 1)"
(declare (type integer socket-fd)
(type (integer 0 1) new-value))
(fli:with-dynamic-foreign-objects ((zero-or-one :int))
(setf (fli:dereference zero-or-one) new-value)
(when (zerop (comm::setsockopt socket-fd
comm::*sockopt_sol_socket*
*sockopt_so_keepalive*
(fli:copy-pointer zero-or-one
:type '(:pointer #+win32 :char #-win32 :void))
(fli:size-of :int)))
new-value)))
(defun initialize-dynamic-sockaddr (hostname service protocol &aux (original-hostname hostname))
(declare (ignorable original-hostname))
#+(or lispworks4 lispworks5 lispworks6.0)
......
......@@ -349,5 +349,75 @@
() ; TODO
new-value))
;;; Socket option: TCP-KEEPALIVE (SO_KEEPALIVE)
(defmethod socket-option ((usocket stream-usocket)
(option (eql :tcp-keepalive)) &key)
(declare (ignorable option))
(socket-option usocket :tcp-keepalive))
(defmethod socket-option ((usocket stream-usocket)
(option (eql :tcp-keepalive)) &key)
(declare (ignorable option))
(let ((socket (socket usocket)))
(declare (ignorable socket))
#+abcl
() ; TODO
#+allegro
() ; TODO
#+clisp
() ; TODO
#+clozure
() ; TODO
#+cmu
()
#+(or ecl clasp)
(sb-bsd-sockets::sockopt-keep-alive socket)
#+lispworks
(int->bool (get-socket-keepalive socket))
#+mcl
() ; TODO
#+mocl
() ; unknown
#+sbcl
(sb-bsd-sockets:sockopt-keep-alive socket)
#+scl
())) ; TODO
(defmethod (setf socket-option) (new-value (usocket stream-usocket)
(option (eql :tcp-keepalive)) &key)
(declare (ignorable option))
(setf (socket-option usocket :tcp-keepalive) new-value))
(defmethod (setf socket-option) (new-value (usocket stream-usocket)
(option (eql :tcp-keepalive)) &key)
(declare (type boolean new-value)
(ignorable new-value option))
(let ((socket (socket usocket)))
(declare (ignorable socket))
#+abcl
() ; TODO
#+allegro
() ; TODO
#+clisp
() ; TODO
#+clozure
(ccl::set-socket-options socket :keepalive new-value)
#+cmu
()
#+(or ecl clasp)
(setf (sb-bsd-sockets::sockopt-keep-alive socket) new-value)
#+lispworks
(set-socket-keepalive socket (bool->int new-value))
#+mcl
() ; TODO
#+mocl
() ; unknown
#+sbcl
(setf (sb-bsd-sockets:sockopt-keep-alive socket) new-value)
#+scl
() ; TODO
new-value))
(eval-when (:load-toplevel :execute)
(export 'socket-option))
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