thrift 0.9.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/{README → README.md} +0 -0
- data/ext/binary_protocol_accelerated.c +12 -12
- data/ext/compact_protocol.c +4 -2
- data/ext/constants.h +3 -0
- data/ext/extconf.rb +3 -1
- data/ext/memory_buffer.c +1 -1
- data/ext/strlcpy.h +7 -3
- data/ext/struct.c +27 -4
- data/ext/thrift_native.c +6 -0
- data/lib/thrift.rb +8 -5
- data/lib/thrift/client.rb +13 -4
- data/lib/thrift/multiplexed_processor.rb +76 -0
- data/lib/thrift/processor.rb +24 -6
- data/lib/thrift/protocol/base_protocol.rb +13 -3
- data/lib/thrift/protocol/binary_protocol.rb +8 -1
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +8 -0
- data/lib/thrift/protocol/compact_protocol.rb +10 -1
- data/lib/thrift/protocol/json_protocol.rb +23 -6
- data/lib/thrift/protocol/multiplexed_protocol.rb +44 -0
- data/lib/thrift/protocol/protocol_decorator.rb +194 -0
- data/lib/thrift/server/base_server.rb +8 -2
- data/lib/thrift/server/simple_server.rb +5 -1
- data/lib/thrift/server/thread_pool_server.rb +5 -1
- data/lib/thrift/server/threaded_server.rb +5 -1
- data/lib/thrift/transport/base_server_transport.rb +1 -1
- data/lib/thrift/transport/base_transport.rb +8 -0
- data/lib/thrift/transport/buffered_transport.rb +9 -1
- data/lib/thrift/transport/framed_transport.rb +9 -1
- data/lib/thrift/transport/http_client_transport.rb +5 -0
- data/lib/thrift/transport/io_stream_transport.rb +4 -1
- data/lib/thrift/transport/memory_buffer_transport.rb +4 -0
- data/lib/thrift/transport/server_socket.rb +6 -1
- data/lib/thrift/transport/socket.rb +21 -17
- data/lib/thrift/transport/ssl_server_socket.rb +41 -0
- data/lib/thrift/transport/ssl_socket.rb +51 -0
- data/lib/thrift/transport/unix_server_socket.rb +5 -1
- data/lib/thrift/transport/unix_socket.rb +5 -1
- data/lib/thrift/union.rb +3 -6
- data/spec/BaseService.thrift +27 -0
- data/spec/ExtendedService.thrift +25 -0
- data/spec/Referenced.thrift +44 -0
- data/spec/ThriftNamespacedSpec.thrift +53 -0
- data/spec/base_protocol_spec.rb +79 -71
- data/spec/base_transport_spec.rb +155 -117
- data/spec/binary_protocol_accelerated_spec.rb +6 -2
- data/spec/binary_protocol_spec.rb +16 -8
- data/spec/binary_protocol_spec_shared.rb +75 -72
- data/spec/bytes_spec.rb +38 -38
- data/spec/client_spec.rb +41 -42
- data/spec/compact_protocol_spec.rb +32 -17
- data/spec/exception_spec.rb +54 -54
- data/spec/flat_spec.rb +62 -0
- data/spec/http_client_spec.rb +52 -33
- data/spec/json_protocol_spec.rb +170 -131
- data/spec/namespaced_spec.rb +67 -0
- data/spec/nonblocking_server_spec.rb +16 -16
- data/spec/processor_spec.rb +26 -26
- data/spec/serializer_spec.rb +20 -20
- data/spec/server_socket_spec.rb +27 -22
- data/spec/server_spec.rb +91 -51
- data/spec/socket_spec.rb +23 -16
- data/spec/socket_spec_shared.rb +31 -31
- data/spec/spec_helper.rb +4 -1
- data/spec/ssl_server_socket_spec.rb +34 -0
- data/spec/ssl_socket_spec.rb +78 -0
- data/spec/struct_nested_containers_spec.rb +24 -24
- data/spec/struct_spec.rb +120 -120
- data/spec/thin_http_server_spec.rb +19 -18
- data/spec/types_spec.rb +56 -53
- data/spec/union_spec.rb +51 -40
- data/spec/unix_socket_spec.rb +43 -34
- metadata +189 -123
- data/CHANGELOG +0 -1
@@ -26,6 +26,12 @@ module Thrift
|
|
26
26
|
@protocol_factory = protocol_factory ? protocol_factory : Thrift::BinaryProtocolFactory.new
|
27
27
|
end
|
28
28
|
|
29
|
-
def serve
|
29
|
+
def serve
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
"server(#{@protocol_factory.to_s}(#{@transport_factory.to_s}(#{@server_transport.to_s})))"
|
35
|
+
end
|
30
36
|
end
|
31
|
-
end
|
37
|
+
end
|
@@ -99,11 +99,19 @@ module Thrift
|
|
99
99
|
alias_method :<<, :write
|
100
100
|
|
101
101
|
def flush; end
|
102
|
+
|
103
|
+
def to_s
|
104
|
+
"base"
|
105
|
+
end
|
102
106
|
end
|
103
107
|
|
104
108
|
class BaseTransportFactory
|
105
109
|
def get_transport(trans)
|
106
110
|
return trans
|
107
111
|
end
|
112
|
+
|
113
|
+
def to_s
|
114
|
+
"base"
|
115
|
+
end
|
108
116
|
end
|
109
117
|
end
|
@@ -104,11 +104,19 @@ module Thrift
|
|
104
104
|
|
105
105
|
@transport.flush
|
106
106
|
end
|
107
|
+
|
108
|
+
def to_s
|
109
|
+
"buffered(#{@transport.to_s})"
|
110
|
+
end
|
107
111
|
end
|
108
112
|
|
109
113
|
class BufferedTransportFactory < BaseTransportFactory
|
110
114
|
def get_transport(transport)
|
111
115
|
return BufferedTransport.new(transport)
|
112
116
|
end
|
117
|
+
|
118
|
+
def to_s
|
119
|
+
"buffered"
|
120
|
+
end
|
113
121
|
end
|
114
|
-
end
|
122
|
+
end
|
@@ -99,6 +99,10 @@ module Thrift
|
|
99
99
|
@wbuf = Bytes.empty_byte_buffer
|
100
100
|
end
|
101
101
|
|
102
|
+
def to_s
|
103
|
+
"framed(#{@transport.to_s})"
|
104
|
+
end
|
105
|
+
|
102
106
|
private
|
103
107
|
|
104
108
|
def read_frame
|
@@ -113,5 +117,9 @@ module Thrift
|
|
113
117
|
def get_transport(transport)
|
114
118
|
return FramedTransport.new(transport)
|
115
119
|
end
|
120
|
+
|
121
|
+
def to_s
|
122
|
+
"framed"
|
123
|
+
end
|
116
124
|
end
|
117
|
-
end
|
125
|
+
end
|
@@ -35,5 +35,8 @@ module Thrift
|
|
35
35
|
def write(buf); @output.write(Bytes.force_binary_encoding(buf)) end
|
36
36
|
def close; @input.close; @output.close end
|
37
37
|
def to_io; @input end # we're assuming this is used in a IO.select for reading
|
38
|
+
def to_s
|
39
|
+
"iostream(input=#{@input.to_s},output=#{@output.to_s})"
|
40
|
+
end
|
38
41
|
end
|
39
|
-
end
|
42
|
+
end
|
@@ -33,26 +33,28 @@ module Thrift
|
|
33
33
|
attr_accessor :handle, :timeout
|
34
34
|
|
35
35
|
def open
|
36
|
-
|
37
|
-
addrinfo = ::Socket::getaddrinfo(@host, @port, nil, ::Socket::SOCK_STREAM).first
|
38
|
-
@handle = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
|
39
|
-
@handle.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
|
40
|
-
sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
|
36
|
+
for addrinfo in ::Socket::getaddrinfo(@host, @port, nil, ::Socket::SOCK_STREAM) do
|
41
37
|
begin
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
raise TransportException.new(TransportException::NOT_OPEN, "Connection timeout to #{@desc}")
|
46
|
-
end
|
38
|
+
socket = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
|
39
|
+
socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
|
40
|
+
sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
|
47
41
|
begin
|
48
|
-
|
49
|
-
rescue Errno::
|
42
|
+
socket.connect_nonblock(sockaddr)
|
43
|
+
rescue Errno::EINPROGRESS
|
44
|
+
unless IO.select(nil, [ socket ], nil, @timeout)
|
45
|
+
next
|
46
|
+
end
|
47
|
+
begin
|
48
|
+
socket.connect_nonblock(sockaddr)
|
49
|
+
rescue Errno::EISCONN
|
50
|
+
end
|
50
51
|
end
|
52
|
+
return @handle = socket
|
53
|
+
rescue StandardError => e
|
54
|
+
next
|
51
55
|
end
|
52
|
-
@handle
|
53
|
-
rescue StandardError => e
|
54
|
-
raise TransportException.new(TransportException::NOT_OPEN, "Could not connect to #{@desc}: #{e}")
|
55
56
|
end
|
57
|
+
raise TransportException.new(TransportException::NOT_OPEN, "Could not connect to #{@desc}: #{e}")
|
56
58
|
end
|
57
59
|
|
58
60
|
def open?
|
@@ -132,8 +134,10 @@ module Thrift
|
|
132
134
|
@handle = nil
|
133
135
|
end
|
134
136
|
|
135
|
-
|
136
|
-
|
137
|
+
alias to_io handle
|
138
|
+
|
139
|
+
def to_s
|
140
|
+
"socket(#{@host}:#{@port})"
|
137
141
|
end
|
138
142
|
end
|
139
143
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'socket'
|
22
|
+
|
23
|
+
module Thrift
|
24
|
+
class SSLServerSocket < ServerSocket
|
25
|
+
def initialize(host_or_port, port = nil, ssl_context = nil)
|
26
|
+
super(host_or_port, port)
|
27
|
+
@ssl_context = ssl_context
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_accessor :ssl_context
|
31
|
+
|
32
|
+
def listen
|
33
|
+
socket = TCPServer.new(@host, @port)
|
34
|
+
@handle = OpenSSL::SSL::SSLServer.new(socket, @ssl_context)
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
"ssl(#{super.to_s})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
|
20
|
+
module Thrift
|
21
|
+
class SSLSocket < Socket
|
22
|
+
def initialize(host='localhost', port=9090, timeout=nil, ssl_context=nil)
|
23
|
+
super(host, port, timeout)
|
24
|
+
@ssl_context = ssl_context
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_accessor :ssl_context
|
28
|
+
|
29
|
+
def open
|
30
|
+
socket = super
|
31
|
+
@handle = OpenSSL::SSL::SSLSocket.new(socket, @ssl_context)
|
32
|
+
begin
|
33
|
+
@handle.connect_nonblock
|
34
|
+
@handle.post_connection_check(@host)
|
35
|
+
@handle
|
36
|
+
rescue IO::WaitReadable
|
37
|
+
IO.select([ @handle ], nil, nil, @timeout)
|
38
|
+
retry
|
39
|
+
rescue IO::WaitWritable
|
40
|
+
IO.select(nil, [ @handle ], nil, @timeout)
|
41
|
+
retry
|
42
|
+
rescue StandardError => e
|
43
|
+
raise TransportException.new(TransportException::NOT_OPEN, "Could not connect to #{@desc}: #{e}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
"ssl(#{super.to_s})"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/thrift/union.rb
CHANGED
@@ -87,12 +87,9 @@ module Thrift
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def ==(other)
|
90
|
-
other
|
91
|
-
end
|
92
|
-
|
93
|
-
def eql?(other)
|
94
|
-
self.class == other.class && self == other
|
90
|
+
other.equal?(self) || other.instance_of?(self.class) && @setfield == other.get_set_field && @value == other.get_value
|
95
91
|
end
|
92
|
+
alias_method :eql?, :==
|
96
93
|
|
97
94
|
def hash
|
98
95
|
[self.class.name, @setfield, @value].hash
|
@@ -176,4 +173,4 @@ module Thrift
|
|
176
173
|
end
|
177
174
|
end
|
178
175
|
end
|
179
|
-
end
|
176
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
namespace rb Base
|
20
|
+
|
21
|
+
struct Hello {
|
22
|
+
1: string greeting = "hello world"
|
23
|
+
}
|
24
|
+
|
25
|
+
service BaseService {
|
26
|
+
Hello greeting(1:bool english)
|
27
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
namespace rb Extended
|
20
|
+
|
21
|
+
include "BaseService.thrift"
|
22
|
+
|
23
|
+
service ExtendedService extends BaseService.BaseService {
|
24
|
+
void ping()
|
25
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/*
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
4
|
+
* distributed with this work for additional information
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
7
|
+
* "License"); you may not use this file except in compliance
|
8
|
+
* with the License. You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
13
|
+
* software distributed under the License is distributed on an
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
* KIND, either express or implied. See the License for the
|
16
|
+
* specific language governing permissions and limitations
|
17
|
+
* under the License.
|
18
|
+
*/
|
19
|
+
|
20
|
+
#
|
21
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
22
|
+
# or more contributor license agreements. See the NOTICE file
|
23
|
+
# distributed with this work for additional information
|
24
|
+
# regarding copyright ownership. The ASF licenses this file
|
25
|
+
# to you under the Apache License, Version 2.0 (the
|
26
|
+
# "License"); you may not use this file except in compliance
|
27
|
+
# with the License. You may obtain a copy of the License at
|
28
|
+
#
|
29
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
30
|
+
#
|
31
|
+
# Unless required by applicable law or agreed to in writing,
|
32
|
+
# software distributed under the License is distributed on an
|
33
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
34
|
+
# KIND, either express or implied. See the License for the
|
35
|
+
# specific language governing permissions and limitations
|
36
|
+
# under the License.
|
37
|
+
#
|
38
|
+
|
39
|
+
namespace rb OtherNamespace
|
40
|
+
|
41
|
+
enum SomeEnum {
|
42
|
+
ONE
|
43
|
+
TWO
|
44
|
+
}
|