Class: Netconf::IOProc
Constant Summary
collapse
- DEFAULT_RDBLKSZ =
(1024*1024)
Instance Attribute Summary collapse
Attributes inherited from Transport
#capabilities, #rpc, #session_id, #state, #timeout, #waitio
Instance Method Summary
collapse
Methods inherited from Transport
#close, #closed?, #has_capability?, #open, #open?, #rpc_exec, #send_and_receive
Constructor Details
#initialize(args_h = {}, &block) ⇒ IOProc
Returns a new instance of IOProc.
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/net/netconf/ioproc.rb', line 9
def initialize( args_h = {}, &block )
os_type = args_h[:os_type] || Netconf::DEFAULT_OS_TYPE
@args = args_h.clone
extend Netconf::const_get( os_type )::IOProc
@trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
@trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
super( &block )
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
7
8
9
|
# File 'lib/net/netconf/ioproc.rb', line 7
def args
@args
end
|
Instance Method Details
#puts(str = nil) ⇒ Object
52
53
54
|
# File 'lib/net/netconf/ioproc.rb', line 52
def puts( str = nil )
@trans.puts( str )
end
|
#trans_open ⇒ Object
the OS specific transport must implement this method
24
25
26
|
# File 'lib/net/netconf/ioproc.rb', line 24
def trans_open raise "Unsupported IOProc"
end
|
#trans_receive ⇒ Object
45
46
47
48
49
50
|
# File 'lib/net/netconf/ioproc.rb', line 45
def trans_receive
got = waitfor( Netconf::RPC::MSG_END_RE )
msg_end = got.rindex( Netconf::RPC::MSG_END )
got[msg_end .. -1] = ''
got
end
|
#trans_receive_hello ⇒ Object
28
29
30
|
# File 'lib/net/netconf/ioproc.rb', line 28
def trans_receive_hello
trans_receive()
end
|
#trans_send(cmd_str) ⇒ Object
41
42
43
|
# File 'lib/net/netconf/ioproc.rb', line 41
def trans_send( cmd_str )
@trans.write( cmd_str )
end
|
#trans_send_hello ⇒ Object
32
33
34
|
# File 'lib/net/netconf/ioproc.rb', line 32
def trans_send_hello
nil
end
|
#waitfor(on_re) ⇒ Object
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
84
85
|
# File 'lib/net/netconf/ioproc.rb', line 56
def waitfor( on_re )
time_out = @trans_timeout
wait_io = @trans_waitio
time_out = nil if time_out == false
done = false
rx_buf = ''
until( rx_buf.match( on_re ) and not IO::select( [@trans], nil, nil, wait_io ) )
unless IO::select( [@trans], nil, nil, time_out )
raise TimeoutError, "Netconf IO timed out while waiting for more data"
end
begin
rx_some = @trans.readpartial( DEFAULT_RDBLKSZ )
rx_buf += rx_some
break if rx_buf.match( on_re )
rescue EOFError rx_buf = nil if rx_buf == ''
break end
end
rx_buf
end
|