Module: Roma::Command::Definition
Defined Under Namespace
Modules: ClassMethods
Classes: ClientErrorException, ServerErrorException
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
8
9
10
11
|
# File 'lib/roma/command/command_definition.rb', line 8
def self.included(base)
base.extend ClassMethods
end
|
Instance Method Details
#forward_and_multi_line_receive(nid, rs, data = nil) ⇒ Object
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
# File 'lib/roma/command/command_definition.rb', line 383
def forward_and_multi_line_receive(nid, rs, data=nil)
if rs.last == "forward"
return send_data("SERVER_ERROR Routing table is inconsistent.\r\n")
end
@log.warn("forward #{rs} to #{nid}");
buf = rs.join(' ') + " forward\r\n"
buf << data + "\r\n" if data
con = get_connection(nid)
con.send(buf)
buf = con.gets
if buf == nil
@rttable.proc_failed(nid)
@log.error("forward get failed:nid=#{nid} rs=#{rs} #{$@}")
return send_data("SERVER_ERROR Message forward failed.\r\n")
elsif buf.start_with?("ERROR")
@rttable.proc_succeed(nid)
con.close_connection
@log.error("forward get failed:nid=#{nid} rs=#{rs} #{$@}")
return send_data("SERVER_ERROR Message forward failed.\r\n")
elsif buf.start_with?("VALUE") == false
return_connection(nid, con)
@rttable.proc_succeed(nid)
return send_data(buf)
end
res = ''
begin
res << buf
s = buf.split(/ /)
if s[0] != 'VALUE'
return_connection(nid, con)
@rttable.proc_succeed(nid)
return send_data(buf)
end
res << con.read_bytes(s[3].to_i + 2)
end while (buf = con.gets)!="END\r\n"
res << "END\r\n"
return_connection(nid, con)
@rttable.proc_succeed(nid)
send_data(res)
rescue => e
@rttable.proc_failed(nid) if e.message != "no connection"
@log.error("forward get failed:nid=#{nid} rs=#{rs} #{e} #{$@}")
send_data("SERVER_ERROR Message forward failed.\r\n")
end
|
#forward_and_one_line_receive(nid, rs, data = nil) ⇒ Object
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
# File 'lib/roma/command/command_definition.rb', line 366
def forward_and_one_line_receive(nid, rs, data = nil)
if rs.last == "forward"
return send_data("SERVER_ERROR Routing table is inconsistent.\r\n")
end
@log.warn("forward #{rs} to #{nid}");
buf = rs.join(' ') + " forward\r\n"
buf << data + "\r\n" if data
res = send_cmd(nid, buf)
if res == nil || res.start_with?("ERROR")
return send_data("SERVER_ERROR Message forward failed.\r\n")
end
send_data("#{res}\r\n")
end
|