async-io 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de9c8da76ca6bc5d7065b6729d187dcc235d2ea7
4
- data.tar.gz: 299c561ae952ae21a611cfa083f98b3789f89d6b
3
+ metadata.gz: b747d80615958a841ef56cbdb4d1aaa71a3cf3b1
4
+ data.tar.gz: b613b3dea61e0345267a52c458b51cd7c3ec7993
5
5
  SHA512:
6
- metadata.gz: 396a2e21a43f0048282a144737226361fe9b0c6cd1376c7cc359c8522ab1e0a20fb721397ee6a18d81bc5eb9db87a0aa36c341786a58d69f521f3a82287eab53
7
- data.tar.gz: d0627c41180d5d5faa92155a4feea2ee5f75285ad54105f2f9f17fe9a6a35789b9ecc9b3c0d2f2829f6987de4c7616ef8923eb41ffbee4b187eb8fd62a0a0529
6
+ metadata.gz: 23605b1a8f9ef861b7657d15f5b41abc6ca5efe63cc09a67da2cb7b3f14c9776964a76adf9ec1f044233576339ad963a6f1b18c4acbb239c806e3514857e1b67
7
+ data.tar.gz: bae87bb2a744df43d33c21ea8fe59ff37adee72c5fc9901b36ea456c0702763acf61d935039ec54fe1597a3a334da3307dc517fbef84d805462ae072750dacc1
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative 'socket'
22
+ require 'uri'
22
23
 
23
24
  module Async
24
25
  module IO
@@ -27,6 +28,11 @@ module Async
27
28
  include Comparable
28
29
 
29
30
  class << self
31
+ def parse(string, **options)
32
+ uri = URI.parse(string)
33
+ self.__send__(uri.scheme, uri.host, uri.port, **options)
34
+ end
35
+
30
36
  def tcp(*args, **options)
31
37
  self.new([:tcp, *args], **options)
32
38
  end
@@ -106,11 +106,12 @@ module Async
106
106
  task.annotate "connecting to #{remote_address.inspect}"
107
107
 
108
108
  wrapper = build(remote_address.afamily, remote_address.socktype, protocol) do |socket|
109
+ socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true)
110
+
109
111
  if local_address
110
- socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_REUSEADDR, true)
111
- socket.bind(local_address.to_sockaddr) if local_address
112
+ socket.bind(local_address.to_sockaddr)
112
113
  end
113
-
114
+
114
115
  self.new(socket, task.reactor)
115
116
  end
116
117
 
@@ -24,12 +24,11 @@ require_relative 'generic'
24
24
  module Async
25
25
  module IO
26
26
  class Stream
27
- def initialize(io, block_size: 1024*4, sync: false)
27
+ def initialize(io, block_size: 1024*8)
28
28
  @io = io
29
29
  @eof = false
30
30
 
31
31
  @block_size = block_size
32
- @sync = sync
33
32
 
34
33
  @read_buffer = BinaryString.new
35
34
  @write_buffer = BinaryString.new
@@ -37,9 +36,6 @@ module Async
37
36
 
38
37
  attr :io
39
38
 
40
- # The "sync mode" of the stream. See IO#sync for full details.
41
- attr_accessor :sync
42
-
43
39
  # Reads `size` bytes from the stream. If size is not specified, read until end of file.
44
40
  def read(size = nil)
45
41
  return "" if size == 0
@@ -58,7 +54,7 @@ module Async
58
54
  def write(string)
59
55
  @write_buffer << string
60
56
 
61
- if @sync || @write_buffer.size > @block_size
57
+ if @write_buffer.size > @block_size
62
58
  flush
63
59
  end
64
60
 
@@ -100,17 +96,20 @@ module Async
100
96
  def read_until(pattern)
101
97
  index = @read_buffer.index(pattern)
102
98
 
103
- until index || @eof
99
+ until index
100
+ offset = @read_buffer.size
101
+
104
102
  fill_read_buffer
105
103
 
106
- index = @read_buffer.index(pattern)
104
+ return if @eof
105
+
106
+ index = @read_buffer.index(pattern, offset)
107
107
  end
108
108
 
109
- if line = consume_read_buffer(index)
110
- consume_read_buffer(pattern.bytesize)
111
-
112
- return line
113
- end
109
+ matched = @read_buffer.slice!(0, index)
110
+ @read_buffer.slice!(0, pattern.bytesize)
111
+
112
+ return matched
114
113
  end
115
114
 
116
115
  def peek
@@ -124,7 +123,6 @@ module Async
124
123
  # Fills the buffer from the underlying stream.
125
124
  def fill_read_buffer
126
125
  if buffer = @io.read(@block_size)
127
- # We guarantee that the read_buffer remains ASCII-8BIT because read should always return ASCII-8BIT
128
126
  @read_buffer << buffer
129
127
  else
130
128
  @eof = true
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Async
22
22
  module IO
23
- VERSION = "0.4.0"
23
+ VERSION = "0.5.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-08 00:00:00.000000000 Z
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async