iproto 0.3.6 → 0.3.7

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.
data/iproto.gemspec CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'iproto'
7
- s.version = '0.3.6'
8
- s.date = '2012-07-18'
7
+ s.version = '0.3.7'
8
+ s.date = '2012-08-07'
9
9
  s.rubyforge_project = 'iproto'
10
10
 
11
11
  s.summary = "Mail.Ru simple network protocol"
@@ -37,4 +37,5 @@ Gem::Specification.new do |s|
37
37
  ## Test files will be grabbed from the file list. Make sure the path glob
38
38
  ## matches what you actually use.
39
39
  s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
40
- end
40
+ s.add_dependency 'bin_utils', ['= 0.0.2']
41
+ end
@@ -1,6 +1,6 @@
1
+ require 'bin_utils'
1
2
  module IProto
2
3
  module ConnectionAPI
3
- PACK = 'VVV'.freeze
4
4
  DEFAULT_RECONNECT = 0.1
5
5
  HEADER_SIZE = 12
6
6
 
@@ -11,5 +11,12 @@ module IProto
11
11
  def send_request(request_id, data)
12
12
  # for override
13
13
  end
14
+
15
+ BINARY = ::Encoding::BINARY
16
+ def pack_request(request_type, request_id, body)
17
+ data = ''.force_encoding(BINARY)
18
+ ::BinUtils.append_int32_le!(data, request_type, body.bytesize, request_id)
19
+ ::BinUtils.append_string!(data, body)
20
+ end
14
21
  end
15
22
  end
data/lib/iproto/em.rb CHANGED
@@ -83,7 +83,8 @@ module IProto
83
83
 
84
84
  def receive_chunk(chunk)
85
85
  if @_state == :receive_header
86
- @type, body_size, @request_id = chunk.unpack(PACK)
86
+ body_size = ::BinUtils.get_int32_le(chunk, 4)
87
+ @request_id = ::BinUtils.get_int32_le(chunk, 8)
87
88
  if body_size > 0
88
89
  @_needed_size = body_size
89
90
  @_state = :receive_body
@@ -154,7 +155,7 @@ module IProto
154
155
 
155
156
  def _do_send_request(request_type, body, request)
156
157
  while @waiting_requests.include?(request_id = next_request_id); end
157
- send_data [request_type, body.size, request_id].pack(PACK) + body
158
+ send_data pack_request(request_type, request_id, body)
158
159
  @waiting_requests[request_id] = request
159
160
  end
160
161
 
@@ -48,7 +48,7 @@ module IProto
48
48
  def send_request(request_type, body)
49
49
  begin
50
50
  request_id = next_request_id
51
- r = socket.send ([request_type, body.bytesize, request_id].pack(PACK) << body), 0
51
+ socket.send pack_request(request_type, request_id, body), 0
52
52
  response_size = recv_header request_id
53
53
  recv_response response_size
54
54
  rescue Errno::EPIPE, Retry => e
@@ -61,7 +61,8 @@ module IProto
61
61
 
62
62
  def recv_header(request_id)
63
63
  header = socket.read(HEADER_SIZE) or _raise_disconnected('disconnected while read', @retry ? :retry : true)
64
- type, response_size, recv_request_id = header.unpack(PACK)
64
+ response_size = ::BinUtils.get_int32_le(header, 4)
65
+ recv_request_id = ::BinUtils.get_int32_le(header, 8)
65
66
  unless request_id == recv_request_id
66
67
  raise UnexpectedResponse.new("Waiting response for request_id #{request_id}, but received for #{recv_request_id}")
67
68
  end
data/lib/iproto.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module IProto
2
- VERSION = '0.3.6'
2
+ VERSION = '0.3.7'
3
3
  class IProtoError < StandardError; end
4
4
  class ConnectionError < IProtoError; end
5
5
  class CouldNotConnect < ConnectionError; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iproto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-18 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-08-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bin_utils
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.2
14
30
  description: Mail.Ru simple network protocol
15
31
  email: ceo@prepor.ru
16
32
  executables: []
@@ -54,3 +70,4 @@ signing_key:
54
70
  specification_version: 2
55
71
  summary: Mail.Ru simple network protocol
56
72
  test_files: []
73
+ has_rdoc: