Class: NETSNMP::Session::Transport
- Inherits:
-
Object
- Object
- NETSNMP::Session::Transport
- Defined in:
- lib/netsnmp/session.rb
Constant Summary collapse
- MAXPDUSIZE =
0xffff + 1
- SOCK_FLAGS =
Socket.const_defined?(:MSG_DONTWAIT) ? Socket::MSG_DONTWAIT : 0
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(host, port, timeout:) ⇒ Transport
constructor
A new instance of Transport.
- #recv(bytesize = MAXPDUSIZE) ⇒ Object
- #send(payload) ⇒ Object
- #write(payload) ⇒ Object
Constructor Details
#initialize(host, port, timeout:) ⇒ Transport
Returns a new instance of Transport.
77 78 79 80 81 |
# File 'lib/netsnmp/session.rb', line 77 def initialize(host, port, timeout:) @socket = UDPSocket.new @destaddr = Socket.sockaddr_in(port, host) @timeout = timeout end |
Instance Method Details
#close ⇒ Object
83 84 85 |
# File 'lib/netsnmp/session.rb', line 83 def close @socket.close end |
#recv(bytesize = MAXPDUSIZE) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/netsnmp/session.rb', line 101 def recv(bytesize = MAXPDUSIZE) perform_io do datagram, = @socket.recv_nonblock(bytesize, SOCK_FLAGS) datagram end end |
#send(payload) ⇒ Object
87 88 89 90 |
# File 'lib/netsnmp/session.rb', line 87 def send(payload) write(payload) recv end |
#write(payload) ⇒ Object
95 96 97 98 99 |
# File 'lib/netsnmp/session.rb', line 95 def write(payload) perform_io do @socket.send(payload, SOCK_FLAGS, @destaddr) end end |