minitcp 0.15.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.txt +4 -0
  3. data/README.md +4 -2
  4. data/VERSION +1 -1
  5. data/lib/minitcp.rb +19 -7
  6. metadata +6 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40c86e0923a11e1d1399840594700ed14d087f5b
4
- data.tar.gz: 25fc9a740519e40ed6ccf029cb986bb85e0e0a13
3
+ metadata.gz: af267c0cf8561cde0e65f3288401b9a28153c7a4
4
+ data.tar.gz: c3d3de7c6901a71fbbe21185ea802a714988bc1c
5
5
  SHA512:
6
- metadata.gz: 1e59ae815447e1bd2639a3a49a8c536f9af7856c88a6c0861e643e671f78f68973eeec0ecb1cc1c067c6730e88d1bd3ee61b9633d7844550f4c09fcdee72d445
7
- data.tar.gz: b204d6cb22237371a6bb93e449ee977564d7e8d9931ed86b0d1c76b15c1b310f726611f8f7168a6627f7a834fde673f6366361cdd933358ed6c3f433a0f962c5
6
+ metadata.gz: 033b71525b06221b027ab52a4a833c0b5f97cd9a5c1e0da142ad3d982ad75d40378a6a429169130527ec318faa36c5fd219118edb24f99fe5ea57b6d0d4d231d
7
+ data.tar.gz: 9d102861440497169a52efda8002abb368811970ffbb5994ae751bd5a6d1c1a6263ed59facb358fa018ec135d4966c82dd3c5e9b0de560df9f590de09f8535ac
@@ -1,3 +1,7 @@
1
+ 0.17.0 : 2016-05-18 16:00:30 +0200
2
+ 0.16.0 : 2016-05-18 16:00:15 +0200
3
+ minitcp.rb : correction UDPAgent
4
+ README.md : update
1
5
  0.15.0 : 2015-04-02 15:51:14 +0200
2
6
  minitcp.rb : force data received to encding BINARY
3
7
  0.14.0 : 2015-01-13 20:56:17 +0100
data/README.md CHANGED
@@ -145,8 +145,10 @@ UDP
145
145
 
146
146
  2 primitives :
147
147
 
148
- * **send_datagram(host,port,message)** : create a socket, send mesage and close socket (ca'nt receive a reply)
149
- * **send_datagram_on_socket(socket,host,port,message)** : use existant socket for send a message to ip:port
148
+ * **send_datagram(host,port,message)** :
149
+ create a socket, send mesage and close socket (ca'nt receive a reply)
150
+ * **send_datagram_on_socket(socket,host,port,message)** :
151
+ use an existant socket for send a message to ip:port
150
152
 
151
153
  Messages
152
154
  ===
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.15.0
1
+ 0.17.0
@@ -255,8 +255,9 @@ end
255
255
  #
256
256
  # MClient.run_continous("localhost",2200,6000) do |socket| .. end.join
257
257
  #
258
+ $udp_socket={}
258
259
  class UDPAgent
259
- # maintain a conntection to a TCP serveur, sleep timer_interconnection_ms millisecondes
260
+ # maintain a connection to a UDP serveur, sleep timer_interconnection_ms millisecondes
260
261
  # beetwen each reconnections
261
262
  def self.send_datagram(host,port,mess)
262
263
  sock = UDPSocket.new
@@ -273,18 +274,29 @@ class UDPAgent
273
274
  # send datagram on timer
274
275
  def self.on_timer(periode,options)
275
276
  Thread.new do
276
- sleep periode/1000.0
277
- sock = UDPSocket.new
277
+ sleep 0.1
278
278
  if options[:port]
279
- sock.bind("0.0.0.0", options[:port])
279
+ if $udp_socket[options[:port]]
280
+ sock=$udp_socket[options[:port]]
281
+ else
282
+ sock = UDPSocket.new
283
+ sock.bind("0.0.0.0", options[:port])
284
+ $udp_socket[options[:port]]=sock
285
+ end
286
+ end
287
+ if options[:on_timer]
288
+ h=options[:on_timer].call()
289
+ self.send_datagram_on_socket(sock,h[:host], h[:port],h[:mess]) if h && h[:mess] && h[:host] && h[:port]
280
290
  end
281
291
  loop do
282
- rep=IO.select([sock],nil,nil,periode/1000.0)
292
+ nextt= (((Time.now.to_f*1000).round/periode + 1)*periode)/1000.0
293
+ delta=nextt - Time.now.to_f
294
+ rep=IO.select([sock],nil,nil,delta)
283
295
  #puts "IO.SELECT => #{rep}"
284
296
  if rep
285
297
  Thread.new {
286
- data,peer=sock.recvfrom(1024)
287
- options[:on_receive].call(data,peer,sock)
298
+ data,peer=(sock.recvfrom(1024) rescue [nil,nil])
299
+ options[:on_receive].call(data,peer,sock) if data
288
300
  } if options[:on_receive]
289
301
  elsif options[:on_timer]
290
302
  h=options[:on_timer].call()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Regis d'Aubarede
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-02 00:00:00.000000000 Z
11
+ date: 2016-05-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  A DSL for programming little Tcp client and server
@@ -46,17 +46,17 @@ require_paths:
46
46
  - lib
47
47
  required_ruby_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
- - - '>='
49
+ - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '>='
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  requirements: []
58
58
  rubyforge_project:
59
- rubygems_version: 2.4.6
59
+ rubygems_version: 2.4.5.1
60
60
  signing_key:
61
61
  specification_version: 3
62
62
  summary: A DSL for programming little Tcp client and server
@@ -68,3 +68,4 @@ test_files:
68
68
  - samples/relay.rb
69
69
  - samples/spdy.rb
70
70
  - samples/statcpu.rb
71
+ has_rdoc: