Skip to content

Commit

Permalink
Add TCPTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
phokz committed Mar 13, 2014
1 parent dcb7495 commit a8c10e4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/snmp/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ def recv(max_bytes)
end
end

class TCPTransport
def initialize(host, port)
@socket = TCPSocket.open(host, port)
end

def close
@socket.close
end

def send(data, host, port)
@socket.send(data, 0)
end

def recv(max_bytes)
@socket.recv(max_bytes)
end
end


##
# Manage a request-id in the range 1..2**31-1
#
Expand Down Expand Up @@ -133,7 +152,11 @@ class Config < Options
option :use_IPv6, :use_IPv6, lambda { |c| ipv6_address?(c) }

def create_transport
transport.respond_to?(:new) ? transport.new(socket_address_family) : transport
if transport == UDPTransport
transport.respond_to?(:new) ? transport.new(socket_address_family) : transport
elsif transport == TCPTransport
transport.respond_to?(:new) ? transport.new(host, trap_port) : transport
end
end
end

Expand Down

0 comments on commit a8c10e4

Please sign in to comment.