bayserver-core 2.3.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/lib/baykit/bayserver/agent/accept_handler.rb +0 -26
  3. data/lib/baykit/bayserver/agent/channel_listener.rb +6 -6
  4. data/lib/baykit/bayserver/agent/command_receiver.rb +97 -38
  5. data/lib/baykit/bayserver/agent/grand_agent.rb +444 -134
  6. data/lib/baykit/bayserver/agent/letter.rb +30 -0
  7. data/lib/baykit/bayserver/agent/lifecycle_listener.rb +9 -7
  8. data/lib/baykit/bayserver/agent/monitor/grand_agent_monitor.rb +298 -0
  9. data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer.rb +257 -0
  10. data/lib/baykit/bayserver/agent/multiplexer/job_multiplexer_base.rb +52 -0
  11. data/lib/baykit/bayserver/agent/multiplexer/multiplexer_base.rb +150 -0
  12. data/lib/baykit/bayserver/agent/multiplexer/plain_transporter.rb +129 -0
  13. data/lib/baykit/bayserver/agent/multiplexer/rudder_state.rb +81 -0
  14. data/lib/baykit/bayserver/agent/multiplexer/secure_transporter.rb +50 -0
  15. data/lib/baykit/bayserver/agent/multiplexer/spider_multiplexer.rb +561 -0
  16. data/lib/baykit/bayserver/agent/multiplexer/spin_multiplexer.rb +311 -0
  17. data/lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb +194 -0
  18. data/lib/baykit/bayserver/agent/multiplexer/transporter.rb +61 -0
  19. data/lib/baykit/bayserver/agent/multiplexer/write_unit.rb +30 -0
  20. data/lib/baykit/bayserver/agent/non_blocking_handler.rb +0 -319
  21. data/lib/baykit/bayserver/agent/signal/signal_agent.rb +2 -1
  22. data/lib/baykit/bayserver/agent/timer_handler.rb +1 -1
  23. data/lib/baykit/bayserver/agent/transporter/data_listener.rb +7 -7
  24. data/lib/baykit/bayserver/agent/transporter/package.rb +0 -3
  25. data/lib/baykit/bayserver/agent/transporter/transporter.rb +5 -139
  26. data/lib/baykit/bayserver/bay_log.rb +1 -0
  27. data/lib/baykit/bayserver/bayserver.rb +32 -28
  28. data/lib/baykit/bayserver/{util → common}/groups.rb +1 -1
  29. data/lib/baykit/bayserver/common/inbound_handler.rb +12 -0
  30. data/lib/baykit/bayserver/{docker/base → common}/inbound_ship.rb +94 -19
  31. data/lib/baykit/bayserver/{docker/base → common}/inbound_ship_store.rb +7 -9
  32. data/lib/baykit/bayserver/common/multiplexer.rb +98 -0
  33. data/lib/baykit/bayserver/common/postpone.rb +15 -0
  34. data/lib/baykit/bayserver/common/read_only_ship.rb +42 -0
  35. data/lib/baykit/bayserver/common/recipient.rb +24 -0
  36. data/lib/baykit/bayserver/common/vehicle.rb +24 -0
  37. data/lib/baykit/bayserver/common/vehicle_runner.rb +127 -0
  38. data/lib/baykit/bayserver/{docker/warp → common}/warp_data.rb +18 -10
  39. data/lib/baykit/bayserver/common/warp_handler.rb +27 -0
  40. data/lib/baykit/bayserver/{docker/warp → common}/warp_ship.rb +107 -27
  41. data/lib/baykit/bayserver/{docker/warp → common}/warp_ship_store.rb +3 -8
  42. data/lib/baykit/bayserver/docker/base/inbound_data_listener.rb +2 -2
  43. data/lib/baykit/bayserver/docker/base/port_base.rb +59 -27
  44. data/lib/baykit/bayserver/docker/{warp/warp_docker.rb → base/warp_base.rb} +43 -50
  45. data/lib/baykit/bayserver/docker/built_in/built_in_harbor_docker.rb +118 -31
  46. data/lib/baykit/bayserver/docker/built_in/built_in_log_docker.rb +60 -63
  47. data/lib/baykit/bayserver/docker/built_in/built_in_permission_docker.rb +11 -10
  48. data/lib/baykit/bayserver/docker/built_in/built_in_secure_docker.rb +13 -4
  49. data/lib/baykit/bayserver/docker/city.rb +27 -13
  50. data/lib/baykit/bayserver/docker/club.rb +8 -8
  51. data/lib/baykit/bayserver/docker/docker.rb +9 -1
  52. data/lib/baykit/bayserver/docker/harbor.rb +184 -22
  53. data/lib/baykit/bayserver/docker/permission.rb +7 -6
  54. data/lib/baykit/bayserver/docker/port.rb +39 -11
  55. data/lib/baykit/bayserver/docker/secure.rb +11 -9
  56. data/lib/baykit/bayserver/docker/send_file/file_content_handler.rb +99 -4
  57. data/lib/baykit/bayserver/docker/send_file/send_file_docker.rb +6 -2
  58. data/lib/baykit/bayserver/docker/send_file/send_file_ship.rb +92 -0
  59. data/lib/baykit/bayserver/docker/town.rb +31 -15
  60. data/lib/baykit/bayserver/docker/trouble.rb +17 -5
  61. data/lib/baykit/bayserver/docker/warp.rb +34 -0
  62. data/lib/baykit/bayserver/mem_usage.rb +9 -9
  63. data/lib/baykit/bayserver/protocol/command_packer.rb +1 -8
  64. data/lib/baykit/bayserver/protocol/packet_packer.rb +7 -11
  65. data/lib/baykit/bayserver/protocol/packet_store.rb +4 -4
  66. data/lib/baykit/bayserver/protocol/protocol_handler.rb +26 -8
  67. data/lib/baykit/bayserver/protocol/protocol_handler_store.rb +5 -5
  68. data/lib/baykit/bayserver/rudders/io_rudder.rb +62 -0
  69. data/lib/baykit/bayserver/rudders/rudder.rb +29 -0
  70. data/lib/baykit/bayserver/{watercraft → ships}/ship.rb +65 -41
  71. data/lib/baykit/bayserver/taxi/taxi.rb +15 -10
  72. data/lib/baykit/bayserver/taxi/taxi_runner.rb +9 -94
  73. data/lib/baykit/bayserver/tours/read_file_taxi.rb +2 -2
  74. data/lib/baykit/bayserver/tours/req_content_handler.rb +16 -13
  75. data/lib/baykit/bayserver/tours/tour.rb +2 -2
  76. data/lib/baykit/bayserver/tours/tour_handler.rb +36 -0
  77. data/lib/baykit/bayserver/tours/tour_req.rb +14 -24
  78. data/lib/baykit/bayserver/tours/tour_res.rb +5 -89
  79. data/lib/baykit/bayserver/tours/tour_store.rb +5 -5
  80. data/lib/baykit/bayserver/train/train_runner.rb +17 -13
  81. data/lib/baykit/bayserver/util/data_consume_listener.rb +1 -1
  82. data/lib/baykit/bayserver/util/executor_service.rb +11 -7
  83. data/lib/baykit/bayserver/util/ip_matcher.rb +9 -39
  84. data/lib/baykit/bayserver/util/locale.rb +1 -1
  85. data/lib/baykit/bayserver/util/selector.rb +24 -5
  86. data/lib/baykit/bayserver/util/sys_util.rb +6 -6
  87. data/lib/baykit/bayserver/version.rb +1 -1
  88. metadata +37 -18
  89. data/lib/baykit/bayserver/agent/grand_agent_monitor.rb +0 -231
  90. data/lib/baykit/bayserver/agent/transporter/plain_transporter.rb +0 -55
  91. data/lib/baykit/bayserver/agent/transporter/secure_transporter.rb +0 -81
  92. data/lib/baykit/bayserver/docker/base/inbound_handler.rb +0 -42
  93. data/lib/baykit/bayserver/docker/warp/package.rb +0 -4
  94. data/lib/baykit/bayserver/docker/warp/warp_data_listener.rb +0 -112
  95. data/lib/baykit/bayserver/docker/warp/warp_handler.rb +0 -38
  96. /data/lib/baykit/bayserver/{util → common}/cities.rb +0 -0
@@ -0,0 +1,561 @@
1
+ require 'baykit/bayserver/common/recipient'
2
+ require 'baykit/bayserver/rudders/rudder'
3
+ require 'baykit/bayserver/rudders/io_rudder'
4
+
5
+ require 'baykit/bayserver/agent/multiplexer/multiplexer_base'
6
+ require 'baykit/bayserver/agent/multiplexer/write_unit'
7
+ require 'baykit/bayserver/agent/timer_handler'
8
+
9
+ module Baykit
10
+ module BayServer
11
+ module Agent
12
+ module Multiplexer
13
+ class SpiderMultiplexer < Baykit::BayServer::Agent::Multiplexer::MultiplexerBase
14
+ include Baykit::BayServer::Agent::TimerHandler #implements
15
+ include Baykit::BayServer::Common::Recipient # implements
16
+ include Baykit::BayServer::Agent::Multiplexer
17
+
18
+ include Baykit::BayServer::Rudders
19
+ include Baykit::BayServer::Util
20
+
21
+ class ChannelOperation
22
+
23
+ attr :rudder
24
+ attr_accessor :op
25
+ attr_accessor :to_connect
26
+ attr_accessor :to_close
27
+
28
+
29
+ def initialize(rd, op, to_connect, to_close)
30
+ @rudder = rd
31
+ @op = op
32
+ @to_connect = to_connect
33
+ @to_close = to_close
34
+ end
35
+ end
36
+
37
+ attr :anchorable
38
+ attr :selector
39
+ attr :operations
40
+ attr :operations_lock
41
+ attr :select_wakeup_pipe
42
+ attr :handshaked
43
+
44
+ def initialize(agt, anchorable)
45
+ super(agt)
46
+ @anchorable = anchorable
47
+ @operations = []
48
+ @operations_lock = Mutex.new
49
+ @selector = Selector.new
50
+ @select_wakeup_pipe = IO.pipe
51
+ @selector.register(@select_wakeup_pipe[0], Selector::OP_READ)
52
+
53
+ @agent.add_timer_handler(self)
54
+ @handshaked = false
55
+ end
56
+ def to_s
57
+ return "SpdMpx[" + @agent.to_s + "]"
58
+ end
59
+
60
+
61
+ #########################################
62
+ # Implements Multiplexer
63
+ #########################################
64
+
65
+ def req_accept(rd)
66
+ st = get_rudder_state(rd)
67
+ selector.register(rd.io, Selector::OP_READ)
68
+ st.accepting = true
69
+ end
70
+
71
+ def req_connect(rd, adr)
72
+ st = get_rudder_state(rd)
73
+ BayLog.debug("%s reqConnect adr=%s rd=%s chState=%s", @agent, adr.canonname, rd, st)
74
+
75
+ rd.set_non_blocking
76
+
77
+ begin
78
+ rd.io.connect(adr)
79
+ rescue IO::WaitWritable => e
80
+ #BayLog.error_e(e)
81
+ end
82
+
83
+ st.connecting = true
84
+ add_operation(rd, Selector::OP_WRITE, true)
85
+ end
86
+
87
+ def req_read(rd)
88
+ st = get_rudder_state(rd)
89
+ BayLog.debug("%s reqRead st=%s", @agent, st);
90
+
91
+ add_operation(rd, Selector::OP_READ)
92
+
93
+ if st != nil
94
+ st.access
95
+ end
96
+ end
97
+
98
+ def req_write(rd, buf,adr, tag, lis)
99
+ st = get_rudder_state(rd)
100
+ BayLog.debug("%s req write st=%s tag=%s", @agent, st, tag)
101
+
102
+ if st == nil || st.closed
103
+ BayLog.warn("%s Channel is closed: %s", @agent, rd)
104
+ return
105
+ end
106
+
107
+ unt = WriteUnit.new(buf, adr, tag, lis)
108
+ st.writing_lock.synchronize do
109
+ st.write_queue << unt
110
+ end
111
+
112
+ add_operation(rd, Selector::OP_WRITE)
113
+
114
+ st.access
115
+ end
116
+
117
+ def req_end(rd)
118
+ st = get_rudder_state(rd)
119
+ if st == nil
120
+ return
121
+ end
122
+
123
+ st.end
124
+ st.access
125
+ end
126
+
127
+ def req_close(rd)
128
+ st = get_rudder_state(rd)
129
+ BayLog.debug("%s reqClose rd=%s", @agent, rd);
130
+
131
+ if st == nil
132
+ BayLog.warn("%s channel state not found: %s", @agent, rd)
133
+ return
134
+ end
135
+
136
+ st.closing = true
137
+ add_operation(rd, Selector::OP_WRITE, false, true)
138
+
139
+ st.access
140
+ end
141
+
142
+
143
+ def shutdown
144
+ wakeup
145
+ end
146
+
147
+ def is_non_blocking
148
+ return true
149
+ end
150
+
151
+ def use_async_api
152
+ return false
153
+ end
154
+
155
+
156
+ def cancel_read(st)
157
+ @selector.unregister(st.rudder.io)
158
+ end
159
+
160
+ def cancel_write(st)
161
+ op = @selector.get_op(st.rudder.io) & ~Selector::OP_WRITE
162
+ # Write OP off
163
+ if op != Selector::OP_READ
164
+ @selector.unregister(st.rudder.io)
165
+ else
166
+ @selector.modify(st.rudder.io, op)
167
+ end
168
+ end
169
+
170
+ def next_accept(st)
171
+ end
172
+
173
+ def next_read(st)
174
+ end
175
+
176
+ def next_write(st)
177
+ end
178
+
179
+ def close_rudder(st)
180
+ @selector.unregister(st.rudder.io)
181
+ super
182
+ end
183
+
184
+
185
+ def on_busy
186
+ BayLog.debug("%s onBusy", agent)
187
+ BayServer::anchorable_port_map.keys.each do |rd|
188
+ @selector.unregister(rd.io)
189
+ st = get_rudder_state(rd)
190
+ st.accepting = false
191
+ end
192
+ end
193
+
194
+ def on_free
195
+ BayLog.debug("%s onFree aborted=%s", agent, agent.aborted);
196
+ if agent.aborted
197
+ return
198
+ end
199
+
200
+ BayServer.anchorable_port_map.keys.each do |rd|
201
+ req_accept(rd)
202
+ end
203
+ end
204
+
205
+ #########################################
206
+ # Implements TimerHandler
207
+ #########################################
208
+
209
+ def on_timer
210
+ close_timeout_sockets
211
+ end
212
+ #########################################
213
+ # Implements Recipient
214
+ #########################################
215
+
216
+ #
217
+ # Receive letters
218
+ #
219
+ def receive(wait)
220
+ if not wait
221
+ selected_map = @selector.select()
222
+ else
223
+ selected_map = @selector.select(GrandAgent::SELECT_TIMEOUT_SEC)
224
+ end
225
+ #BayLog.debug("%s selected: %s", self, selected_map)
226
+
227
+ register_channel_ops
228
+
229
+ selected_map.keys.each do |io|
230
+ if io == @select_wakeup_pipe[0]
231
+ # Waked up by req_*
232
+ on_waked_up
233
+ else
234
+ handle_channel(io, selected_map[io])
235
+ end
236
+ end
237
+
238
+ return !selected_map.empty?
239
+ end
240
+
241
+ #
242
+ # Wake up the recipient
243
+ #
244
+ def wakeup
245
+ IOUtil.write_int32(@select_wakeup_pipe[1], 0)
246
+ end
247
+
248
+ private
249
+ def add_operation(rd, op, to_connect=false, to_close=false)
250
+ @operations_lock.synchronize do
251
+ found = false
252
+ @operations.each do |ch_op|
253
+ if ch_op.rudder == rd
254
+ ch_op.op |= op
255
+ ch_op.to_close = (ch_op.to_close or to_close)
256
+ ch_op.to_connect = (ch_op.to_connect or to_connect)
257
+ found = true
258
+ BayLog.trace("%s Update operation: %s con=%s close=%s ch=%s",
259
+ @agent, self.class.op_mode(ch_op.op), ch_op.to_connect, ch_op.to_close, ch_op.rudder.inspect())
260
+ end
261
+ end
262
+
263
+ if not found
264
+ BayLog.trace("%s New operation: %d con=%s close=%s ch=%s", @agent, op, to_connect, to_close, rd.inspect)
265
+ @operations << ChannelOperation.new(rd, op, to_connect, to_close)
266
+ end
267
+ end
268
+
269
+ wakeup
270
+ end
271
+
272
+ def register_channel_ops
273
+ if @operations.empty?
274
+ return 0
275
+ end
276
+
277
+ @operations_lock.synchronize do
278
+ nch = @operations.length
279
+ @operations.each do |rd_op|
280
+ st = get_rudder_state(rd_op.rudder)
281
+ if rd_op.rudder.io.closed?
282
+ # Channel is closed before register operation
283
+ BayLog.debug("%s Try to register closed socket (Ignore)", @agent)
284
+ next
285
+ end
286
+
287
+ begin
288
+ io = rd_op.rudder.io
289
+ BayLog.trace("%s register op=%s st=%s", @agent, self.class.op_mode(rd_op.op), st)
290
+ op = @selector.get_op(io)
291
+ if op == nil
292
+ @selector.register(io, rd_op.op)
293
+ else
294
+ new_op = op | rd_op.op
295
+ BayLog.trace("%s Already registered rd=%s op=%s update to %s", @agent, rd_op.rudder, self.class.op_mode(op), self.class.op_mode(new_op))
296
+ @selector.modify(io, new_op)
297
+ end
298
+
299
+ if rd_op.to_connect
300
+ if st == nil
301
+ BayLog.warn("%s register connect but ChannelState is null", @agent);
302
+ else
303
+ st.connecting = true
304
+ end
305
+
306
+ elsif rd_op.to_close
307
+ if st == nil
308
+ BayLog.warn("%s chState=%s register close but ChannelState", self.agent);
309
+ else
310
+ st.closing = true
311
+ end
312
+ end
313
+
314
+ rescue => e
315
+ st = get_rudder_state(rd_op.rudder)
316
+ BayLog.error_e(e, "%s Cannot register operation: %s", self.agent, st.rudder)
317
+ end
318
+ end
319
+
320
+ @operations.clear
321
+ return nch
322
+ end
323
+ end
324
+
325
+ def handle_channel(io, op)
326
+
327
+ #BayLog.info("%s handle_channel io=%s op=%d", self, io, op)
328
+ st = find_rudder_state_by_key(io)
329
+ if st == nil
330
+ BayLog.error("Cannot find fd state (Maybe file is closed)")
331
+ @selector.unregister(io)
332
+ return
333
+ end
334
+
335
+ begin
336
+
337
+ if st.closing
338
+ on_close_req(st)
339
+
340
+ elsif st.connecting
341
+ on_connectable(st)
342
+
343
+ st.connecting = false
344
+ # "Write-OP Off"
345
+ op = @selector.get_op(io)
346
+ op = op & ~Selector::OP_WRITE
347
+ if op == 0
348
+ @selector.unregister(io)
349
+ else
350
+ @selector.modify(io, op)
351
+ end
352
+
353
+ elsif st.accepting
354
+ on_acceptable(st)
355
+
356
+ else
357
+ if op & Selector::OP_READ != 0
358
+ # readable
359
+ on_readable(st)
360
+ =begin
361
+ next_action = st.listener.on_readable(rd)
362
+ if next_action == nil
363
+ raise Sink.new("unknown next action")
364
+ elsif next_action == NextSocketAction::WRITE
365
+ op = @agent.selector.get_op(rd)
366
+ op = op | Selector::OP_WRITE
367
+ @agent.selector.modify(rd, op)
368
+ end
369
+ =end
370
+ end
371
+
372
+ if op & Selector::OP_WRITE != 0
373
+ # writable
374
+ on_writable(st)
375
+ =begin
376
+ next_action = st.listener.on_writable(rd)
377
+ if next_action == nil
378
+ raise Sink.new("unknown next action")
379
+ elsif next_action == NextSocketAction::READ
380
+ # Handle as "Write Off"
381
+ op = @agent.selector.get_op(rd)
382
+ op = op & ~Selector::OP_WRITE
383
+ if op == 0
384
+ @agent.selector.unregister(rd)
385
+ else
386
+ @agent.selector.modify(rd, op)
387
+ end
388
+ end
389
+ =end
390
+ end
391
+ end
392
+
393
+ rescue Sink => e
394
+ raise e
395
+
396
+ rescue => e
397
+ if e.kind_of? EOFError
398
+ BayLog.debug("%s Socket closed by peer: skt=%s", @agent, st.rudder.inspect)
399
+ elsif e.kind_of? SystemCallError
400
+ BayLog.debug("%s O/S error: %s (skt=%s)", @agent, e.message, st.rudder.inspect)
401
+ elsif e.kind_of? IOError
402
+ BayLog.debug("%s IO error: %s (skt=%s)", @agent, e.message, st.rudder.inspect)
403
+ elsif e.kind_of? OpenSSL::SSL::SSLError
404
+ BayLog.debug_e(e, "%s SSL error: %s (skt=%s)", @agent, e.message, st.rudder.inspect)
405
+ else
406
+ BayLog.error_e(e, "%s Unhandled error error: (skt=%s)", @agent, st.rudder.inspect)
407
+ raise e
408
+ end
409
+ # Cannot handle Exception any more
410
+ BayLog.error_e(e)
411
+ next_action = NextSocketAction::CLOSE
412
+ end
413
+
414
+ st.access()
415
+ end
416
+
417
+ def on_acceptable(st)
418
+
419
+ begin
420
+ client_skt, = st.rudder.io.accept_nonblock
421
+ rescue IO::WaitReadable
422
+ # Maybe another agent get socket
423
+ BayLog.debug("Accept failed (must wait readable)")
424
+ return
425
+ end
426
+
427
+ BayLog.debug("%s Accepted: server=%s(%d) client=%s(%d)", self, st.rudder.io, st.rudder.io.fileno, client_skt, client_skt.fileno)
428
+ client_rd = IORudder.new(client_skt)
429
+ client_rd.set_non_blocking
430
+ #client_skt.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
431
+
432
+ @agent.send_accepted_letter(st, client_rd, nil, false)
433
+
434
+ end
435
+
436
+ def on_connectable(st)
437
+ BayLog.trace("%s onConnectable", self)
438
+
439
+ # check connected
440
+ begin
441
+ buf = ""
442
+ st.rudder.io.syswrite(buf)
443
+ rescue => e
444
+ BayLog.error("Connect failed: %s", e)
445
+ @agent.send_connected_letter(st, e, false)
446
+ return
447
+ end
448
+
449
+ @agent.send_connected_letter(st, nil, false)
450
+ end
451
+
452
+ def on_readable(st)
453
+ # Read data
454
+
455
+ BayLog.trace("%s on_readable", self)
456
+
457
+ begin
458
+ if st.handshaking
459
+ begin
460
+ # Calls accept API for client socket
461
+ st.rudder.io.accept_nonblock
462
+ st.handshaking = false
463
+
464
+ BayLog.debug("%s Handshake done (rd=%s)", self, st.rudder)
465
+ app_protocols = st.rudder.io.context.alpn_protocols
466
+
467
+ # HELP ME
468
+ # This code does not work!
469
+ # We cannot get application protocol name
470
+ proto = nil
471
+ if app_protocols != nil && app_protocols.length > 0
472
+ proto = app_protocols[0]
473
+ end
474
+
475
+ rescue IO::WaitReadable => e
476
+ BayLog.debug("%s Handshake status: read more st=%s", self, st)
477
+ return NextSocketAction::CONTINUE
478
+ rescue IO::WaitWritable => e
479
+ BayLog.debug("%s Handshake status: write more st=%s", self, st)
480
+ req_write(st.rudder, "", nil, nil, nil)
481
+ return NextSocketAction::CONTINUE
482
+ end
483
+ end
484
+
485
+ begin
486
+ len = st.rudder.read(st.read_buf, st.buf_size)
487
+ rescue IO::WaitReadable => e
488
+ BayLog.debug("%s Read status: read more", self)
489
+ return NextSocketAction::CONTINUE
490
+ rescue IO::WaitWritable => e
491
+ BayLog.debug("%s Read status: write more", self)
492
+ @channel_handler.ask_to_write(@ch)
493
+ return NextSocketAction::CONTINUE
494
+ rescue EOFError => e
495
+ BayLog.debug("%s EOF", self)
496
+ len = 0
497
+ end
498
+
499
+ BayLog.debug("%s read %d bytes", self, len)
500
+ @agent.send_read_letter(st, len, nil, nil, false)
501
+
502
+ rescue Exception => e
503
+ BayLog.debug_e(e, "%s Unhandled error", self)
504
+ @agent.send_read_letter(st, -1, nil, e, false)
505
+ return
506
+ end
507
+ end
508
+
509
+ def on_writable(st)
510
+ begin
511
+ if st.write_queue.empty?
512
+ raise IOError.new(@agent.to_s + " No data to write: " + st.rudder.to_s)
513
+ end
514
+
515
+ wunit = st.write_queue[0]
516
+
517
+ BayLog.debug("%s Try to write: rd=%s pkt=%s len=%d closed=%s adr=%s",
518
+ self, st.rudder, wunit.tag, wunit.buf.length, st.closed, wunit.adr);
519
+ #BayLog.debug(this + " " + new String(wUnit.buf.array(), 0, wUnit.buf.limit()));
520
+
521
+ n = st.rudder.write(wunit.buf)
522
+ #BayLog.debug("%s Wrote: rd=%s len=%d",self, st.rudder, n);
523
+ wunit.buf.slice!(0, n)
524
+ @agent.send_wrote_letter(st, n, nil, false)
525
+
526
+ rescue SystemCallError, IOError => e
527
+ BayLog.debug_e(e, "%s IO error", self)
528
+ @agent.send_wrote_letter(st, -1, e, false)
529
+ end
530
+ end
531
+
532
+ def on_close_req(st)
533
+ BayLog.debug("%s onCloseReq: rd=%s", self, st.rudder)
534
+ @agent.send_close_req_letter(st, false)
535
+ end
536
+
537
+ def on_waked_up
538
+ #BayLog.debug("%s waked up", self)
539
+ val = IOUtil.read_int32(@select_wakeup_pipe[0])
540
+ end
541
+
542
+ def self.op_mode(mode)
543
+ mode_str = ""
544
+ if (mode & Selector::OP_READ) != 0
545
+ mode_str = "OP_READ"
546
+ end
547
+
548
+ if (mode & Selector::OP_WRITE) != 0
549
+ if mode_str != ""
550
+ mode_str += "|"
551
+ end
552
+ mode_str += "OP_WRITE"
553
+ end
554
+
555
+ return mode_str
556
+ end
557
+ end
558
+ end
559
+ end
560
+ end
561
+ end