thrift 0.22.0 → 0.24.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 +4 -4
- data/README.md +235 -17
- data/benchmark/benchmark.rb +23 -8
- data/benchmark/client.rb +50 -6
- data/benchmark/server.rb +46 -7
- data/benchmark/thin_server.rb +2 -0
- data/ext/binary_protocol_accelerated.c +154 -42
- data/ext/bytes.c +14 -0
- data/ext/compact_protocol.c +138 -45
- data/ext/constants.h +12 -0
- data/ext/extconf.rb +17 -8
- data/ext/memory_buffer.c +44 -7
- data/ext/protocol.c +29 -0
- data/ext/protocol.h +35 -0
- data/ext/struct.c +48 -17
- data/ext/thrift_native.c +28 -3
- data/lib/thrift/bytes.rb +70 -100
- data/lib/thrift/client.rb +54 -13
- data/lib/thrift/exceptions.rb +6 -5
- data/lib/thrift/multiplexed_processor.rb +20 -10
- data/lib/thrift/processor.rb +7 -6
- data/lib/thrift/protocol/base_protocol.rb +52 -21
- data/lib/thrift/protocol/binary_protocol.rb +65 -20
- data/lib/thrift/protocol/binary_protocol_accelerated.rb +6 -5
- data/lib/thrift/protocol/compact_protocol.rb +76 -41
- data/lib/thrift/protocol/header_protocol.rb +321 -0
- data/lib/thrift/protocol/json_protocol.rb +44 -27
- data/lib/thrift/protocol/multiplexed_protocol.rb +6 -5
- data/lib/thrift/protocol/protocol_decorator.rb +13 -4
- data/lib/thrift/serializer/deserializer.rb +6 -5
- data/lib/thrift/serializer/serializer.rb +5 -5
- data/lib/thrift/server/base_server.rb +5 -4
- data/lib/thrift/server/mongrel_http_server.rb +7 -6
- data/lib/thrift/server/nonblocking_server.rb +35 -9
- data/lib/thrift/server/simple_server.rb +13 -5
- data/lib/thrift/server/thin_http_server.rb +4 -3
- data/lib/thrift/server/thread_pool_server.rb +7 -6
- data/lib/thrift/server/threaded_server.rb +13 -5
- data/lib/thrift/struct.rb +12 -11
- data/lib/thrift/struct_union.rb +14 -9
- data/lib/thrift/thrift_native.rb +3 -2
- data/lib/thrift/transport/base_server_transport.rb +8 -5
- data/lib/thrift/transport/base_transport.rb +18 -14
- data/lib/thrift/transport/buffered_transport.rb +7 -6
- data/lib/thrift/transport/framed_transport.rb +8 -7
- data/lib/thrift/transport/header_transport.rb +562 -0
- data/lib/thrift/transport/http_client_transport.rb +2 -1
- data/lib/thrift/transport/io_stream_transport.rb +4 -3
- data/lib/thrift/transport/memory_buffer_transport.rb +13 -6
- data/lib/thrift/transport/server_socket.rb +14 -8
- data/lib/thrift/transport/socket.rb +126 -60
- data/lib/thrift/transport/ssl_server_socket.rb +4 -3
- data/lib/thrift/transport/ssl_socket.rb +45 -13
- data/lib/thrift/transport/unix_server_socket.rb +9 -5
- data/lib/thrift/transport/unix_socket.rb +7 -6
- data/lib/thrift/types.rb +10 -6
- data/lib/thrift/union.rb +15 -8
- data/lib/thrift/uuid.rb +50 -0
- data/lib/thrift.rb +4 -1
- data/spec/ThriftSpec.thrift +21 -1
- data/spec/base_protocol_spec.rb +21 -2
- data/spec/base_transport_spec.rb +48 -8
- data/spec/binary_protocol_accelerated_spec.rb +1 -0
- data/spec/binary_protocol_spec.rb +1 -2
- data/spec/binary_protocol_spec_shared.rb +206 -155
- data/spec/bytes_spec.rb +71 -114
- data/spec/client_spec.rb +86 -19
- data/spec/compact_protocol_spec.rb +153 -16
- data/spec/constants_demo_spec.rb +102 -0
- data/spec/exception_spec.rb +1 -1
- data/spec/flat_spec.rb +1 -0
- data/spec/header_protocol_spec.rb +476 -0
- data/spec/header_transport_spec.rb +431 -0
- data/spec/http_client_spec.rb +5 -6
- data/spec/json_protocol_spec.rb +69 -47
- data/spec/multiplexed_processor_spec.rb +75 -0
- data/spec/namespaced_spec.rb +1 -1
- data/spec/nonblocking_server_spec.rb +174 -8
- data/spec/processor_spec.rb +1 -1
- data/spec/recursion_depth_spec.rb +223 -0
- data/spec/serializer_spec.rb +1 -1
- data/spec/server_socket_spec.rb +38 -1
- data/spec/server_spec.rb +60 -9
- data/spec/socket_spec.rb +119 -13
- data/spec/socket_spec_shared.rb +73 -9
- data/spec/spec_helper.rb +2 -1
- data/spec/ssl_server_socket_spec.rb +52 -1
- data/spec/ssl_socket_spec.rb +181 -11
- data/spec/struct_nested_containers_spec.rb +2 -2
- data/spec/struct_spec.rb +114 -9
- data/spec/support/header_protocol_helper.rb +55 -0
- data/spec/thin_http_server_spec.rb +4 -18
- data/spec/types_spec.rb +26 -26
- data/spec/union_spec.rb +70 -11
- data/spec/unix_socket_spec.rb +17 -2
- data/spec/uuid_validation_spec.rb +239 -0
- data/test/fuzz/Makefile +779 -0
- data/test/fuzz/Makefile.am +173 -0
- data/test/fuzz/Makefile.in +775 -0
- data/test/fuzz/README.md +149 -0
- data/test/fuzz/fuzz_common.rb +96 -0
- data/{lib/thrift/core_ext.rb → test/fuzz/fuzz_parse_binary_protocol.rb} +4 -4
- data/{lib/thrift/core_ext/fixnum.rb → test/fuzz/fuzz_parse_binary_protocol_accelerated.rb} +7 -13
- data/test/fuzz/fuzz_parse_binary_protocol_accelerated_harness.rb +23 -0
- data/test/fuzz/fuzz_parse_binary_protocol_harness.rb +23 -0
- data/test/fuzz/fuzz_parse_compact_protocol.rb +23 -0
- data/test/fuzz/fuzz_parse_compact_protocol_harness.rb +23 -0
- data/test/fuzz/fuzz_parse_json_protocol.rb +23 -0
- data/test/fuzz/fuzz_parse_json_protocol_harness.rb +23 -0
- data/test/fuzz/fuzz_roundtrip_binary_protocol.rb +23 -0
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated.rb +23 -0
- data/test/fuzz/fuzz_roundtrip_binary_protocol_accelerated_harness.rb +23 -0
- data/test/fuzz/fuzz_roundtrip_binary_protocol_harness.rb +23 -0
- data/test/fuzz/fuzz_roundtrip_compact_protocol.rb +23 -0
- data/test/fuzz/fuzz_roundtrip_compact_protocol_harness.rb +23 -0
- data/test/fuzz/fuzz_roundtrip_json_protocol.rb +23 -0
- data/test/fuzz/fuzz_roundtrip_json_protocol_harness.rb +23 -0
- data/test/fuzz/fuzz_tracer.rb +29 -0
- metadata +105 -70
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
|
-
#
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
#
|
|
3
4
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
4
5
|
# or more contributor license agreements. See the NOTICE file
|
|
5
6
|
# distributed with this work for additional information
|
|
@@ -7,18 +8,16 @@
|
|
|
7
8
|
# to you under the Apache License, Version 2.0 (the
|
|
8
9
|
# "License"); you may not use this file except in compliance
|
|
9
10
|
# with the License. You may obtain a copy of the License at
|
|
10
|
-
#
|
|
11
|
+
#
|
|
11
12
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
#
|
|
13
|
+
#
|
|
13
14
|
# Unless required by applicable law or agreed to in writing,
|
|
14
15
|
# software distributed under the License is distributed on an
|
|
15
16
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
17
|
# KIND, either express or implied. See the License for the
|
|
17
18
|
# specific language governing permissions and limitations
|
|
18
19
|
# under the License.
|
|
19
|
-
#
|
|
20
|
-
|
|
21
|
-
require 'base64'
|
|
20
|
+
#
|
|
22
21
|
|
|
23
22
|
module Thrift
|
|
24
23
|
class LookaheadReader
|
|
@@ -181,6 +180,8 @@ module Thrift
|
|
|
181
180
|
"set"
|
|
182
181
|
when Types::LIST
|
|
183
182
|
"lst"
|
|
183
|
+
when Types::UUID
|
|
184
|
+
"uid"
|
|
184
185
|
else
|
|
185
186
|
raise NotImplementedError
|
|
186
187
|
end
|
|
@@ -209,6 +210,8 @@ module Thrift
|
|
|
209
210
|
result = Types::SET
|
|
210
211
|
elsif (name == "lst")
|
|
211
212
|
result = Types::LIST
|
|
213
|
+
elsif (name == "uid")
|
|
214
|
+
result = Types::UUID
|
|
212
215
|
else
|
|
213
216
|
result = Types::STOP
|
|
214
217
|
end
|
|
@@ -255,7 +258,7 @@ module Thrift
|
|
|
255
258
|
if (ch_value.kind_of? String)
|
|
256
259
|
ch_value = ch.bytes.first
|
|
257
260
|
end
|
|
258
|
-
trans.write(ch_value.to_s(16).rjust(4,'0'))
|
|
261
|
+
trans.write(ch_value.to_s(16).rjust(4, '0'))
|
|
259
262
|
end
|
|
260
263
|
|
|
261
264
|
# Write the character ch as part of a JSON string, escaping as appropriate.
|
|
@@ -266,9 +269,9 @@ module Thrift
|
|
|
266
269
|
# <other> : escape using "\<other>" notation
|
|
267
270
|
kJSONCharTable = [
|
|
268
271
|
# 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
|
269
|
-
0, 0, 0, 0, 0, 0, 0, 0,'b','t','n', 0,'f','r', 0, 0, # 0
|
|
272
|
+
0, 0, 0, 0, 0, 0, 0, 0, 'b', 't', 'n', 0, 'f', 'r', 0, 0, # 0
|
|
270
273
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, # 1
|
|
271
|
-
1, 1,'"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, # 2
|
|
274
|
+
1, 1, '"', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, # 2
|
|
272
275
|
]
|
|
273
276
|
|
|
274
277
|
ch_value = ch[0]
|
|
@@ -311,7 +314,7 @@ module Thrift
|
|
|
311
314
|
def write_json_base64(str)
|
|
312
315
|
@context.write(trans)
|
|
313
316
|
trans.write(@@kJSONStringDelimiter)
|
|
314
|
-
trans.write(
|
|
317
|
+
trans.write([str].pack('m0'))
|
|
315
318
|
trans.write(@@kJSONStringDelimiter)
|
|
316
319
|
end
|
|
317
320
|
|
|
@@ -477,6 +480,11 @@ module Thrift
|
|
|
477
480
|
write_json_base64(str)
|
|
478
481
|
end
|
|
479
482
|
|
|
483
|
+
def write_uuid(uuid)
|
|
484
|
+
UUID.validate_uuid!(uuid)
|
|
485
|
+
write_json_string(uuid.downcase)
|
|
486
|
+
end
|
|
487
|
+
|
|
480
488
|
##
|
|
481
489
|
# Reading functions
|
|
482
490
|
##
|
|
@@ -493,15 +501,11 @@ module Thrift
|
|
|
493
501
|
# characters above the BMP are encoded as two escape sequences (surrogate pairs),
|
|
494
502
|
# which is not yet implemented
|
|
495
503
|
def read_json_escape_char
|
|
496
|
-
str =
|
|
497
|
-
str
|
|
498
|
-
str
|
|
499
|
-
str
|
|
500
|
-
|
|
501
|
-
str.hex.chr(Encoding::UTF_8)
|
|
502
|
-
else
|
|
503
|
-
str.hex.chr
|
|
504
|
-
end
|
|
504
|
+
str = +@reader.read
|
|
505
|
+
str << @reader.read
|
|
506
|
+
str << @reader.read
|
|
507
|
+
str << @reader.read
|
|
508
|
+
str.hex.chr(Encoding::UTF_8)
|
|
505
509
|
end
|
|
506
510
|
|
|
507
511
|
# Decodes a JSON string, including unescaping, and returns the string via str
|
|
@@ -521,8 +525,7 @@ module Thrift
|
|
|
521
525
|
@context.read(@reader)
|
|
522
526
|
end
|
|
523
527
|
read_json_syntax_char(@@kJSONStringDelimiter)
|
|
524
|
-
|
|
525
|
-
str = ""
|
|
528
|
+
str = +''
|
|
526
529
|
while (true)
|
|
527
530
|
ch = @reader.read
|
|
528
531
|
if (ch == @@kJSONStringDelimiter)
|
|
@@ -540,7 +543,7 @@ module Thrift
|
|
|
540
543
|
ch = escape_char_vals[pos]
|
|
541
544
|
end
|
|
542
545
|
end
|
|
543
|
-
str
|
|
546
|
+
str << ch
|
|
544
547
|
end
|
|
545
548
|
return str
|
|
546
549
|
end
|
|
@@ -555,20 +558,20 @@ module Thrift
|
|
|
555
558
|
str += '='
|
|
556
559
|
end
|
|
557
560
|
end
|
|
558
|
-
|
|
561
|
+
str.unpack1('m0')
|
|
559
562
|
end
|
|
560
563
|
|
|
561
564
|
# Reads a sequence of characters, stopping at the first one that is not
|
|
562
565
|
# a valid JSON numeric character.
|
|
563
566
|
def read_json_numeric_chars
|
|
564
|
-
str =
|
|
567
|
+
str = String.new(encoding: Encoding::UTF_8)
|
|
565
568
|
while (true)
|
|
566
569
|
ch = @reader.peek
|
|
567
570
|
if (!is_json_numeric(ch))
|
|
568
571
|
break;
|
|
569
572
|
end
|
|
570
573
|
ch = @reader.read
|
|
571
|
-
str
|
|
574
|
+
str << ch
|
|
572
575
|
end
|
|
573
576
|
return str
|
|
574
577
|
end
|
|
@@ -709,6 +712,7 @@ module Thrift
|
|
|
709
712
|
key_type = get_type_id_for_type_name(read_json_string)
|
|
710
713
|
val_type = get_type_id_for_type_name(read_json_string)
|
|
711
714
|
size = read_json_integer
|
|
715
|
+
validate_container_size(size)
|
|
712
716
|
read_json_object_start
|
|
713
717
|
[key_type, val_type, size]
|
|
714
718
|
end
|
|
@@ -720,7 +724,10 @@ module Thrift
|
|
|
720
724
|
|
|
721
725
|
def read_list_begin
|
|
722
726
|
read_json_array_start
|
|
723
|
-
|
|
727
|
+
type = get_type_id_for_type_name(read_json_string)
|
|
728
|
+
size = read_json_integer
|
|
729
|
+
validate_container_size(size)
|
|
730
|
+
[type, size]
|
|
724
731
|
end
|
|
725
732
|
|
|
726
733
|
def read_list_end
|
|
@@ -729,7 +736,10 @@ module Thrift
|
|
|
729
736
|
|
|
730
737
|
def read_set_begin
|
|
731
738
|
read_json_array_start
|
|
732
|
-
|
|
739
|
+
type = get_type_id_for_type_name(read_json_string)
|
|
740
|
+
size = read_json_integer
|
|
741
|
+
validate_container_size(size)
|
|
742
|
+
[type, size]
|
|
733
743
|
end
|
|
734
744
|
|
|
735
745
|
def read_set_end
|
|
@@ -769,6 +779,13 @@ module Thrift
|
|
|
769
779
|
read_json_base64
|
|
770
780
|
end
|
|
771
781
|
|
|
782
|
+
def read_uuid
|
|
783
|
+
uuid = read_json_string
|
|
784
|
+
raise EOFError.new if uuid.length < 36
|
|
785
|
+
UUID.validate_uuid!(uuid)
|
|
786
|
+
uuid.tap(&:downcase!)
|
|
787
|
+
end
|
|
788
|
+
|
|
772
789
|
def to_s
|
|
773
790
|
"json(#{super.to_s})"
|
|
774
791
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,9 +7,9 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
@@ -34,9 +35,9 @@ module Thrift
|
|
|
34
35
|
@protocol.write_message_begin("#{@service_name}:#{name}", type, seqid)
|
|
35
36
|
else
|
|
36
37
|
@protocol.write_message_begin(name, type, seqid)
|
|
37
|
-
end
|
|
38
|
+
end
|
|
38
39
|
end
|
|
39
|
-
|
|
40
|
+
|
|
40
41
|
def to_s
|
|
41
42
|
"multiplexed(#{@service_name=@protocol.to_s})"
|
|
42
43
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,9 +7,9 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
@@ -111,6 +112,10 @@ module Thrift
|
|
|
111
112
|
@protocol.write_binary(buf)
|
|
112
113
|
end
|
|
113
114
|
|
|
115
|
+
def write_uuid(uuid)
|
|
116
|
+
@protocol.write_uuid(uuid)
|
|
117
|
+
end
|
|
118
|
+
|
|
114
119
|
def read_message_begin
|
|
115
120
|
@protocol.read_message_begin
|
|
116
121
|
end
|
|
@@ -190,5 +195,9 @@ module Thrift
|
|
|
190
195
|
def read_binary
|
|
191
196
|
@protocol.read_binary
|
|
192
197
|
end
|
|
198
|
+
|
|
199
|
+
def read_uuid
|
|
200
|
+
@protocol.read_uuid
|
|
201
|
+
end
|
|
193
202
|
end
|
|
194
|
-
end
|
|
203
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,16 +7,16 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
16
|
# KIND, either express or implied. See the License for the
|
|
16
17
|
# specific language governing permissions and limitations
|
|
17
18
|
# under the License.
|
|
18
|
-
#
|
|
19
|
+
#
|
|
19
20
|
|
|
20
21
|
module Thrift
|
|
21
22
|
class Deserializer
|
|
@@ -30,4 +31,4 @@ module Thrift
|
|
|
30
31
|
base
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
|
-
end
|
|
34
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,16 +7,16 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
16
|
# KIND, either express or implied. See the License for the
|
|
16
17
|
# specific language governing permissions and limitations
|
|
17
18
|
# under the License.
|
|
18
|
-
#
|
|
19
|
+
#
|
|
19
20
|
|
|
20
21
|
module Thrift
|
|
21
22
|
class Serializer
|
|
@@ -31,4 +32,3 @@ module Thrift
|
|
|
31
32
|
end
|
|
32
33
|
end
|
|
33
34
|
end
|
|
34
|
-
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,9 +7,9 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
@@ -19,7 +20,7 @@
|
|
|
19
20
|
|
|
20
21
|
module Thrift
|
|
21
22
|
class BaseServer
|
|
22
|
-
def initialize(processor, server_transport, transport_factory=nil, protocol_factory=nil)
|
|
23
|
+
def initialize(processor, server_transport, transport_factory = nil, protocol_factory = nil)
|
|
23
24
|
@processor = processor
|
|
24
25
|
@server_transport = server_transport
|
|
25
26
|
@transport_factory = transport_factory ? transport_factory : Thrift::BaseTransportFactory.new
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,16 +7,16 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
16
|
# KIND, either express or implied. See the License for the
|
|
16
17
|
# specific language governing permissions and limitations
|
|
17
18
|
# under the License.
|
|
18
|
-
#
|
|
19
|
+
#
|
|
19
20
|
|
|
20
21
|
require 'mongrel'
|
|
21
22
|
|
|
@@ -38,12 +39,12 @@ module Thrift
|
|
|
38
39
|
@processor.process protocol, protocol
|
|
39
40
|
end
|
|
40
41
|
else
|
|
41
|
-
response.start(404) {
|
|
42
|
+
response.start(404) {}
|
|
42
43
|
end
|
|
43
44
|
end
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
def initialize(processor, opts={})
|
|
47
|
+
def initialize(processor, opts = {})
|
|
47
48
|
Kernel.warn "[DEPRECATION WARNING] `Thrift::MongrelHTTPServer` is deprecated. Please use `Thrift::ThinHTTPServer` instead."
|
|
48
49
|
port = opts[:port] || 80
|
|
49
50
|
ip = opts[:ip] || "0.0.0.0"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,16 +7,16 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
16
|
# KIND, either express or implied. See the License for the
|
|
16
17
|
# specific language governing permissions and limitations
|
|
17
18
|
# under the License.
|
|
18
|
-
#
|
|
19
|
+
#
|
|
19
20
|
|
|
20
21
|
require 'logger'
|
|
21
22
|
require 'thread'
|
|
@@ -23,7 +24,7 @@ require 'thread'
|
|
|
23
24
|
module Thrift
|
|
24
25
|
# this class expects to always use a FramedTransport for reading messages
|
|
25
26
|
class NonblockingServer < BaseServer
|
|
26
|
-
def initialize(processor, server_transport, transport_factory=nil, protocol_factory=nil, num=20, logger=nil)
|
|
27
|
+
def initialize(processor, server_transport, transport_factory = nil, protocol_factory = nil, num = 20, logger = nil)
|
|
27
28
|
super(processor, server_transport, transport_factory, protocol_factory)
|
|
28
29
|
@num_threads = num
|
|
29
30
|
if logger.nil?
|
|
@@ -97,7 +98,7 @@ module Thrift
|
|
|
97
98
|
|
|
98
99
|
class IOManager # :nodoc:
|
|
99
100
|
DEFAULT_BUFFER = 2**20
|
|
100
|
-
|
|
101
|
+
|
|
101
102
|
def initialize(processor, server_transport, transport_factory, protocol_factory, num, logger)
|
|
102
103
|
@processor = processor
|
|
103
104
|
@server_transport = server_transport
|
|
@@ -106,7 +107,7 @@ module Thrift
|
|
|
106
107
|
@num_threads = num
|
|
107
108
|
@logger = logger
|
|
108
109
|
@connections = []
|
|
109
|
-
@buffers = Hash.new { |h,k| h[k] =
|
|
110
|
+
@buffers = Hash.new { |h, k| h[k] = Bytes.empty_byte_buffer }
|
|
110
111
|
@signal_queue = Queue.new
|
|
111
112
|
@signal_pipes = IO.pipe
|
|
112
113
|
@signal_pipes[1].sync = true
|
|
@@ -138,11 +139,16 @@ module Thrift
|
|
|
138
139
|
|
|
139
140
|
def ensure_closed
|
|
140
141
|
kill_worker_threads if @worker_threads
|
|
141
|
-
@iom_thread
|
|
142
|
+
if @iom_thread&.alive?
|
|
143
|
+
@iom_thread.kill
|
|
144
|
+
@iom_thread.join
|
|
145
|
+
end
|
|
146
|
+
close_connections
|
|
147
|
+
close_signal_pipes
|
|
142
148
|
end
|
|
143
149
|
|
|
144
150
|
private
|
|
145
|
-
|
|
151
|
+
|
|
146
152
|
def run
|
|
147
153
|
spin_worker_threads
|
|
148
154
|
|
|
@@ -246,6 +252,26 @@ module Thrift
|
|
|
246
252
|
@worker_threads.clear
|
|
247
253
|
end
|
|
248
254
|
|
|
255
|
+
def close_connections
|
|
256
|
+
@connections.each do |fd|
|
|
257
|
+
begin
|
|
258
|
+
fd.close
|
|
259
|
+
rescue IOError, SystemCallError, TransportException
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
@connections.clear
|
|
263
|
+
@buffers.clear
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
def close_signal_pipes
|
|
267
|
+
@signal_pipes.each do |pipe|
|
|
268
|
+
begin
|
|
269
|
+
pipe.close unless pipe.closed?
|
|
270
|
+
rescue IOError
|
|
271
|
+
end
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
|
|
249
275
|
def slice_frame!(buf)
|
|
250
276
|
if buf.length >= 4
|
|
251
277
|
size = buf.unpack('N').first
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,9 +7,9 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
@@ -23,7 +24,14 @@ module Thrift
|
|
|
23
24
|
begin
|
|
24
25
|
@server_transport.listen
|
|
25
26
|
loop do
|
|
26
|
-
|
|
27
|
+
begin
|
|
28
|
+
client = @server_transport.accept
|
|
29
|
+
rescue Errno::ECONNRESET, Errno::EPIPE
|
|
30
|
+
next
|
|
31
|
+
rescue => e
|
|
32
|
+
next if defined?(OpenSSL::SSL::SSLError) && e.is_a?(OpenSSL::SSL::SSLError)
|
|
33
|
+
raise
|
|
34
|
+
end
|
|
27
35
|
trans = @transport_factory.get_transport(client)
|
|
28
36
|
prot = @protocol_factory.get_protocol(trans)
|
|
29
37
|
begin
|
|
@@ -39,7 +47,7 @@ module Thrift
|
|
|
39
47
|
@server_transport.close
|
|
40
48
|
end
|
|
41
49
|
end
|
|
42
|
-
|
|
50
|
+
|
|
43
51
|
def to_s
|
|
44
52
|
"simple(#{super.to_s})"
|
|
45
53
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
@@ -32,7 +33,7 @@ module Thrift
|
|
|
32
33
|
# * :ip
|
|
33
34
|
# * :path
|
|
34
35
|
# * :protocol_factory
|
|
35
|
-
def initialize(processor, options={})
|
|
36
|
+
def initialize(processor, options = {})
|
|
36
37
|
port = options[:port] || 80
|
|
37
38
|
ip = options[:ip] || "0.0.0.0"
|
|
38
39
|
path = options[:path] || "/"
|
|
@@ -60,9 +61,9 @@ module Thrift
|
|
|
60
61
|
run lambda { |env|
|
|
61
62
|
request = Rack::Request.new(env)
|
|
62
63
|
if RackApplication.valid_thrift_request?(request)
|
|
63
|
-
RackApplication.successful_request(request, processor, protocol_factory)
|
|
64
|
+
RackApplication.successful_request(request, processor, protocol_factory).finish
|
|
64
65
|
else
|
|
65
|
-
RackApplication.failed_request
|
|
66
|
+
RackApplication.failed_request.finish
|
|
66
67
|
end
|
|
67
68
|
}
|
|
68
69
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,22 +7,22 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
16
|
# KIND, either express or implied. See the License for the
|
|
16
17
|
# specific language governing permissions and limitations
|
|
17
18
|
# under the License.
|
|
18
|
-
#
|
|
19
|
+
#
|
|
19
20
|
|
|
20
21
|
require 'thread'
|
|
21
22
|
|
|
22
23
|
module Thrift
|
|
23
24
|
class ThreadPoolServer < BaseServer
|
|
24
|
-
def initialize(processor, server_transport, transport_factory=nil, protocol_factory=nil, num=20)
|
|
25
|
+
def initialize(processor, server_transport, transport_factory = nil, protocol_factory = nil, num = 20)
|
|
25
26
|
super(processor, server_transport, transport_factory, protocol_factory)
|
|
26
27
|
@thread_q = SizedQueue.new(num)
|
|
27
28
|
@exception_q = Queue.new
|
|
@@ -71,7 +72,7 @@ module Thrift
|
|
|
71
72
|
@server_transport.close
|
|
72
73
|
end
|
|
73
74
|
end
|
|
74
|
-
|
|
75
|
+
|
|
75
76
|
def to_s
|
|
76
77
|
"threadpool(#{super.to_s})"
|
|
77
78
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
#
|
|
2
3
|
# Licensed to the Apache Software Foundation (ASF) under one
|
|
3
4
|
# or more contributor license agreements. See the NOTICE file
|
|
4
5
|
# distributed with this work for additional information
|
|
@@ -6,9 +7,9 @@
|
|
|
6
7
|
# to you under the Apache License, Version 2.0 (the
|
|
7
8
|
# "License"); you may not use this file except in compliance
|
|
8
9
|
# with the License. You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
+
#
|
|
10
11
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
+
#
|
|
12
13
|
# Unless required by applicable law or agreed to in writing,
|
|
13
14
|
# software distributed under the License is distributed on an
|
|
14
15
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
@@ -25,7 +26,14 @@ module Thrift
|
|
|
25
26
|
begin
|
|
26
27
|
@server_transport.listen
|
|
27
28
|
loop do
|
|
28
|
-
|
|
29
|
+
begin
|
|
30
|
+
client = @server_transport.accept
|
|
31
|
+
rescue Errno::ECONNRESET, Errno::EPIPE
|
|
32
|
+
next
|
|
33
|
+
rescue => e
|
|
34
|
+
next if defined?(OpenSSL::SSL::SSLError) && e.is_a?(OpenSSL::SSL::SSLError)
|
|
35
|
+
raise
|
|
36
|
+
end
|
|
29
37
|
trans = @transport_factory.get_transport(client)
|
|
30
38
|
prot = @protocol_factory.get_protocol(trans)
|
|
31
39
|
Thread.new(prot, trans) do |p, t|
|
|
@@ -43,7 +51,7 @@ module Thrift
|
|
|
43
51
|
@server_transport.close
|
|
44
52
|
end
|
|
45
53
|
end
|
|
46
|
-
|
|
54
|
+
|
|
47
55
|
def to_s
|
|
48
56
|
"threaded(#{super.to_s})"
|
|
49
57
|
end
|