私はCommonLispの新人です。iolibを使用してサーバーを作成すると、サーバーにtelnetで接続し、telnetを切断してサーバーをスローすることがわかりました。
不明なタイプ指定子:HANGUP
バックトレースを印刷すると、make-server-line-echoerのread-lineが実行されたときに表示されることがわかりました。そこでハンドラーケースを使用しますが、機能しません。何か助けはありますか?
これは私のコードです:
(ql:quickload 'iolib)
(defpackage :com.server.test
(:use :sockets :iomux :common-lisp))
(in-package :com.server.test)
(defvar *server-event-base* nil)
(defun make-server-line-echoer (socket)
(lambda (fd event exception)
(handler-case
(progn
(let ((line (read-line socket)))
(format t "Read ~A~%" line)
(format socket "~A~%" line)
(finish-output socket)))
(socket-connection-reset-error ()
(format t "Connection reset by peer~%")
(close socket))
(hangup ()
(format t "Client close connection on write~%")
(close socket))
(end-of-file ()
(format t "Client closed connection on read~%")
(close socket)))))
(defun make-server-listener-handler (socket)
(lambda (fd event exception)
(let ((client (accept-connection socket :wait t)))
(when client
(multiple-value-bind (who port)
(remote-name client)
(format t "Accept a client from ~A:~A~%" who port)
(set-io-handler *server-event-base*
(socket-os-fd client)
:read
(make-server-line-echoer
client)))))))
(defun run-server (&key port)
(setf *server-event-base* (make-instance 'event-base))
(let ((listener (make-socket :connect :passive
:address-family :internet
:type :stream
:ipv6 nil
:external-format '(:utf-8 :eol-style :crlf))))
(bind-address listener +ipv4-unspecified+ :port port :reuse-addr t)
(listen-on listener :backlog 5)
(format t "Listening on socket bound to: ~A:~A~%"
(local-host listener)
(local-port listener))
(set-io-handler *server-event-base*
(socket-os-fd listener)
:read
(make-server-listener-handler listener))
(handler-case
(event-dispatch *server-event-base*)
(socket-connection-reset-error ()
(format t "Connection reset by peer~%"))
(hangup ()
(format t "Client close connection on write~%"))
(end-of-file ()
(format t "Client closed connection on read~%")))
(format t "Close connection now~%")))
(run-server :port 3000)