tiny_tcp_service 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_tcp_service.rb +12 -2
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df345d1a0441ab1451364e2d6c60dcabae1539387f8d32c0a8f6c7a506bc43a4
4
- data.tar.gz: be6dacf5fe1d224280f73b0b4529ae5cdea4d15b53e09a29d2effbf430e69e71
3
+ metadata.gz: 9153074bb46f8f6cbf51c4a864bfb2fa2eabb63232669d708e61502c931324dd
4
+ data.tar.gz: 401a36c00244ebecad0a6c8ee3cae185860edac655270d4cf4eb70f39392a097
5
5
  SHA512:
6
- metadata.gz: bd0fb1ee8872b784205f29e3a16a5a10764b11ea0a33646db31ac60da8bffd32c2070c24087abfedf746905a23e2c8626a36cdb7a755f9fd65d686325f07af96
7
- data.tar.gz: 3c5cb2735db8c26e076aa2cf07893d199047e5f39a18bb0932ec6e884e351d4fc0739afd3b847f56f8003acb1b328df53990967ef82bdb071099630020dc82a9
6
+ metadata.gz: 77f635cb2880c4578db3c72f0190a47f4939dc1f479fc8583e6f39d3eb84368beb1cf1c1ca2f7d146309cb78b3427084a36e9a4e7ddc8b0e886793a496f5f96c
7
+ data.tar.gz: b7766536ee659434cdaa7d1055611784837baf6fb90f9f8e7675d8d29a519fe8d3df66dc84c8cf035f2b1645abaff63538fc263af429963448db11cc58b3507c
@@ -32,7 +32,7 @@ class TinyTCPService
32
32
  @error_handlers = {}
33
33
 
34
34
  # client accept thread
35
- Thread.new do |t|
35
+ @thread = Thread.new do |t|
36
36
  loop do
37
37
  break unless running?
38
38
  @clients << @server.accept
@@ -51,7 +51,12 @@ class TinyTCPService
51
51
  readable&.each do |c|
52
52
  begin
53
53
  m = c.gets&.chomp
54
- c.puts(@msg_handler&.call(m) || 'ok')
54
+
55
+ if m.is_a?(String)
56
+ c.puts(@msg_handler&.call(m))
57
+ else
58
+ _remove_client!(c)
59
+ end
55
60
  rescue TinyTCPService::BadClient, Errno::ECONNRESET => e
56
61
  _remove_client!(c)
57
62
  rescue => e
@@ -73,6 +78,11 @@ class TinyTCPService
73
78
  end
74
79
  end
75
80
 
81
+ # join the service Thread if you want to wait until it's closed
82
+ def join
83
+ @thread.join
84
+ end
85
+
76
86
  # h - some object that responds to #call
77
87
  def msg_handler=(h)
78
88
  @msg_handler = h
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_tcp_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-04 00:00:00.000000000 Z
11
+ date: 2023-11-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a tiny TCP service with automated client lifecycle
14
14
  email: jefflunt@gmail.com
@@ -36,7 +36,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
38
  requirements: []
39
- rubygems_version: 3.3.7
39
+ rubygems_version: 3.4.1
40
40
  signing_key:
41
41
  specification_version: 4
42
42
  summary: a tiny TCP service with automated client lifecycle