2
我在調試一個使用emacs lisp作爲簡單的tcp客戶端的程序時遇到了麻煩。我把它簡化到最低限度,在這裏作爲一個問題呈現。這段代碼在Max OSX和Linux Centos機器上工作正常,但在windows上(全部使用Gnu emacs最新版本),從不會調用標記和過濾器進程的回調函數。阻塞連接工作,而非阻塞連接表示窗口上不支持,我可以忍受。服務器顯示客戶端連接正常並斷開連接;但似乎沒有輸出到服務器。最終服務器斷開連接。在Windows中make-network-process工作嗎?
任何想法?
(defvar *url-process* nil)
(defvar *url-state* nil)
(defvar *url-response* nil)
(defun url-buffer-message(process message)
"print a message to the url process buffer"
(save-excursion
(set-buffer (process-buffer process))
(insert message)))
(defun url-sentinel(process event)
"sentinal function for url network process which monitors for events"
(url-buffer-message process (format "sentinel event %s" event))
(cond
((string-match "open" event)
(setq *url-state* 'open))))
(defun url-filter(process string)
"filter function for url network process, which receives output"
(url-buffer-message process (format "filter %s" string)) ; debug
(setq *url-response* string))
(defun url-new-process(p)
(url-delete-process)
(setf *url-process* p))
(defun url-delete-process()
(when *url-process*
(delete-process *url-process*)
(setq *url-state* 'closed)))
(defun url-hai(host port blocking)
(setq *url-state* 'opening)
(url-new-process
(make-network-process :name "url"
:host host
:service port
:nowait (not blocking)
:filter #'url-filter
:sentinel #'url-sentinel
:buffer (get-buffer-create "*url*"))))
(defun url-kthxbye()
(url-delete-process))
(defun url-ping()
(if (and *url-process* (eq *url-state* 'open))
(process-send-string *url-process* "PING\r\n")))
(defun url-get()
(if (and *url-process* (eq *url-state* 'open))
(process-send-string *url-process* (format "GET /\r\n"))))
(defun url-info()
(if (and *url-process* (eq *url-state* 'open))
(process-send-string *url-process* "INFO\r\n")))
; usage
; (url-hai "127.0.0.1" 80 t)
; (url-hai "127.0.0.1" 80 nil)
; (url-get)
; (url-kthxbye)
不應該':nowait blocking' read':nowait(not blocking)'? – sanityinc
是的,你說得對。我在上面的代碼中切換了它 – justinhj