memcached-server 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b24344e4d59a83ed5efc916e5e162c045968e9e54bdac468138d082387cc518a
4
- data.tar.gz: fae266a5d5a9cc51c311566fcb6b7632e8f26517cb672213095e443e33695001
3
+ metadata.gz: 8b9e9bb722d09ab81f8ea0e3b1556d9fa96e2e022022ad719ee2921530e25d58
4
+ data.tar.gz: cd607bdbbadade18327ae7e797856466ca1baccbb1e3f4f86153c6e4b1c03eda
5
5
  SHA512:
6
- metadata.gz: 4695cc451824b4ecda4fa3d5b10bf20f3c4d45494f51b49fcdf3a8fe93cacddd4649f84fef49167a1809ac72f5db0debb2474a06bf726692a8fe53ece85d033f
7
- data.tar.gz: ba52fb4818a83c87336352157a0cf6c8d02236ab8e11ad818c07a4c78f24f4aeedba3ca30329b1ce0599799de243f53b3669fea461f20c2619f16beda0b08958
6
+ metadata.gz: 523e091a87a2f2dfa0036331ebcc5cc4fcce61ac25031398419eae55cf6c19dd651f651dd0735134f2155f97dbabae1057eff6777e9d8adc90f158811f8ba655
7
+ data.tar.gz: 77bc03d72982b8f4a33e8e7c8eb72148f2e1cf7269d5fc78e03222ee7913eb0f46cb6bc4413f1dca1be5173a7b1e5f4d7e89d8f3df4e627e90ee751f4377a4e1
data/bin/memcached-server CHANGED
@@ -9,6 +9,4 @@ port = ARGV[1]
9
9
  server = MemcachedServer::Server.new(hostname, port)
10
10
  puts ('Server running on port %d' % server.port)
11
11
 
12
- run = Thread.new {server.run()}
13
-
14
- run.join()
12
+ server.run()
@@ -176,8 +176,7 @@ module MemcachedServer
176
176
  # @param flags [Integer] Is an arbitrary unsigned integer (written out in decimal)
177
177
  # @param exptime [Integer] The exptime of the Item to store
178
178
  # @param bytes [Integer] The byte size of <data_block>
179
- # @param data_block [String] Is a chunk of arbitrary 8-bit data of length <bytes>
180
- # @return [String] The reply that describes the result of the operation
179
+ # @param data_block [String] Is a chunk of arbitrary 8-bit data of length <bytes>
181
180
  def store_item(key, flags, exptime, bytes, data_block)
182
181
 
183
182
  item = Item.new(key, flags, exptime, bytes, data_block)
@@ -42,14 +42,14 @@ module MemcachedServer
42
42
 
43
43
  close = false
44
44
  while command = connection.gets()
45
-
45
+
46
46
  puts("Command: #{command} | Connection: #{connection.to_s}")
47
47
 
48
48
  valid_command = validate_command(command)
49
49
  if valid_command
50
50
  close = run_command(connection, valid_command)
51
- else
52
- connection.puts(Error::CLIENT_ERROR % [" Undefined command. Please check the command syntax and try again."])
51
+ else
52
+ connection.puts(Error::ERROR)
53
53
  end
54
54
 
55
55
  break if close
@@ -61,19 +61,18 @@ module MemcachedServer
61
61
  puts ("Connection closed to: #{connection}.")
62
62
 
63
63
  end
64
-
65
64
  end
65
+
66
66
  rescue => exception
67
67
  error = Error::SERVER_ERROR % exception.message
68
68
  connection.puts(error)
69
69
  end
70
70
  end
71
71
 
72
- # Runs a valid memcache command
73
- #
72
+ # Runs a valid memcache command.
74
73
  # Depends on MemcachedServer::Memcache method names.
75
- # In some cases, to make #send method work the MemcachedServer::Memcache
76
- # corresponding method must be equal to valid_command[:name]
74
+ # In some cases, when the #send method is used, the corresponding
75
+ # MemcachedServer::Memcache method must be equal to valid_command[:name]
77
76
  #
78
77
  # @param connection [TCPSocket] Client's socket
79
78
  # @param valid_command [MatchData] It encapsulates all the results of a valid command pattern match
@@ -92,8 +91,8 @@ module MemcachedServer
92
91
  noreply = !valid_command[:noreply].nil?
93
92
  data = self.read_bytes(connection, bytes)
94
93
 
95
- reply = @mc.send(name.to_sym, key, flags, exptime, bytes, data)
96
- connection.puts(reply) unless noreply
94
+ reply = @mc.send(name.to_sym, key, flags, exptime, bytes, data) unless data.nil?()
95
+ connection.puts(reply) unless noreply || reply.nil?()
97
96
 
98
97
  return false
99
98
 
@@ -103,8 +102,8 @@ module MemcachedServer
103
102
  bytes = valid_command[:bytes].to_i
104
103
  data = self.read_bytes(connection, bytes)
105
104
 
106
- reply = @mc.send(name.to_sym, key, bytes, data)
107
- connection.puts(reply) unless noreply
105
+ reply = @mc.send(name.to_sym, key, bytes, data) unless data.nil?()
106
+ connection.puts(reply) unless noreply || reply.nil?()
108
107
 
109
108
  return false
110
109
 
@@ -118,8 +117,8 @@ module MemcachedServer
118
117
  data = self.read_bytes(connection, bytes)
119
118
  cas_id = valid_command[:cas_id].to_i()
120
119
 
121
- reply = @mc.cas(key, flags, exptime, bytes, cas_id, data)
122
- connection.puts(reply) unless noreply
120
+ reply = @mc.cas(key, flags, exptime, bytes, cas_id, data) unless data.nil?()
121
+ connection.puts(reply) unless noreply || reply.nil?()
123
122
 
124
123
  return false
125
124
 
@@ -158,11 +157,17 @@ module MemcachedServer
158
157
  #
159
158
  # @param connection [TCPSocket] Client's socket
160
159
  # @param bytes [Integer] The number of bytes to read
161
- # @return [String] The message read
160
+ # @return [String, nil] The message read
162
161
  def read_bytes(connection, bytes)
163
162
 
164
- return connection.read(bytes + 1).chomp()
163
+ data_chunk = connection.read(bytes + 1).chomp()
165
164
 
165
+ if data_chunk.bytesize() != bytes
166
+ connection.puts(Error::CLIENT_ERROR % [" bad data chunk"])
167
+ return nil
168
+ end
169
+
170
+ return data_chunk
166
171
  end
167
172
 
168
173
  # Validates a command.
@@ -184,6 +189,12 @@ module MemcachedServer
184
189
  return nil
185
190
  end
186
191
 
192
+ # Accepts a connection
193
+ # @return [TCPSocket] An accepted TCPSocket for the incoming connection.
194
+ def accept()
195
+ return @connection.accept()
196
+ end
197
+
187
198
  end
188
199
 
189
200
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memcached-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Andrés Puglia Laca
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-27 00:00:00.000000000 Z
11
+ date: 2021-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec