aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/udp_server.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-07-22 16:55:54 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-07-22 16:55:54 +0100
commit25b32914b72a5f709eca773f3511cc89c2e710c2 (patch)
tree4dab9e78e4c6b49220a837b38d463328c05e2983 /lib/mauve/udp_server.rb
parent3185e5d746abda1b7f42ecdbd74ec14359fda3bc (diff)
parentfd23821950f0562a8995735105cd31fdc6d55933 (diff)
merge
Diffstat (limited to 'lib/mauve/udp_server.rb')
-rw-r--r--lib/mauve/udp_server.rb35
1 files changed, 17 insertions, 18 deletions
diff --git a/lib/mauve/udp_server.rb b/lib/mauve/udp_server.rb
index 049ea09..4e6296d 100644
--- a/lib/mauve/udp_server.rb
+++ b/lib/mauve/udp_server.rb
@@ -12,31 +12,30 @@ module Mauve
include Singleton
- attr_accessor :ip, :port, :sleep_interval
+ attr_reader :ip, :port
def initialize
super
- #
- # Set the logger up
- #
- @ip = "127.0.0.1"
- @port = 32741
+ self.ip = "127.0.0.1"
+ self.port = 32741
@socket = nil
- @closing_now = false
- @sleep_interval = 0
end
-
- def open_socket
- #
- # check the IP address
- #
- _ip = IPAddr.new(@ip)
+
+ def ip=(i)
+ raise ArgumentError, "ip must be a string" unless i.is_a?(String)
+ @ip = IPAddr.new(i)
+ end
+
+ def port=(pr)
+ raise ArgumentError, "port must be an integer between 0 and #{2**16-1}" unless pr.is_a?(Integer) and pr < 2**16 and pr > 0
+ @port = pr
+ end
+ def open_socket
#
# Specify the family when opening the socket.
#
- @socket = UDPSocket.new(_ip.family)
- @closing_now = false
+ @socket = UDPSocket.new(@ip.family)
logger.debug("Trying to increase Socket::SO_RCVBUF to 10M.")
old = @socket.getsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF).unpack("i").first
@@ -48,9 +47,9 @@ module Mauve
logger.debug("Successfully increased Socket::SO_RCVBUF from #{old} to #{new}.")
- @socket.bind(@ip, @port)
+ @socket.bind(@ip.to_s, @port)
- logger.info("Opened socket on #{@ip}:#{@port}")
+ logger.info("Opened socket on #{@ip.to_s}:#{@port}")
end
def close_socket