开发者

Does make-network-process work in windows?

I'm having trouble debugging a program that uses emacs lisp to act as a simple tcp client. I've stripped it down to the minimum to present as a question here. This code works fine on Max OSX and on a Linux Centos machine, but on windows (all with Gnu emacs recent version) the callback functions for the sentinel and filter process are never called. The blocking connect works whereas the non-blocking connect says non supported on windows, which I can live with. The server is showing that the client connects and disconnects fine; but no output seems to make it to the server. Eventually the server disconnects.

Any ideas?

(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 
    (s开发者_如何学Cet-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)


The problem here was related to make-network-process

When calling this function with :nowait set to nil to make the call synchronous/blocking the sentinel function is never called with the state 'open'. Sadly I was relying on that behavior, and in my functions which send data I check for whether the connection is open yet.

Once I discovered that the fix was obvious; just set the state to 'open if the make-network-process function succeeds and it's a blocking call. Working code below:

(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-delete-process)
  (let ((p 
     (make-network-process :name "url"
                   :host host
                   :service port
                   :nowait (not blocking)
                   :filter #'url-filter
                   :sentinel #'url-sentinel
                   :buffer (get-buffer-create "*url*"))))
    (if p 
    (progn
      (if blocking 
          (setf *url-state* 'open))
      (setf *url-process* p)))))

(defun url-kthxbye()
  (url-delete-process))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜