Module: SimpleRPC::SocketProtocol::Simple
- Defined in:
- lib/simplerpc/socket_protocol.rb
Overview
Sends string buffers back and forth using a simple protocol.
This method is significantly slower, but significantly more secure, than SocketProtocol::Stream, and is used for the auth handshake.
Class Method Summary collapse
-
.recv(s) ⇒ Object
Receive a buffer.
-
.send(s, buf) ⇒ Object
Send a buffer.
Class Method Details
.recv(s) ⇒ Object
Receive a buffer
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/simplerpc/socket_protocol.rb', line 77 def self.recv(s) buflen = s.gets.to_s.chomp.to_i return nil if buflen <= 0 buf = '' recieved = 0 while recieved < buflen do str = s.read(buflen - recieved) buf += str recieved += str.length end return buf end |
.send(s, buf) ⇒ Object
Send a buffer
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/simplerpc/socket_protocol.rb', line 60 def self.send(s, buf) # Dump into buffer buflen = buf.length # Send buffer length s.puts(buflen) # Send buffer sent = 0 while sent < buflen do sent += s.write(buf[sent..-1]) end # raise Errno::ETIMEDOUT unless x end |