socketry 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dae535663b1bc19486c7766d86d1444cf097fb81
4
- data.tar.gz: 31212e71094435898cd1f2937bece83f9f863708
3
+ metadata.gz: 3035f86108ed663a3bae8c6ef3d50b09925e9628
4
+ data.tar.gz: f21df11ab03cbddfe484f6f73ec2c08e501d7d88
5
5
  SHA512:
6
- metadata.gz: 5e4bedb944e9683e08e6027edc585c09383c9f962eec07375a70fff0aaac3fdeedf5020ec12beaa56213de0bb96d1b1a3d66fbd0cd5655544e22b96530f52836
7
- data.tar.gz: b169b991a93b8667ad3f532889751e05aa5e25a98825452da04ddcbcfc5652a8fb01218f0a48212d111e02316f677156d72190ba64e6a74b0bfbe1325ed251b2
6
+ metadata.gz: a659f5c5b1be2398364efe1a0a088476d1ec85594c8986c88836baea15fe235d99d58e29b8e0a765de89691a843f35658757dab17586f490bb21adf7be80997d
7
+ data.tar.gz: 4e96517be39871436dcd8afe7bf22752a58f906fc1da5aef8e0edf3189987fe11905fb7cb6cd2f01332083e1146e4312280c41d51f9c4152bce24aa10ff6a6ac
data/.rspec CHANGED
@@ -1,4 +1,3 @@
1
- --backtrace
2
1
  --color
3
2
  --format=documentation
4
3
  --order random
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.0 (2016-09-12)
2
+
3
+ * Rename Socketry::TCP::Socket#connected? -> #closed?
4
+
1
5
  ## 0.1.0 (2016-09-11)
2
6
 
3
7
  * Initial release
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2015-2016 Tony Arcieri, Zachary Anker
3
+ Copyright (c) 2016 Tony Arcieri
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -19,12 +19,29 @@ Socketry can also be used to provide asynchronous I/O with [Celluloid::IO].
19
19
 
20
20
  [Celluloid::IO]: https://github.com/celluloid/celluloid-io
21
21
 
22
+ ## Motivation
23
+
24
+ By default, Ruby sockets do not provide a built-in timeout mechanism. The only
25
+ timeout mechanism provided by the language leverages [timeout.rb], which uses
26
+ [unsafe multithreaded behaviors] to implement timeouts.
27
+
28
+ While Socketry provides a synchronous, blocking API similar to Ruby's own
29
+ `TCPSocket` and `UDPSocket` classes, behind the scenes it uses non-blocking I/O
30
+ to implement thread-safe timeouts.
31
+
32
+ Highly modular and pluggable, Socketry also provides the flexibility to
33
+ seamlessly leverage [Celluloid::IO] for event-driven I/O.
34
+
35
+ [timeout.rb]: http://ruby-doc.org/stdlib-2.3.1/libdoc/timeout/rdoc/Timeout.html
36
+ [unsafe multithreaded behaviors]: http://blog.headius.com/2008/02/ruby-threadraise-threadkill-timeoutrb.html
37
+ [Celluloid::IO]: https://github.com/celluloid/celluloid-io
38
+
22
39
  ## Installation
23
40
 
24
41
  Add this line to your application's Gemfile:
25
42
 
26
43
  ```ruby
27
- gem 'socketry'
44
+ gem "socketry"
28
45
  ```
29
46
 
30
47
  And then execute:
@@ -35,9 +52,31 @@ Or install it yourself as:
35
52
 
36
53
  $ gem install socketry
37
54
 
38
- ## Usage
55
+ ## Basic Usage
56
+
57
+ Below is a basic example of how to use Socketry to make an HTTPS request:
58
+
59
+ ```ruby
60
+ require "socketry"
61
+
62
+ socket = Socketry::SSL::Socket.connect("github.com", 443)
63
+ socket.writepartial("GET / HTTP/1.0\r\nHost: github.com\r\n\r\n")
64
+ p socket.readpartial(1024)
65
+ ```
66
+
67
+ [TCP], [UDP], and [SSL] servers and sockets also available.
39
68
 
40
- TODO: Coming soon!
69
+ [TCP]: https://github.com/socketry/socketry/wiki/TCP
70
+ [UDP]: https://github.com/socketry/socketry/wiki/UDP
71
+ [SSL]: https://github.com/socketry/socketry/wiki/SSL
72
+
73
+ ## Documentation
74
+
75
+ [Please see the Socketry wiki](https://github.com/socketry/socketry/wiki)
76
+ for more detailed documentation and usage notes.
77
+
78
+ [YARD API documentation](http://www.rubydoc.info/gems/socketry/)
79
+ is also available.
41
80
 
42
81
  ## Contributing
43
82
 
@@ -48,8 +87,6 @@ TODO: Coming soon!
48
87
 
49
88
  ## License
50
89
 
51
- Copyright (c) 2016 Tony Arcieri
52
-
53
- Distributed under the MIT License. See
90
+ Copyright (c) 2016 Tony Arcieri. Distributed under the MIT License. See
54
91
  [LICENSE.txt](https://github.com/socketry/socketry/blob/master/LICENSE.txt)
55
92
  for further details.
@@ -100,9 +100,15 @@ module Socketry
100
100
  # @param outbuf [String, NilClass] an optional buffer into which data should be read
101
101
  # @raise [Socketry::Error] an I/O operation failed
102
102
  # @return [String, :wait_readable] data read, or :wait_readable if operation would block
103
- def read_nonblock(size)
103
+ def read_nonblock(size, outbuf: nil)
104
104
  ensure_connected
105
- @ssl_socket.read_nonblock(size, exception: false)
105
+ case outbuf
106
+ when String
107
+ @ssl_socket.read_nonblock(size, outbuf, exception: false)
108
+ when NilClass
109
+ @ssl_socket.read_nonblock(size, exception: false)
110
+ else raise TypeError, "unexpected outbuf class: #{outbuf.class}"
111
+ end
106
112
  # Some buggy Rubies continue to raise exceptions in these cases
107
113
  rescue IO::WaitReadable
108
114
  :wait_readable
@@ -243,14 +243,14 @@ module Socketry
243
243
  #
244
244
  # @return [true, false] true if the socket was open, false if closed
245
245
  def close
246
- return false unless connected?
246
+ return false if closed?
247
247
  @socket.close
248
248
  true
249
249
  ensure
250
250
  @socket = nil
251
251
  end
252
252
 
253
- # Is the socket currently connected?
253
+ # Is the socket closed?
254
254
  #
255
255
  # This method returns the local connection state. However, it's possible
256
256
  # the remote side has closed the connection, so it's not actually
@@ -258,20 +258,20 @@ module Socketry
258
258
  # reading from or writing to it. It's sort of like the Heisenberg
259
259
  # uncertainty principle of sockets.
260
260
  #
261
- # @return [true, false] do we locally think the socket is open?
262
- def connected?
263
- @socket != nil
261
+ # @return [true, false] do we locally think the socket is closed?
262
+ def closed?
263
+ @socket.nil?
264
264
  end
265
265
 
266
266
  private
267
267
 
268
268
  def ensure_connected
269
- return true if connected?
270
- raise StateError, "not connected"
269
+ raise StateError, "not connected" if closed?
270
+ true
271
271
  end
272
272
 
273
273
  def ensure_disconnected
274
- return true unless connected?
274
+ return true if closed?
275
275
  raise StateError, "already connected"
276
276
  end
277
277
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Socketry
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -6,10 +6,10 @@ require "socketry/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "socketry"
8
8
  spec.version = Socketry::VERSION
9
- spec.authors = ["Tony Arcieri", "Zachary Anker"]
9
+ spec.authors = ["Tony Arcieri"]
10
10
  spec.email = ["bascule@gmail.com"]
11
11
  spec.licenses = ["MIT"]
12
- spec.homepage = "https://github.com/celluloid/socketry/"
12
+ spec.homepage = "https://github.com/socketry/socketry/"
13
13
  spec.summary = "High-level wrappers for Ruby sockets with advanced thread-safe timeout support"
14
14
  spec.description = <<-DESCRIPTION.strip.gsub(/\s+/, " ")
15
15
  Socketry wraps Ruby's sockets with an advanced timeout engine which is able to provide multiple
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socketry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
8
- - Zachary Anker
9
8
  autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
@@ -70,7 +69,7 @@ files:
70
69
  - lib/socketry/udp/socket.rb
71
70
  - lib/socketry/version.rb
72
71
  - socketry.gemspec
73
- homepage: https://github.com/celluloid/socketry/
72
+ homepage: https://github.com/socketry/socketry/
74
73
  licenses:
75
74
  - MIT
76
75
  metadata: {}