How to check if the connection is still open?

Issue #3 wontfix
Eugen GFu created an issue

Hi Kaspar,

I discovered this library today and it looks quite simple and easy to use from the ruby interface. However, I would like to check for messages until the connection drops. Now, I dont see a method which can give me the status of the connection. Is there probably a workaround?

As code, I would like to implement something like this:

sock = NanoMsg::PairSocket.new
sock.connect("ipc:///tmp/myendpoint.ipc")

while(sock.is_open)
    res=sock.recv
    ...process res....
end

Thanks a lot in advance!

Eugen

Comments (3)

  1. Eugen GFu reporter

    My current work around is now like this:

        sock = NanoMsg::PairSocket.new
        # passing direct integers read from https://github.com/nanomsg/nanomsg/blob/5515f964c3c5e01ca702ecb4d8ef0856d27a095c/src/nn.h
        # and this doc: https://github.com/nanomsg/nanomsg/blob/master/doc/nn_setsockopt.txt
        sock.setsockopt(0,5,timeout_ms) #params: first. 0: NN_SOL_SOCKET;  second. NN_RCVTIMEO; third parameter: timeout in ms
        sock.connect(endpoint)
    
        begin
          res=sock.resc()
          ... process res ....
        rescue NanoMsg::Errno::EAGAIN #catches time out errors
          puts "Timeout..."
        end
    

    However, I have not found the constants I am passing to the setsockop function. Is it possible to use something like NanoMsg::NN_SOL_SOCKET and NanoMsg::NN_RCVTIMEO ?

  2. Kaspar Schiess repo owner

    AFAIK, you cannot explicitly test nanomsg sockets for 'open?' - and so the library cannot either.

    You can use all setsockopts; for example this should work:

    @q.setsockopt(NanoMsg::NN_SOL_SOCKET, NanoMsg::NN_RCVTIMEO, 5000)
    
  3. Kaspar Schiess repo owner

    This was more of a question. I think the answer is sufficient and the library is fine, really.

  4. Log in to comment