Skip to content

Commit

Permalink
[LW] SOCKET-CONNECT now supports setting "tcp_nodelay" in all version…
Browse files Browse the repository at this point in the history
…s (4/5/6/7)
  • Loading branch information
binghe committed Oct 25, 2016
1 parent 36f6f56 commit 56bb4f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
19 changes: 11 additions & 8 deletions backend/lispworks.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,8 @@
(error "cannot create socket"))))))

(defun socket-connect (host port &key (protocol :stream) (element-type 'base-char)
timeout deadline (nodelay t nodelay-specified)
timeout deadline (nodelay t)
local-host local-port)

;; What's the meaning of this keyword?
(when deadline
(unimplemented 'deadline 'socket-connect))
Expand All @@ -395,11 +394,6 @@
(when timeout
(unsupported 'timeout 'socket-connect :minimum "LispWorks 4.4.5"))

#+(or lispworks4 lispworks5.0) ; < 5.1
(when (and nodelay-specified
(not (eq nodelay :if-supported)))
(unsupported 'nodelay 'socket-connect :minimum "LispWorks 5.1"))

#+lispworks4
(when local-host
(unsupported 'local-host 'socket-connect :minimum "LispWorks 5.0"))
Expand All @@ -411,7 +405,7 @@
(:stream
(let ((hostname (host-to-hostname host))
(stream))
(setf stream
(setq stream
(with-mapped-conditions ()
(comm:open-tcp-stream hostname port
:element-type element-type
Expand All @@ -425,6 +419,15 @@
#-(or lispworks4 lispworks5.0) ; >= 5.1
#-(or lispworks4 lispworks5.0)
:nodelay nodelay)))

;; Then handle `nodelay' separately for older versions <= 5.0
#+(or lispworks4 lispworks5.0)
(when (and stream nodelay)
(#+lispworks4 set-socket-tcp-nodelay
#+lispworks5.0 comm::set-socket-tcp-nodelay
(comm:socket-stream-socket stream)
(bool->int nodelay))) ; ":if-supported" maps to 1 too.

(if stream
(make-stream-socket :socket (comm:socket-stream-socket stream)
:stream stream)
Expand Down
5 changes: 0 additions & 5 deletions option.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

(in-package :usocket)

;;; Small utility functions
(declaim (inline bool->int) (inline int->bool))
(defun bool->int (bool) (if bool 1 0))
(defun int->bool (int) (= 1 int))

;;; Interface definition

(defgeneric socket-option (socket option &key)
Expand Down
7 changes: 7 additions & 0 deletions usocket.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -683,3 +683,10 @@ streams to be created by `socket-accept'. `reuseaddress' is supported for
backward compatibility (but deprecated); when both `reuseaddress' and
`reuse-address' have been specified, the latter takes precedence.
")

;;; Small utility functions mapping true/false to 1/0, moved here from option.lisp

(proclaim '(inline bool->int int->bool))

(defun bool->int (bool) (if bool 1 0))
(defun int->bool (int) (= 1 int))

0 comments on commit 56bb4f3

Please sign in to comment.