protoplasm-em-server 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,14 +28,28 @@ module Protoplasm
28
28
  raise "Must be implemented by the client class"
29
29
  end
30
30
 
31
- def _socket
31
+ def _socket(timeout = 5)
32
32
  count = 0
33
33
  begin
34
34
  host, port = host_port
35
35
  @socket ||= begin
36
- s = TCPSocket.open(host, port)
37
- s.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
38
- s
36
+ addr = Socket.getaddrinfo(host, nil)
37
+ sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
38
+
39
+ if timeout
40
+ secs = Integer(timeout)
41
+ usecs = Integer((timeout - secs) * 1_000_000)
42
+ optval = [secs, usecs].pack("l_2")
43
+ begin
44
+ io.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
45
+ io.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
46
+ rescue Exception => ex
47
+ # Solaris, for one, does not like/support socket timeouts.
48
+ @logger.info "[memcache-client] Unable to use raw socket timeouts: #{ex.class.name}: #{ex.message}" if @logger
49
+ end
50
+ end
51
+ sock.connect(Socket.pack_sockaddr_in(port, addr[0][3]))
52
+ sock
39
53
  end
40
54
  yield @socket if block_given?
41
55
  rescue Errno::EPIPE, Errno::ECONNRESET
@@ -74,7 +88,7 @@ module Protoplasm
74
88
  while data.size < len
75
89
  data << socket.sysread([len - data.size, 4096].min)
76
90
  end
77
- obj = type.response_class.decode(data)
91
+ obj = type.response_class.decode(data.force_encoding('BINARY'))
78
92
  yield obj if block_given?
79
93
  end
80
94
  fetch_objects = false unless type.streaming?
@@ -74,6 +74,7 @@ module Protoplasm
74
74
  obj = type.response_class.new(*args)
75
75
  s = ''
76
76
  obj.encode(s)
77
+ s = s.force_encoding('BINARY')
77
78
  send_data [Types::Response::NORMAL].pack("C")
78
79
  send_data [s.size].pack("Q")
79
80
  send_data s
@@ -1,3 +1,3 @@
1
1
  module Protoplasm
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protoplasm-em-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-07 00:00:00.000000000 Z
12
+ date: 2012-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70098254751460 !ruby/object:Gem::Requirement
16
+ requirement: &70111869145700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70098254751460
24
+ version_requirements: *70111869145700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: beefcake
27
- requirement: &70098254748100 !ruby/object:Gem::Requirement
27
+ requirement: &70111869145200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.3.7
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70098254748100
35
+ version_requirements: *70111869145200
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70098254746360 !ruby/object:Gem::Requirement
38
+ requirement: &70111869144780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70098254746360
46
+ version_requirements: *70111869144780
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
- requirement: &70098254734380 !ruby/object:Gem::Requirement
49
+ requirement: &70111869144240 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 2.6.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70098254734380
57
+ version_requirements: *70111869144240
58
58
  description: A protoplasm server backed by EventMachine.
59
59
  email:
60
60
  - joshbuddy@gmail.com
@@ -87,18 +87,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- segments:
91
- - 0
92
- hash: -844767653554300454
93
90
  required_rubygems_version: !ruby/object:Gem::Requirement
94
91
  none: false
95
92
  requirements:
96
93
  - - ! '>='
97
94
  - !ruby/object:Gem::Version
98
95
  version: '0'
99
- segments:
100
- - 0
101
- hash: -844767653554300454
102
96
  requirements: []
103
97
  rubyforge_project: protoplasm-em-server
104
98
  rubygems_version: 1.8.15
@@ -108,3 +102,4 @@ summary: A protoplasm server backed by EventMachine
108
102
  test_files:
109
103
  - test/protoplasm_test.rb
110
104
  - test/test_helper.rb
105
+ has_rdoc: