json-socket 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json-socket.rb +21 -25
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 875091899544dfd73d4014d91052776f04ef92c62acd78d233701baf82a2f01c
|
4
|
+
data.tar.gz: db3aedc20dabe6e640d83fe682cde75dbde60ddc601eda29269099e6f2fca52f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc524ff94905b6f97ab70d6bbc6c0ee067737cededacb4eec6c2bfc5c2dd74ed76d2455fcc494c2abaa3c8ef2f4b74016941893e2f747715d3d3646f25b1d67e
|
7
|
+
data.tar.gz: 7a56e89c0320e7b494dafee28037567214b4663168d82eb08536e8c90c74a15074a35958d939b9cfe100b11c7f83e544eaf35287594ce891b2e2a7d2120679f4
|
data/lib/json-socket.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require "socket"
|
1
|
+
# require "socket"
|
2
2
|
require "fileutils"
|
3
3
|
require "oj"
|
4
|
+
require "async/io"
|
5
|
+
require 'async/io/unix_endpoint'
|
4
6
|
|
5
7
|
Oj.default_options = { :mode => :strict }
|
6
8
|
|
@@ -25,32 +27,30 @@ module JSONSocket
|
|
25
27
|
def initialize(host: "127.0.0.1", port: 1234, delimeter: "#", unix_socket: nil, oj_options: nil)
|
26
28
|
Oj.default_options = oj_options if oj_options
|
27
29
|
@delimeter = delimeter
|
28
|
-
@stop = false
|
29
30
|
@server = if unix_socket
|
30
31
|
FileUtils.rm_f(unix_socket)
|
31
|
-
|
32
|
+
Async::IO::Endpoint.unix(unix_socket)
|
32
33
|
else
|
33
|
-
|
34
|
+
Async::IO::Endpoint.tcp(host, port)
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
def stop
|
38
|
-
@stop = true
|
39
|
-
end
|
40
|
-
|
41
38
|
def listen
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
Async do |task|
|
40
|
+
begin
|
41
|
+
@server.accept do |client|
|
42
|
+
client = client.set_encoding 'UTF-8'
|
43
|
+
# https://stackoverflow.com/questions/25303943/how-to-send-a-utf-8-encoded-strings-via-tcpsocket-in-ruby/25305256
|
44
|
+
message_length = client.gets(@delimeter).to_i
|
45
|
+
unless message_length == 0
|
48
46
|
on_message(parse_json(client.read(message_length)), client)
|
49
|
-
|
50
|
-
|
47
|
+
else
|
48
|
+
client.close
|
51
49
|
end
|
52
50
|
end
|
53
|
-
|
51
|
+
rescue Exception => e
|
52
|
+
on_error e
|
53
|
+
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -104,14 +104,10 @@ module JSONSocket
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def send(message)
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
TCPSocket.open(@host, @port) {|socket| handle_send_receive(socket, message) }
|
112
|
-
end
|
113
|
-
rescue Exception => e
|
114
|
-
STDERR.puts e
|
107
|
+
if @unix_socket
|
108
|
+
UNIXSocket.open(@unix_socket) {|socket| handle_send_receive(socket, message) }
|
109
|
+
else
|
110
|
+
TCPSocket.open(@host, @port) {|socket| handle_send_receive(socket, message) }
|
115
111
|
end
|
116
112
|
end
|
117
113
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-socket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- foi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: async-io
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,8 +52,8 @@ dependencies:
|
|
38
52
|
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
|
-
description: JSON-socket client & server implementation
|
42
|
-
with sebastianseilund/node-json-socket
|
55
|
+
description: JSON-socket client & server implementation based on async-io. Inspired
|
56
|
+
by and compatible with sebastianseilund/node-json-socket
|
43
57
|
email: foi@live.ru
|
44
58
|
executables: []
|
45
59
|
extensions: []
|