diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-07-22 16:55:01 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-07-22 16:55:01 +0100 |
commit | fd23821950f0562a8995735105cd31fdc6d55933 (patch) | |
tree | 967df2f5647803a6c46f4d52003b2231c1de72cb /lib/mauve/udp_server.rb | |
parent | d3a3cfef9650b08f62db62bd7e86b673f9d77d0b (diff) |
* Rejigged configuration
* Added --test and --verbose flags for the server config
* Started proper test suite
* Config parsing now gives more sensible errors + backtrace
* Rejigged people and source lists
Diffstat (limited to 'lib/mauve/udp_server.rb')
-rw-r--r-- | lib/mauve/udp_server.rb | 35 |
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 |