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.
- checksums.yaml +4 -4
- data/lib/tiny_tcp_service.rb +12 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9153074bb46f8f6cbf51c4a864bfb2fa2eabb63232669d708e61502c931324dd
|
4
|
+
data.tar.gz: 401a36c00244ebecad0a6c8ee3cae185860edac655270d4cf4eb70f39392a097
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77f635cb2880c4578db3c72f0190a47f4939dc1f479fc8583e6f39d3eb84368beb1cf1c1ca2f7d146309cb78b3427084a36e9a4e7ddc8b0e886793a496f5f96c
|
7
|
+
data.tar.gz: b7766536ee659434cdaa7d1055611784837baf6fb90f9f8e7675d8d29a519fe8d3df66dc84c8cf035f2b1645abaff63538fc263af429963448db11cc58b3507c
|
data/lib/tiny_tcp_service.rb
CHANGED
@@ -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
|
-
|
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.
|
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-
|
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.
|
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
|