tiny_tcp_service 1.3.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tiny_tcp_service.rb +14 -5
- 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: 166a2118d50973568da49c7afa4809187a3e3782ff1bf4393c14d3b605813ee3
|
4
|
+
data.tar.gz: a2e8f63bff4b0b7d02b938420cc88eab1c774480bc4b65f15ba64d020a2e7608
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeeada155b9e4a765821d50d2f9f2791e28e7cd38894ea9fa1e0d3dbcb482dcb9147d711ffe39f362c158911554954853fd973f50aa8c91530e27c9023227ead
|
7
|
+
data.tar.gz: 7ced6b9bada66ca7a409512b94043edeb6790a20ead6d0d694c48ac7c419ad7cf0843dbbff0e08ae5102bc33fd7800a21a2c2e0bb81d7c08d47f1f5c419ed339
|
data/lib/tiny_tcp_service.rb
CHANGED
@@ -11,10 +11,9 @@ require 'socket'
|
|
11
11
|
# TinyTCPService implements a line-based, call and response protocol, where
|
12
12
|
# every incoming message must be a newline-terminated ("\n") String, and for
|
13
13
|
# every received message the service responds with a newline-terminated String.
|
14
|
-
# been set).
|
15
14
|
#
|
16
|
-
#
|
17
|
-
#
|
15
|
+
# You can use this to send more complex objects, such as minified JSON, so long
|
16
|
+
# as your JSON's content doesn't also contain newlines.
|
18
17
|
#
|
19
18
|
# NOTE: if you're running a TinyTCPService and a client of your system violates
|
20
19
|
# your communication protocol, you should raise an instance of
|
@@ -32,7 +31,7 @@ class TinyTCPService
|
|
32
31
|
@error_handlers = {}
|
33
32
|
|
34
33
|
# client accept thread
|
35
|
-
Thread.new do |t|
|
34
|
+
@thread = Thread.new do |t|
|
36
35
|
loop do
|
37
36
|
break unless running?
|
38
37
|
@clients << @server.accept
|
@@ -51,7 +50,12 @@ class TinyTCPService
|
|
51
50
|
readable&.each do |c|
|
52
51
|
begin
|
53
52
|
m = c.gets&.chomp
|
54
|
-
|
53
|
+
|
54
|
+
if m.is_a?(String)
|
55
|
+
c.puts(@msg_handler&.call(m))
|
56
|
+
else
|
57
|
+
_remove_client!(c)
|
58
|
+
end
|
55
59
|
rescue TinyTCPService::BadClient, Errno::ECONNRESET => e
|
56
60
|
_remove_client!(c)
|
57
61
|
rescue => e
|
@@ -73,6 +77,11 @@ class TinyTCPService
|
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
80
|
+
# join the service Thread if you want to wait until it's closed
|
81
|
+
def join
|
82
|
+
@thread.join
|
83
|
+
end
|
84
|
+
|
76
85
|
# h - some object that responds to #call
|
77
86
|
def msg_handler=(h)
|
78
87
|
@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.1
|
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-12 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
|