Open GoogleCodeExporter opened 8 years ago
The patch below implements the enhancement, allowing passive tcp streams with
the port determined by the
OS. It can be implemented better by upgrading #'ot-conn-tcp-passive-connect.
(ccl:advise ot-conn-tcp-passive-connect
(destructuring-bind (conn port &optional (allow-reuse t)) arglist
(declare (ignore allow-reuse))
(if (eql port #$kOTAnyInetAddress)
;; Avoids registering a proxy for port 0 but instead registers one for the true port:
(multiple-value-bind (proxy result)
(let* ((*opentransport-class-proxies* NIL) ; makes ot-find-proxy return NIL
(result (:do-it)) ;; pushes onto *opentransport-class-proxies*
(proxy (prog1
(pop *opentransport-class-proxies*)
(assert (not *opentransport-class-proxies*))))
(context (cdr proxy))
(tmpconn (make-ot-conn :context context
:endpoint (pref context :ot-context.ref)))
(localaddress (ot-conn-tcp-get-addresses tmpconn)))
(declare (dynamic-extent tmpconn))
;; replace original set in body of function
(setf (ot-conn-local-address conn) localaddress)
(values
(cons localaddress context)
result))
;; need to be outside local binding of *opentransport-class-proxies*
(without-interrupts
(push proxy *opentransport-class-proxies*))
result)
(:do-it)))
:when :around :name 'ot-conn-tcp-passive-connect-any-address)
;; should not be zero after ot-conn-tcp-passive-connect-any-address advise:
(with-open-stream (stream (open-tcp-stream NIL #$kOTAnyInetAddress
:reuse-local-port-p nil))
(stream-local-port stream))
Original comment by terje.norderhaug
on 3 Jan 2010 at 9:41
Original issue reported on code.google.com by
terje.norderhaug
on 3 Jan 2010 at 9:36