经过一番折腾,我想出了以下解决方案:
在我的源文件中,在我声明我的包之后,编译/加载适当的模块,但在我在我的包中声明任何内容之前,我添加了以下代码:
(defmethod sb-bsd-sockets:socket-make-stream ((socket sb-bsd-sockets:socket)
&key input output
(element-type 'character)
(buffering :full)
(external-format :default)
timeout
(auto-close t))
"Default method for SOCKET objects. An ELEMENT-TYPE of :DEFAULT
will construct a bivalent stream. Acceptable values for BUFFERING
are :FULL, :LINE and :NONE. Streams will have no TIMEOUT
by default.
The stream for SOCKET will be cached, and a second invocation of this
method will return the same stream. This may lead to oddities if this
function is invoked with inconsistent arguments \(e.g., one might request
an input stream and get an output stream in response\)."
(let ((stream
(and (slot-boundp socket 'stream) (slot-value socket 'stream))))
(unless stream
(setf stream (sb-sys:make-fd-stream
(sb-bsd-sockets:socket-file-descriptor socket)
:name "a socket"
:dual-channel-p t
:input input
:output output
:element-type element-type
:buffering buffering
:external-format external-format
:timeout timeout
:auto-close auto-close)))
(setf (slot-value socket 'stream) stream)
(sb-ext:cancel-finalization socket)
stream))
(这基本上是sb-bsd-sockets/socket.lisp
与将auto-close
键添加到参数列表中的内容相比的提升)
这样我就避免了修改或修补系统文件,并且基本上直接挂钩到 sb-bsd-sockets 包中。
到目前为止,它似乎正在正常工作。通过连续调用的基本测试(room)
表明我没有明显的内存泄漏,并且性能符合预期。
如果您认为它可能会以意想不到的方式影响我的系统的稳定性,请随时对此进行评论。