zeromq / rbzmq

Ruby binding for 0MQ

Home Page:http://www.zeromq.org/bindings:ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid argument when try to bind

shiziwen opened this issue · comments

When I use zmq as a server, I met error "Invalid argument":
irb(main):001:0> require 'ffi-rzmq'
=> true
irb(main):002:0> context = ZMQ::Context.new
=> #<ZMQ::Context:0x00000002483cd8 @io_threads=1, @context=#<FFI::Pointer address=0x0000000265d210>>
irb(main):003:0> publisher = context.socket ZMQ::PUB
=> #<ZMQ::Socket:0x000000024911a8 @receiver_klass=ZMQ::Message, @socket=#<FFI::Pointer address=0x000000027500f0>, @name="PUB", @int_cache=nil, @longlong_cache=nil, @more_parts_array=[], @option_lookup=[nil, 1, nil, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, nil, nil, nil, nil, nil, 0, 0]>
irb(main):004:0> status = publisher.bind("tcp://127.0.0.1:5555")
=> -1

I use strace to get more information, I found below information:
socket(PF_INET, 0x80001 /* SOCK_??? */, IPPROTO_TCP) = -1 EINVAL (Invalid argument)

But in another machine, the same information is:
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 17

Then I tried another simple ruby httpserver:
require 'socket'
server = TCPServer.new("127.0.0.1", 5555)
loop do
socket = server.accept
while socket.gets.chop.length > 0
end
socket.puts "HTTP/1.1 200 OK"
socket.puts "Content-type: text/html"
socket.puts ""
socket.puts ""
socket.puts ""
socket.puts "

"
socket.puts "

#{Time.now}

"
socket.puts ""
socket.puts ""
socket.puts ""
socket.close
end

It works, and the strace information is :
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 5

I have tried many ways to fix this problem, but un-useful.

I need help, thanks.

Please report this bug against the ffi-rzmq project. This project is for a different extension.