Methods
Public Instance methods
method dumps the object in a protocol format which can be easily picked by a recursive descent parser
[ show source ]
# File framework/nbio.rb, line 58
58: def dump_object(p_data,p_sock)
59: object_dump = Marshal.dump(p_data)
60: dump_length = object_dump.length.to_s
61: length_str = dump_length.rjust(9,'0')
62: final_data = length_str + object_dump
63: begin
64: p_sock.write_nonblock(final_data)
65: rescue Errno::EAGAIN
66: puts "EAGAIN Error while writing socket"
67: return
68: rescue Errno::EINTR
69: puts "Interrupt error"
70: return
71: rescue Errno::EPIPE
72: puts "Pipe error"
73: raise DisconnectError.new(p_sock)
74: end
75: end
[ show source ]
# File framework/nbio.rb, line 8
8: def gen_worker_key(worker_name,job_key = nil)
9: return worker_name if job_key.nil?
10: return "#{worker_name}_#{job_key}".to_sym
11: end
[ show source ]
# File framework/nbio.rb, line 3 3: def packet_classify(original_string) 4: word_parts = original_string.split('_') 5: return word_parts.map { |x| x.capitalize}.join 6: end
[ show source ]
# File framework/nbio.rb, line 13
13: def read_data(t_sock)
14: sock_data = ""
15: begin
16: while(t_data = t_sock.recv_nonblock(1023))
17: raise DisconnectError.new(t_sock) if t_data.empty?
18: sock_data << t_data
19: end
20: rescue Errno::EAGAIN
21: return sock_data
22: rescue
23: puts "Some read error"
24: raise DisconnectError.new(t_sock)
25: end
26: end
[ show source ]
# File framework/nbio.rb, line 28
28: def write_data(p_data,p_sock)
29: return unless p_data
30: if p_data.is_a? Fixnum
31: t_data = p_data.to_s
32: else
33: t_data = p_data.dup.to_s
34: end
35: t_length = t_data.length
36: begin
37: p_sock.write_nonblock(t_data)
38: rescue Errno::EAGAIN
39: return
40: rescue Errno::EPIPE
41: raise DisconnectError.new(p_sock)
42: end
43: end
method writes data to socket in a non blocking manner, but doesn‘t care if there is a error writing data
[ show source ]
# File framework/nbio.rb, line 46
46: def write_once(p_data,p_sock)
47: t_data = p_data.dup.to_s
48: begin
49: p_sock.write_nonblock(t_data)
50: rescue Errno::EAGAIN
51: return
52: rescue Errno::EPIPE
53: raise DisconnectError.new(p_sock)
54: end
55: end