udat 1.4.0 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/udat.rb +48 -15
- metadata +2 -2
data/lib/udat.rb
CHANGED
@@ -439,16 +439,16 @@ module Udat
|
|
439
439
|
port = port.to_int if port
|
440
440
|
socket_args = nil
|
441
441
|
result = nil
|
442
|
-
|
443
|
-
|
442
|
+
if port.nil?
|
443
|
+
Resolv::DNS.open do |dns|
|
444
444
|
srv_rr = dns.getresource(
|
445
445
|
"_udat-rpc._tcp.#{domain}",
|
446
446
|
Resolv::DNS::Resource::IN::SRV
|
447
447
|
)
|
448
448
|
socket_args = [srv_rr.target.to_s, srv_rr.port.to_i]
|
449
|
-
else
|
450
|
-
socket_args = [domain, port]
|
451
449
|
end
|
450
|
+
else
|
451
|
+
socket_args = [domain, port]
|
452
452
|
end
|
453
453
|
socket = nil
|
454
454
|
begin
|
@@ -1089,16 +1089,45 @@ module Udat
|
|
1089
1089
|
|
1090
1090
|
end
|
1091
1091
|
|
1092
|
-
# Waits in an endless loop for incoming
|
1093
|
-
#
|
1094
|
-
#
|
1095
|
-
#
|
1096
|
-
#
|
1097
|
-
#
|
1098
|
-
|
1099
|
-
|
1092
|
+
# Waits in an endless loop for incoming connections and runs a new thread
|
1093
|
+
# for each incoming connection, reads and parses UDAT objects, passes
|
1094
|
+
# them each to a given block (by calling yield) and writes the result of
|
1095
|
+
# the called block in form of an encoded UDAT object back to the socket.
|
1096
|
+
# If the argument "listen_on" is an Integer, it is used as a TCP port
|
1097
|
+
# number, if the argument is a String, the port being listened on will
|
1098
|
+
# be determined by a DNS look-up of an _udat-rpc._tcp SRV record. In both
|
1099
|
+
# cases the TCP socket is bound to all interfaces. Alternatively
|
1100
|
+
# "listen_on" may be a non Integer object, supplying an "accept" method
|
1101
|
+
# like TCPServer or UNIXServer, which returns a socket for each incoming
|
1102
|
+
# connection.
|
1103
|
+
def run_rpc_server(listen_on, timeout = 180)
|
1104
|
+
unless block_given?
|
1105
|
+
raise ArgumentError, "No block given for Udat::run_rpc_server call."
|
1106
|
+
end
|
1107
|
+
if listen_on.kind_of? String
|
1108
|
+
Resolv::DNS.open do |dns|
|
1109
|
+
srv_rr = dns.getresource(
|
1110
|
+
"_udat-rpc._tcp.#{listen_on}",
|
1111
|
+
Resolv::DNS::Resource::IN::SRV
|
1112
|
+
)
|
1113
|
+
listen_on = srv_rr.port.to_i
|
1114
|
+
end
|
1115
|
+
end
|
1116
|
+
new_server = nil
|
1100
1117
|
begin
|
1101
|
-
|
1118
|
+
if listen_on.kind_of? Integer
|
1119
|
+
new_server = TCPServer.new(listen_on)
|
1120
|
+
server = new_server
|
1121
|
+
elsif listen_on.respond_to? :accept
|
1122
|
+
server = listen_on
|
1123
|
+
elsif listen_on.respond_to? :to_int
|
1124
|
+
new_server = TCPServer.new(listen_on.to_int)
|
1125
|
+
server = new_server
|
1126
|
+
else
|
1127
|
+
raise ArgumentError,
|
1128
|
+
"Argument \"listen_on\" passed to Udat::run_rpc_server " <<
|
1129
|
+
"is not an integer and has no \"accept\" or \"to_int\" method."
|
1130
|
+
end
|
1102
1131
|
while true
|
1103
1132
|
Thread.new(server.accept) do |socket|
|
1104
1133
|
begin
|
@@ -1106,7 +1135,11 @@ module Udat
|
|
1106
1135
|
query = nil
|
1107
1136
|
begin
|
1108
1137
|
Timeout.timeout(timeout) do
|
1109
|
-
|
1138
|
+
begin
|
1139
|
+
query = socket.read_udat
|
1140
|
+
rescue EOFError, ParseError
|
1141
|
+
break
|
1142
|
+
end
|
1110
1143
|
end
|
1111
1144
|
rescue Timeout::Error
|
1112
1145
|
end
|
@@ -1119,7 +1152,7 @@ module Udat
|
|
1119
1152
|
end
|
1120
1153
|
end
|
1121
1154
|
ensure
|
1122
|
-
|
1155
|
+
new_server.close if server
|
1123
1156
|
end
|
1124
1157
|
end
|
1125
1158
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: udat
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.4.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.4.1
|
7
|
+
date: 2007-06-01 00:00:00 +00:00
|
8
8
|
summary: Parser and generator for UDAT documents, a generic data format similar to XML or YAML.
|
9
9
|
require_paths:
|
10
10
|
- lib/
|