Class: GrpcKit::Session::ServerSession
- Inherits:
-
DS9::Server
- Object
- DS9::Server
- GrpcKit::Session::ServerSession
- Extended by:
- Forwardable
- Defined in:
- lib/grpc_kit/session/server_session.rb
Instance Method Summary collapse
- #drain ⇒ void
-
#initialize(io, dispatcher) ⇒ ServerSession
constructor
A new instance of ServerSession.
-
#run_once ⇒ bool
Return session can continue.
- #shutdown ⇒ void
- #start ⇒ void
Constructor Details
#initialize(io, dispatcher) ⇒ ServerSession
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/grpc_kit/session/server_session.rb', line 20 def initialize(io, dispatcher) super() # initialize DS9::Session @io = io @streams = {} @stop = false @dispatcher = dispatcher @peer_shutdowned = false @inflights = [] @drain = nil end |
Instance Method Details
#drain ⇒ void
86 87 88 |
# File 'lib/grpc_kit/session/server_session.rb', line 86 def drain @drain ||= GrpcKit::Session::DrainController.new end |
#run_once ⇒ bool
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/grpc_kit/session/server_session.rb', line 52 def run_once if @peer_shutdowned || @stop || !(want_read? || want_write?) # it could be called twice @streams.each_value(&:close) return false end if @drain if @streams.empty? shutdown return end @drain.call(self) end rs, ws = @io.select if !rs.empty? && want_read? do_read end if !ws.empty? && want_write? send end true rescue Errno::ECONNRESET, IOError => e GrpcKit.logger.debug(e.) shutdown false end |
#shutdown ⇒ void
91 92 93 94 95 96 |
# File 'lib/grpc_kit/session/server_session.rb', line 91 def shutdown stop @io.close rescue StandardError => e GrpcKit.logger.debug(e) end |
#start ⇒ void
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/grpc_kit/session/server_session.rb', line 33 def start loop do invoke if @streams.size == 0 unless @io.wait_readable shutdown break end end continue = run_once break unless continue end ensure GrpcKit.logger.debug('Finish server session') end |