Class: DRb::DRbWebSocket::ClientSide

Inherits:
Object
  • Object
show all
Defined in:
lib/drb/drb_websocket.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri, config) ⇒ ClientSide

Returns a new instance of ClientSide.



176
177
178
179
180
181
182
# File 'lib/drb/drb_websocket.rb', line 176

def initialize(uri, config)
  @uri = uri
  @pool = SocketPool.open(uri)
  @res = nil
  @config = config
  @msg = DRbMessage.new(@config)
end

Instance Method Details

#alive?Boolean

Returns:

  • (Boolean)


184
185
186
# File 'lib/drb/drb_websocket.rb', line 184

def alive?
  !!@pool.ws && @pool.ws.open?
end

#closeObject



188
189
# File 'lib/drb/drb_websocket.rb', line 188

def close
end

#recv_reply(reply_stream) ⇒ Object



197
198
199
# File 'lib/drb/drb_websocket.rb', line 197

def recv_reply(reply_stream)
  @msg.recv_reply(reply_stream)
end

#send(uri, data, &block) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/drb/drb_websocket.rb', line 201

def send(uri, data, &block)
  @pool.send(data) do |message|
    reply_stream = StrStream.new
    reply_stream.write(message.to_s)

    if @config[:load_limit] < reply_stream.buf.size
      raise TypeError, 'too large packet'
    end

    block.call reply_stream
  end
end

#send_request(ref, msg_id, *arg, b, &block) ⇒ Object



191
192
193
194
195
# File 'lib/drb/drb_websocket.rb', line 191

def send_request(ref, msg_id, *arg, b, &block)
  stream = StrStream.new
  @msg.send_request(stream, ref, msg_id, *arg, b)
  send(@uri, stream.buf, &block)
end