module SimpleRPC::SocketProtocol::Simple
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.
Public Class Methods
recv(s)
click to toggle source
Receive a buffer
# 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)
click to toggle source
Send a buffer
# 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