ffi-rxs 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +10 -0
- data/README.textile +13 -6
- data/examples/request.rb +1 -1
- data/ffi-rxs.gemspec +2 -2
- data/lib/ffi-rxs/constants.rb +12 -1
- data/lib/ffi-rxs/context.rb +1 -2
- data/lib/ffi-rxs/libxs.rb +2 -0
- data/lib/ffi-rxs/message.rb +0 -1
- data/lib/ffi-rxs/poll.rb +0 -1
- data/lib/ffi-rxs/socket.rb +19 -4
- data/lib/ffi-rxs/util.rb +22 -27
- data/lib/ffi-rxs/version.rb +1 -1
- data/spec/context_spec.rb +2 -6
- data/spec/message_spec.rb +2 -0
- data/spec/multipart_spec.rb +2 -0
- data/spec/nonblocking_recv_spec.rb +1 -0
- data/spec/poll_spec.rb +1 -1
- data/spec/pushpull_spec.rb +3 -2
- data/spec/reqrep_spec.rb +1 -0
- data/spec/socket_spec.rb +46 -9
- data/spec/spec_helper.rb +3 -2
- metadata +26 -24
- data/lib/ffi-rxs/constants.rb~ +0 -100
- data/lib/ffi-rxs/context.rb~ +0 -155
- data/lib/ffi-rxs/device.rb~ +0 -28
- data/lib/ffi-rxs/exceptions.rb~ +0 -47
- data/lib/ffi-rxs/libc.rb~ +0 -19
- data/lib/ffi-rxs/libxs.rb~ +0 -156
- data/lib/ffi-rxs/message.rb~ +0 -282
- data/lib/ffi-rxs/poll.rb~ +0 -212
- data/lib/ffi-rxs/poll_items.rb~ +0 -120
- data/lib/ffi-rxs/socket.rb~ +0 -659
- data/lib/ffi-rxs/util.rb~ +0 -105
- data/lib/ffi-rxs/version.rb~ +0 -3
data/lib/ffi-rxs/util.rb~
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
|
2
|
-
module XS
|
3
|
-
|
4
|
-
# These methods don't belong to any specific class. They get included
|
5
|
-
# in the #Context, #Socket and #Poller classes.
|
6
|
-
#
|
7
|
-
module Util
|
8
|
-
|
9
|
-
# Returns true when +rc+ is greater than or equal to 0, false otherwise.
|
10
|
-
#
|
11
|
-
# We use the >= test because xs_poll() returns the number of sockets
|
12
|
-
# that had a read or write event triggered. So, a >= 0 result means
|
13
|
-
# it succeeded.
|
14
|
-
#
|
15
|
-
def self.resultcode_ok? rc
|
16
|
-
rc >= 0
|
17
|
-
end
|
18
|
-
|
19
|
-
# Returns the +errno+ as set by the libxs library.
|
20
|
-
#
|
21
|
-
def self.errno
|
22
|
-
LibXS.xs_errno
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns a string corresponding to the currently set #errno. These
|
26
|
-
# error strings are defined by libxs.
|
27
|
-
#
|
28
|
-
def self.error_string
|
29
|
-
LibXS.xs_strerror(errno).read_string
|
30
|
-
end
|
31
|
-
|
32
|
-
# Returns an array of the form [major, minor, patch] to represent the
|
33
|
-
# version of libzmq.
|
34
|
-
#
|
35
|
-
# Class method! Invoke as: XS::Util.version
|
36
|
-
#
|
37
|
-
def self.version
|
38
|
-
major = FFI::MemoryPointer.new :int
|
39
|
-
minor = FFI::MemoryPointer.new :int
|
40
|
-
patch = FFI::MemoryPointer.new :int
|
41
|
-
LibXS.xs_version major, minor, patch
|
42
|
-
[major.read_int, minor.read_int, patch.read_int]
|
43
|
-
end
|
44
|
-
|
45
|
-
# Attempts to bind to a random tcp port on +host+ up to +max_tries+
|
46
|
-
# times. Returns the port number upon success or nil upon failure.
|
47
|
-
#
|
48
|
-
def self.bind_to_random_tcp_port host = '127.0.0.1', max_tries = 500
|
49
|
-
tries = 0
|
50
|
-
rc = -1
|
51
|
-
|
52
|
-
while !resultcode_ok?(rc) && tries < max_tries
|
53
|
-
tries += 1
|
54
|
-
random = random_port
|
55
|
-
rc = socket.bind "tcp://#{host}:#{random}"
|
56
|
-
end
|
57
|
-
|
58
|
-
resultcode_ok?(rc) ? random : nil
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
# generate a random port between 10_000 and 65534
|
65
|
-
def self.random_port
|
66
|
-
rand(55534) + 10_000
|
67
|
-
end
|
68
|
-
|
69
|
-
# :doc:
|
70
|
-
# Called by most library methods to verify there were no errors during
|
71
|
-
# operation. If any are found, raise the appropriate #XSError.
|
72
|
-
#
|
73
|
-
# When no error is found, this method returns +true+ which is behavior
|
74
|
-
# used internally by #send and #recv.
|
75
|
-
#
|
76
|
-
def error_check source, result_code
|
77
|
-
if -1 == result_code
|
78
|
-
raise_error source, result_code
|
79
|
-
end
|
80
|
-
|
81
|
-
# used by Socket::send/recv, ignored by others
|
82
|
-
true
|
83
|
-
end
|
84
|
-
|
85
|
-
def raise_error source, result_code
|
86
|
-
if 'xs_init' == source || 'xs_socket' == source
|
87
|
-
raise ContextError.new source, result_code, XS::Util.errno, XS::Util.error_string
|
88
|
-
|
89
|
-
elsif ['xs_msg_init', 'xs_msg_init_data', 'xs_msg_copy', 'xs_msg_move'].include?(source)
|
90
|
-
raise MessageError.new source, result_code, XS::Util.errno, XS::Util.error_string
|
91
|
-
|
92
|
-
else
|
93
|
-
puts "else"
|
94
|
-
raise XSError.new source, result_code, -1,
|
95
|
-
"Source [#{source}] does not match any xs_* strings, rc [#{result_code}], errno [#{XS::Util.errno}], error_string [#{XS::Util.error_string}]"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def eagain?
|
100
|
-
EAGAIN == XS::Util.errno
|
101
|
-
end
|
102
|
-
|
103
|
-
end # module Util
|
104
|
-
|
105
|
-
end # module XS
|
data/lib/ffi-rxs/version.rb~
DELETED