Class: ZMQ::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/green/zmq.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Socket

Returns a new instance of Socket.



48
49
50
51
52
# File 'lib/green/zmq.rb', line 48

def initialize(*args)
  super
  fd, = [].tap { |a| getsockopt(ZMQ::FD, a) }
  @waiter = Green::ZMQ::Waiter.new fd
end

Instance Method Details

#brecvmsgObject



69
# File 'lib/green/zmq.rb', line 69

alias :brecvmsg :recvmsg

#bsendmsgObject



54
# File 'lib/green/zmq.rb', line 54

alias :bsendmsg :sendmsg

#closeObject



85
86
87
88
89
90
# File 'lib/green/zmq.rb', line 85

def close
  @waiter.cancel
  Green.hub.callback do
    original_close
  end
end

#original_closeObject



84
# File 'lib/green/zmq.rb', line 84

alias :original_close :close

#recvmsg(message, flags = 0) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/green/zmq.rb', line 70

def recvmsg(message, flags = 0)
  return brecvmsg(message, flags) if (flags & ZMQ::NonBlocking) != 0
  flags |= ZMQ::NonBlocking
  loop do
    rc = brecvmsg message, flags
    if rc == -1 && ZMQ::Util.errno == EAGAIN
      @waiter.lock
    else
      @waiter.wake
      return rc
    end
  end
end

#sendmsg(message, flags = 0) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/green/zmq.rb', line 55

def sendmsg(message, flags = 0)
  return bsendmsg(message, flags) if (flags & ZMQ::NonBlocking) != 0
  flags |= ZMQ::NonBlocking
  loop do
    rc = bsendmsg message, flags
    if rc == -1 && ZMQ::Util.errno == EAGAIN
      @waiter.lock
    else
      @waiter.wake
      return rc
    end
  end
end