chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] zmq, problems with using several sockets, closing socket


From: Matt Welland
Subject: [Chicken-users] zmq, problems with using several sockets, closing sockets
Date: Thu, 1 Nov 2012 00:15:02 -0700

I have a zmq pub/req client server and everything is working great, nice and fast etc.

However I need to ping servers to see if they are alive so I wrote a little code to try and connect to the server and return yay/nay. The problem I have is that if I don't close the socket (I'm pinging a number of servers) I get crashes. If I do close the socket I get this:

INFO: (0) connected as client

Warning: in finalizer: (close-socket) Socket operation on non-socket: 88

    Call history:

    configf.scm:42: filter     
    configf.scm:43: append     

====for what its worth here is the server ping code======
;; ping a server and return number of clients or #f (if no response)
(define (server:ping host port #!key (secs 10))
  (cdb:use-non-blocking-mode
   (lambda ()
     (let* ((res #f)
        (th1 (make-thread
          (lambda ()
            (let ((zmq-socket (server:client-connect host port)))
              (if zmq-socket
              (if (server:client-login zmq-socket)
                  (let ((numclients (cdb:num-clients zmq-socket)))
                (server:client-logout zmq-socket)
                (close-socket  zmq-socket)
                (set! res (list #t numclients)))
                  (begin
                ;; (close-socket zmq-socket)
                (set! res (list #f "CAN'T LOGIN"))))
              (set! res (list #f "CAN'T CONNECT")))))))
        (th2 (make-thread
          (lambda ()
            (let loop ((count 1))
              (debug:print-info 1 "Ping " count " server on " host " at port " port)
              (thread-sleep! 2)
              (if (< count (/ secs 2))
              (loop (+ count 1))))
            ;; (thread-terminate! th1)
            (set! res (list #f "TIMED OUT"))))))
       (thread-start! th2)
       (thread-start! th1)
       (handle-exceptions
    exn
    (set! res (list #f "TIMED OUT"))
    (thread-join! th1 secs))
       res))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]