iproto 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
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.1'
8
- s.date = '2012-01-23'
7
+ s.version = '0.2'
8
+ s.date = '2012-01-27'
9
9
  s.rubyforge_project = 'iproto'
10
10
 
11
11
  s.summary = "Mail.Ru simple network protocol"
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  # = MANIFEST =
24
24
  s.files = %w[
25
+ LICENSE
25
26
  README.md
26
27
  Rakefile
27
28
  iproto.gemspec
data/lib/iproto.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module IProto
2
- VERSION = '0.1'
2
+ VERSION = '0.2'
3
3
  class IProtoError < StandardError; end
4
4
  class CouldNotConnect < IProtoError; end
5
5
  class UnexpectedResponse < IProtoError; end
@@ -8,5 +8,9 @@ module IProto
8
8
  end
9
9
  @next_request_id
10
10
  end
11
+
12
+ def send_request(request_id, data)
13
+ # for override
14
+ end
11
15
  end
12
16
  end
data/lib/iproto/em.rb CHANGED
@@ -92,8 +92,9 @@ module IProto
92
92
  # end FixedHeaderAndBody API
93
93
 
94
94
  # begin ConnectionAPI
95
- def send_packet(request_id, data)
96
- send_data data
95
+ def send_request(request_type, body)
96
+ request_id = next_request_id
97
+ send_data [request_type, body.size, request_id].pack('LLL') + body
97
98
  f = Fiber.current
98
99
  waiting_requests[request_id] = f
99
100
  Fiber.yield
@@ -1,27 +1,27 @@
1
1
  require 'socket'
2
2
  module IProto
3
-
4
3
  # TODO: timeouts
5
4
  class TCPSocket < ::TCPSocket
6
5
  include IProto::ConnectionAPI
7
6
 
8
7
  # begin ConnectionAPI
9
- def send_packet(request_id, data)
10
- send data, 0
11
- body_size = recv_header request_id
12
- recv_body body_size
8
+ def send_request(request_type, body)
9
+ request_id = next_request_id
10
+ r = send [request_type, body.bytesize, request_id].pack('LLL') + body, 0
11
+ response_size = recv_header request_id
12
+ recv_response response_size
13
13
  end
14
14
  # end ConnectionAPI
15
15
 
16
16
  def recv_header(request_id)
17
- header = recv(12)
18
- type, body_size, recv_request_id = header.unpack('L3')
17
+ header = read(12)
18
+ type, response_size, recv_request_id = header.unpack('L3')
19
19
  raise UnexpectedResponse.new("Waiting response for request_id #{request_id}, but received for #{recv_request_id}") unless request_id == recv_request_id
20
- body_size
20
+ response_size
21
21
  end
22
22
 
23
- def recv_body(body_size)
24
- recv(body_size)
23
+ def recv_response(response_size)
24
+ read(response_size)
25
25
  end
26
26
  end
27
27
  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.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-23 00:00:00.000000000Z
12
+ date: 2012-01-27 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Mail.Ru simple network protocol
15
15
  email: ceo@prepor.ru
@@ -19,6 +19,7 @@ extra_rdoc_files:
19
19
  - README.md
20
20
  - LICENSE
21
21
  files:
22
+ - LICENSE
22
23
  - README.md
23
24
  - Rakefile
24
25
  - iproto.gemspec
@@ -26,7 +27,6 @@ files:
26
27
  - lib/iproto/connection_api.rb
27
28
  - lib/iproto/em.rb
28
29
  - lib/iproto/tcp_socket.rb
29
- - LICENSE
30
30
  homepage: http://github.com/mailru/iproto-ruby
31
31
  licenses: []
32
32
  post_install_message: