Class: Pione::DRbPatch::PioneTCPSocket

Inherits:
DRb::DRbTCPSocket
  • Object
show all
Defined in:
lib/pione/patch/drb-patch.rb

Overview

+PioneTCPSocket+ is a reply reader thread extension for standard +DRbTCPSocket+.

Instance Method Summary collapse

Constructor Details

#initialize(uri, soc, config = {}) ⇒ PioneTCPSocket

Returns a new instance of PioneTCPSocket.



73
74
75
76
# File 'lib/pione/patch/drb-patch.rb', line 73

def initialize(uri, soc, config={})
  super
  @reply_reader = ReplyReader.new
end

Instance Method Details

#alive?Boolean

Return true if connection socket exists.

Returns:

  • (Boolean)


104
105
106
# File 'lib/pione/patch/drb-patch.rb', line 104

def alive?
  return (@socket and not(@socket.closed?))
end

#send_reply(req_id, succ, result) ⇒ Object

Send the reply with request id. Note: this overrides original +send_rely+.



99
100
101
# File 'lib/pione/patch/drb-patch.rb', line 99

def send_reply(req_id, succ, result)
  @msg.send_reply(req_id, stream, succ, result)
end

#send_request(ref, msg_id, arg, b) ⇒ Object

Send the request from client to server.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/pione/patch/drb-patch.rb', line 79

def send_request(ref, msg_id, arg, b)
  # set watcher
  @reply_reader.add_watcher(Thread.current)

  # send the request
  req_id = @msg.send_request(stream, ref, msg_id, arg, b)

  # start reply reader
  @reply_reader.start(self)

  # wait the reply by using watier table
  succ, result = Pione::DRbPatch.waiter_table.take(req_id, msg_id, arg)

  # remove watcher
  @reply_reader.remove_watcher(Thread.current)

  return succ, result
end