Class: DNS::Server::Dispatcher::ConnectionDispatcher::Socket
- Inherits:
-
Object
- Object
- DNS::Server::Dispatcher::ConnectionDispatcher::Socket
- Defined in:
- lib/faildns/server/dispatcher/socket.rb
Instance Attribute Summary collapse
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(dispatcher, what) ⇒ Socket
constructor
A new instance of Socket.
- #send(message, close = true) ⇒ Object
Constructor Details
#initialize(dispatcher, what) ⇒ Socket
Returns a new instance of Socket.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/faildns/server/dispatcher/socket.rb', line 31 def initialize (dispatcher, what) @dispatcher = dispatcher if what.is_a? TCPSocket @type = :TCP @ip = what.peeraddr[3] @port = what.addr[1] @socket = what else @type = :UDP @ip = what[3] @port = what[1] @socket = dispatcher.connection.listening[:UDP] end end |
Instance Attribute Details
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
29 30 31 |
# File 'lib/faildns/server/dispatcher/socket.rb', line 29 def ip @ip end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
29 30 31 |
# File 'lib/faildns/server/dispatcher/socket.rb', line 29 def port @port end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
29 30 31 |
# File 'lib/faildns/server/dispatcher/socket.rb', line 29 def type @type end |
Instance Method Details
#close ⇒ Object
80 81 82 83 84 |
# File 'lib/faildns/server/dispatcher/socket.rb', line 80 def close if @socket.is_a? TCPSocket @socket.close end end |
#send(message, close = true) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/faildns/server/dispatcher/socket.rb', line 49 def send (, close=true) @dispatcher.dispatch :output, self, if @type == :UDP && .pack.length > 512 [.additionals, ., .answers, .questions].each {|rr| while (tmp = .pack).length > 512 && r.pop; end if tmp.length <= 512 break end } .header.questions = .questions.length .header.answers = .answers.length .header. = ..length .header.additionals = .additionals.length .header.truncated! end if @socket.is_a? TCPSocket @socket.send_nonblock(.pack) if close @socket.close end else @socket.send(.pack, 0, ::Socket.pack_sockaddr_in(@port, @ip)) end end |