unix_socks 0.2.0 → 0.2.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/CHANGES.md +13 -0
- data/Rakefile +4 -0
- data/lib/unix_socks/server.rb +40 -5
- data/lib/unix_socks/version.rb +1 -1
- data/spec/unix_socks/server_spec.rb +12 -0
- data/unix_socks.gemspec +3 -3
- 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: 69a0d625a0a16de2b2c9e7fdf8e9237050153707accde9497cfa5945219a40a4
|
|
4
|
+
data.tar.gz: 5e45a9d545e4aaba75462c2c63e15a26c2e7ac41fcd1b6eb0b5e6c59ce5292c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fee22225f513d715172777d32630bfa822b4f3e8356966504e028e17f0a2025bae7fcdf450d075f66501d9704772bb92c576344a1adc7edb725768a54a5b397a
|
|
7
|
+
data.tar.gz: '01690791bf91770466c600dff26ed41d8ae92844375e82b5d80e03abbd83c74df06f72b918e8c39832a336639e92a1ba835ccf4ecea3632ff94eb42781f6e06f'
|
data/CHANGES.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2025-12-23 v0.2.1
|
|
4
|
+
|
|
5
|
+
- Updated `receive_in_background` method to validate socket file existence
|
|
6
|
+
before thread creation and raise `Errno::EEXIST` in the calling thread
|
|
7
|
+
instead of the background thread
|
|
8
|
+
- Added comprehensive test case for `receive_in_background` to verify proper
|
|
9
|
+
exception propagation when socket already exists
|
|
10
|
+
- Enhanced documentation for `receive_in_background` method with clearer description and parameter details
|
|
11
|
+
- Improved documentation line wrapping for UnixSocks server methods
|
|
12
|
+
- Added detailed documentation for JSON message parsing and popping functionality
|
|
13
|
+
- Added changelog generation support via `changelog` block in `Rakefile`
|
|
14
|
+
- Updated `gem_hadar` development dependency from version **2.10** to **2.14**
|
|
15
|
+
|
|
3
16
|
## 2025-12-20 v0.2.0
|
|
4
17
|
|
|
5
18
|
- Updated `required_ruby_version` from `~> 3.1` to `>= 3.1` in `Rakefile` and
|
data/Rakefile
CHANGED
data/lib/unix_socks/server.rb
CHANGED
|
@@ -94,13 +94,21 @@ class UnixSocks::Server
|
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
-
#
|
|
98
|
-
# separate thread, allowing it to continue executing without blocking the
|
|
99
|
-
# main program flow.
|
|
97
|
+
# Runs the message receiver in a background thread to prevent blocking.
|
|
100
98
|
#
|
|
101
|
-
#
|
|
102
|
-
#
|
|
99
|
+
# This method starts a new thread that continuously listens for incoming
|
|
100
|
+
# messages from connected clients. The server socket is created in the
|
|
101
|
+
# background, allowing the main execution flow to continue without
|
|
102
|
+
# waiting for messages.
|
|
103
|
+
#
|
|
104
|
+
# @param force [Boolean] Whether to overwrite any existing server socket file
|
|
105
|
+
# @yield [UnixSocks::Message] The received message
|
|
106
|
+
#
|
|
107
|
+
# @return [Thread] The background thread running the receiver
|
|
103
108
|
def receive_in_background(force: false, &block)
|
|
109
|
+
if !force && socket_path_exist?
|
|
110
|
+
raise Errno::EEXIST, "Path already exists #{server_socket_path.inspect}"
|
|
111
|
+
end
|
|
104
112
|
Thread.new do
|
|
105
113
|
receive(force:, &block)
|
|
106
114
|
ensure
|
|
@@ -122,10 +130,37 @@ class UnixSocks::Server
|
|
|
122
130
|
|
|
123
131
|
private
|
|
124
132
|
|
|
133
|
+
# Parses a JSON message from the socket and associates it with the socket
|
|
134
|
+
# connection
|
|
135
|
+
#
|
|
136
|
+
# This method retrieves a line of data from the socket, strips whitespace,
|
|
137
|
+
# and attempts to parse it as JSON. If successful, it creates a
|
|
138
|
+
# UnixSocks::Message object with the parsed data and assigns the socket
|
|
139
|
+
# connection to the message. If parsing fails, it logs a warning and
|
|
140
|
+
# returns nil.
|
|
141
|
+
#
|
|
142
|
+
# @param socket [ Socket ] the socket connection to read from
|
|
143
|
+
#
|
|
144
|
+
# @return [ UnixSocks::Message, nil ] the parsed message object or nil if
|
|
145
|
+
# parsing fails
|
|
125
146
|
def pop_message(socket)
|
|
126
147
|
parse_json_message(socket.gets, socket)
|
|
127
148
|
end
|
|
128
149
|
|
|
150
|
+
# Parses a JSON message from the given data and associates it with the
|
|
151
|
+
# provided socket connection.
|
|
152
|
+
#
|
|
153
|
+
# This method processes the input data by stripping whitespace and attempting
|
|
154
|
+
# to parse it as JSON. If parsing is successful, it creates a
|
|
155
|
+
# UnixSocks::Message object with the parsed data and assigns the socket
|
|
156
|
+
# connection to the message. In case of a JSON parsing error, it
|
|
157
|
+
# logs a warning and returns nil.
|
|
158
|
+
#
|
|
159
|
+
# @param data [ String ] The raw data string to be parsed as JSON.
|
|
160
|
+
# @param socket [ Socket ] The socket connection associated with the message.
|
|
161
|
+
#
|
|
162
|
+
# @return [ UnixSocks::Message, nil ] The parsed message object or nil if
|
|
163
|
+
# parsing fails.
|
|
129
164
|
def parse_json_message(data, socket)
|
|
130
165
|
data = data.strip
|
|
131
166
|
data.empty? and return nil
|
data/lib/unix_socks/version.rb
CHANGED
|
@@ -127,6 +127,18 @@ describe UnixSocks::Server do
|
|
|
127
127
|
|
|
128
128
|
server.receive_in_background(force: true)
|
|
129
129
|
end
|
|
130
|
+
|
|
131
|
+
it 'it raises Errno::EEXIST if socket already exists' do
|
|
132
|
+
expect(Thread).not_to receive(:new).and_yield
|
|
133
|
+
expect(FileUtils).not_to receive(:rm_f).with(server.server_socket_path)
|
|
134
|
+
expect(server).to receive(:socket_path_exist?).and_return true
|
|
135
|
+
expect(server).not_to receive(:at_exit)
|
|
136
|
+
expect(server).not_to receive(:receive).with(force: false)
|
|
137
|
+
|
|
138
|
+
expect {
|
|
139
|
+
server.receive_in_background(force: false)
|
|
140
|
+
}.to raise_error(Errno::EEXIST)
|
|
141
|
+
end
|
|
130
142
|
end
|
|
131
143
|
|
|
132
144
|
describe '#socket_path_exist?' do
|
data/unix_socks.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: unix_socks 0.2.
|
|
2
|
+
# stub: unix_socks 0.2.1 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "unix_socks".freeze
|
|
6
|
-
s.version = "0.2.
|
|
6
|
+
s.version = "0.2.1".freeze
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
|
23
23
|
|
|
24
24
|
s.specification_version = 4
|
|
25
25
|
|
|
26
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.
|
|
26
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.14".freeze])
|
|
27
27
|
s.add_development_dependency(%q<all_images>.freeze, ["~> 0.4".freeze])
|
|
28
28
|
s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2".freeze])
|
|
29
29
|
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unix_socks
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '2.
|
|
18
|
+
version: '2.14'
|
|
19
19
|
type: :development
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '2.
|
|
25
|
+
version: '2.14'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: all_images
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|