(deftest No-offset-Lenght-width-two-No-adjustment-no-strip
(testing "2 bytes length field at offset 0, do not strip header"
(ok (equalp (let ((enc-config (cl-frame:make-encoder-config :byte-order cl-frame:big-endian
:length-field-length 2
:length-adjustment 0
:length-includes-length-field-length nil))
(dec-config (cl-frame:make-decoder-config :byte-order cl-frame:big-endian
:length-field-offset 0
:length-field-length 2
:length-adjustment 0
:initial-bytes-to-strip 0))
(msg (flexi-streams:string-to-octets "HELLO, WORLD"))
(listening nil))
(bt:make-thread (lambda ()
(usocket:with-socket-listener (listener "localhost" 1990 :element-type '(unsigned-byte 8))
(setf listening t)
(let ((conn (usocket:socket-accept listener :element-type '(unsigned-byte 8))))
(unwind-protect (progn
(cl-frame:write-frame (make-instance 'cl-frame:length-field-based-frame-codec
:encoder-config enc-config
:decoder-config dec-config
:iostream (usocket:socket-stream conn))
msg))
(usocket:socket-close conn)))
(usocket:socket-close listener)
)))
(loop
when (equal listening t)
return (usocket:with-client-socket (socket stream "localhost" 1990 :element-type '(unsigned-byte 8))
(unwind-protect
(cl-frame:read-frame (make-instance 'cl-frame:length-field-based-frame-codec :encoder-config enc-config
:decoder-config dec-config
:iostream stream))
(usocket:socket-close socket))
)
))
(let ((head (make-array 2 :element-type '(unsigned-byte 8)))
(body (flexi-streams:string-to-octets "HELLO, WORLD"))
(result))
(cl-frame:put-uint16 cl-frame:big-endian head 12)
(setf result (concatenate 'vector head body))
result))
"2 bytes length field at offset 0, do not strip header")
))
最近想写个协议封装的库来着,但是在写测试的时候。我发现被usocket:socket-close的socket仍然会占用地址。有没有大佬能指点一番。