drb_protocol_drubyws 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4d60c97e74095d8c66fca1f9d8de34014abaace7411322de312cb2a115ca6cfb
4
+ data.tar.gz: cfb17c1f4bd9351f321024ad7cb2f285c578b8c80a204537420caeb5acf72642
5
+ SHA512:
6
+ metadata.gz: 8ee27234e9e09402504117580564d09ecdef784f64c7e620537ba7d09f4e81ff47294d9bc5b2424b3aba936afd8af8acefa3a7c0b67af5f80918a5d02b6253d9
7
+ data.tar.gz: cbde11820a22e8e638ff7cac3fea7831c7bed0b5c917bdc94a249266a72fbf949cd48ae864c67ae85af7c1c2649f5f86e564548da4beca5aeea7d7da835c2d3f
data/.idea/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
@@ -0,0 +1,25 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.3.5) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="drb (v2.2.1, rbenv: 3.3.5) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="fiber-annotation (v0.2.0, rbenv: 3.3.5) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="fiber-local (v1.1.0, rbenv: 3.3.5) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="fiber-storage (v1.0.0, rbenv: 3.3.5) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.3, rbenv: 3.3.5) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="protocol-websocket (v0.20.1, rbenv: 3.3.5) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="racc (v1.8.1, rbenv: 3.3.5) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.3.5) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.2.1, rbenv: 3.3.5) [gem]" level="application" />
24
+ </component>
25
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 3.3.5" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/drb_web_socket.iml" filepath="$PROJECT_DIR$/.idea/drb_web_socket.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-minitest
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.1
7
+ NewCops: enable
8
+
9
+ Style/StringLiterals:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ EnforcedStyle: double_quotes
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Drb Protocol drubyws
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/drb_web_socket`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/drb_web_socket.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
data/examples/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "drb_web_socket", path: "../"
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ drb_web_socket (0.1.0)
5
+ drb (~> 2.2)
6
+ wands (~> 0.6)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ drb (2.2.1)
12
+ protocol-http (0.47.1)
13
+ protocol-websocket (0.20.1)
14
+ protocol-http (~> 0.2)
15
+ wands (0.6.0)
16
+ protocol-websocket (~> 0.20)
17
+ webrick (~> 1.9)
18
+ webrick (1.9.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+ x86_64-linux
23
+
24
+ DEPENDENCIES
25
+ drb_web_socket!
26
+
27
+ BUNDLED WITH
28
+ 2.6.2
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "drb_web_socket"
4
+
5
+ foo = DRbObject.new_with_uri("drubyws://localhost:12345")
6
+ foo.greeting
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "drb_web_socket"
4
+
5
+ # This is a sample class.
6
+ class Foo
7
+ def greeting = puts "Hello, world!"
8
+ end
9
+
10
+ DRb.start_service "drubyws://localhost:12345", Foo.new
11
+ sleep
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DRbWebSocket
4
+ # A connection instance from DrbWebSocket::Server#accept.
5
+ class ConnectionToClient
6
+ # DRb::DRbServer#main_loop calls `client.uri` method.
7
+ attr_reader :uri
8
+
9
+ def initialize(uri, socket, config = {})
10
+ @uri = uri
11
+ @socket = socket
12
+ @config = config
13
+ @msg = DRb::DRbMessage.new(config)
14
+ end
15
+
16
+ # Receive a request from the client and return a [object, message, args, block] tuple.
17
+ def recv_request
18
+ @msg.recv_request(@socket)
19
+ end
20
+
21
+ # Send a reply to the client.
22
+ def send_reply(succ, result)
23
+ @msg.send_reply(@socket, succ, result)
24
+ end
25
+
26
+ # Close this connection.
27
+ def close
28
+ return unless @socket
29
+
30
+ @socket.close
31
+ @socket = nil
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "drb/drb"
4
+
5
+ module DRbWebSocket
6
+ # A protocol instance from DrbWebSocket::Protocol.open.
7
+ class ConnectionToServer
8
+ def initialize(uri, socket, config = {})
9
+ @uri = uri
10
+ @socket = socket
11
+ @config = config
12
+ @msg = DRb::DRbMessage.new(config)
13
+ end
14
+
15
+ # Send a request to +ref+ with the given message id and arguments.
16
+ def send_request(ref, msg_id, arg, block)
17
+ @msg.send_request(@socket, ref, msg_id, arg, block)
18
+ end
19
+
20
+ # Receive a reply from the server and return it as a [success-boolean, reply-value] pair.
21
+ def recv_reply
22
+ @msg.recv_reply(@socket)
23
+ end
24
+
25
+ # Close this connection.
26
+ def close
27
+ return unless @socket
28
+
29
+ @socket.close
30
+ @socket = nil
31
+ end
32
+
33
+ # Is this connection still alive?
34
+ def alive?
35
+ return false unless @socket
36
+
37
+ true
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "wands"
4
+ require "uri"
5
+
6
+ module DRbWebSocket
7
+ # A protocol with WebSocket for drb.
8
+ module Protocol
9
+ class << self
10
+ def open(uri, config)
11
+ host, port = parse_uri(uri)
12
+ socket = Wands::WebSocket.open(host, port)
13
+ ConnectionToServer.new(uri, socket, config)
14
+ end
15
+
16
+ def open_server(uri, config)
17
+ host, port = parse_uri(uri)
18
+ server = Wands::WebSocketServer.open(host, port)
19
+
20
+ if port.zero?
21
+ addr = server.addr
22
+ port = addr[1]
23
+ end
24
+ uri = "drubyws://#{host}:#{port}"
25
+
26
+ Server.new(uri, server, config)
27
+ end
28
+
29
+ def uri_option(uri, _config)
30
+ [uri, nil]
31
+ end
32
+
33
+ private
34
+
35
+ def parse_uri(uri)
36
+ parsed_uri = URI.parse(uri)
37
+ raise(DRb::DRbBadScheme, uri) unless parsed_uri.scheme == "drubyws"
38
+
39
+ [parsed_uri.host, parsed_uri.port]
40
+ rescue URI::InvalidURIError
41
+ raise(DRb::DRbBadURI, "can't parse uri:#{uri}")
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DRbWebSocket
4
+ # A protocol instance from DrbWebSocket::Protocol.open_server.
5
+ class Server
6
+ # Get the URI for this server.
7
+ attr_reader :uri
8
+
9
+ def initialize(uri, socket, config = {})
10
+ raise ArgumentError, "socket Must respond to :to_io" unless socket.respond_to?(:to_io)
11
+
12
+ @uri = uri
13
+ @socket = socket
14
+ @config = config
15
+ end
16
+
17
+ # Accept a new connection to the server.
18
+ # Returns a protocol instance capable of communicating with the client.
19
+ def accept
20
+ socket = @socket.accept
21
+ ConnectionToClient.new(@uri, socket, @config)
22
+ end
23
+
24
+ # Close the server connection.
25
+ def close
26
+ return unless @socket
27
+
28
+ @socket.close
29
+ @socket = nil
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DRbWebSocket
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "drb_web_socket/version"
4
+ require_relative "drb_web_socket/protocol"
5
+ require_relative "drb_web_socket/server"
6
+ require_relative "drb_web_socket/connection_to_client"
7
+ require_relative "drb_web_socket/connection_to_server"
8
+
9
+ # DrbWebSocket provides a protocol with WebSocket for the drb.
10
+ DRb::DRbProtocol.add_protocol(DRbWebSocket::Protocol)
@@ -0,0 +1,4 @@
1
+ module DrbWebSocket
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drb_protocol_drubyws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - shigeru.nakajima
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-03-07 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: drb
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.2'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.2'
26
+ - !ruby/object:Gem::Dependency
27
+ name: wands
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.6'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.6'
40
+ description: A transport protocol for dRuby that uses WebSocket. It enables connections
41
+ from a browser to a dRuby server.
42
+ email:
43
+ - shigeru.nakajima@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".idea/.gitignore"
49
+ - ".idea/drb_web_socket.iml"
50
+ - ".idea/misc.xml"
51
+ - ".idea/modules.xml"
52
+ - ".idea/vcs.xml"
53
+ - ".rubocop.yml"
54
+ - README.md
55
+ - Rakefile
56
+ - examples/Gemfile
57
+ - examples/Gemfile.lock
58
+ - examples/hello_c.rb
59
+ - examples/hello_s.rb
60
+ - lib/drb_web_socket.rb
61
+ - lib/drb_web_socket/connection_to_client.rb
62
+ - lib/drb_web_socket/connection_to_server.rb
63
+ - lib/drb_web_socket/protocol.rb
64
+ - lib/drb_web_socket/server.rb
65
+ - lib/drb_web_socket/version.rb
66
+ - sig/drb_web_socket.rbs
67
+ homepage: https://github.com/ledsun/drb_web_socket
68
+ licenses:
69
+ - MIT
70
+ metadata:
71
+ allowed_push_host: https://rubygems.org
72
+ homepage_uri: https://github.com/ledsun/drb_web_socket
73
+ rubygems_mfa_required: 'true'
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 3.1.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.6.2
89
+ specification_version: 4
90
+ summary: A protocol with WebSocket for drb.
91
+ test_files: []