Module: UV::Stream
Instance Method Summary
collapse
Methods included from Handle
#active?, close, #close, #closing?, #initialize, #ref, #unref
Methods included from Assertions
#assert_arity, #assert_block, #assert_boolean, #assert_signal, #assert_type
Methods included from Resource
#check_result, #check_result!, #to_ptr
Methods included from Listener
define_callback, undefine_callbacks
Instance Method Details
#accept ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/uv/stream.rb', line 17
def accept
client = loop.send(handle_name)
check_result! UV.accept(handle, client.handle)
client
end
|
#listen(backlog, &block) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/uv/stream.rb', line 5
def listen(backlog, &block)
assert_block(block)
assert_arity(1, block)
assert_type(Integer, backlog, "backlog must be an Integer")
@listen_block = block
check_result! UV.listen(handle, Integer(backlog), callback(:on_listen))
self
end
|
#readable? ⇒ Boolean
67
68
69
|
# File 'lib/uv/stream.rb', line 67
def readable?
UV.is_readable(handle) > 0
end
|
#shutdown(&block) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/uv/stream.rb', line 56
def shutdown(&block)
assert_block(block)
assert_arity(1, block)
@shutdown_block = block
check_result! UV.shutdown(UV.create_request(:uv_shutdown), handle, callback(:on_shutdown))
self
end
|
#start_read(&block) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/uv/stream.rb', line 25
def start_read(&block)
assert_block(block)
assert_arity(2, block)
@read_block = block
check_result! UV.read_start(handle, callback(:on_allocate), callback(:on_read))
self
end
|
#stop_read ⇒ Object
36
37
38
39
40
|
# File 'lib/uv/stream.rb', line 36
def stop_read
check_result! UV.read_stop(handle)
self
end
|
#writable? ⇒ Boolean
71
72
73
|
# File 'lib/uv/stream.rb', line 71
def writable?
UV.is_writable(handle) > 0
end
|
#write(data, &block) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/uv/stream.rb', line 42
def write(data, &block)
assert_block(block)
assert_arity(1, block)
assert_type(String, data, "data must be a String")
@write_block = block
size = data.respond_to?(:bytesize) ? data.bytesize : data.size
buffer = UV.buf_init(FFI::MemoryPointer.from_string(data), size)
check_result! UV.write(UV.create_request(:uv_write), handle, buffer, 1, callback(:on_write))
self
end
|