Class: Sanford::Worker::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/sanford/worker.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(socket) ⇒ Connection

Returns a new instance of Connection.



40
41
42
43
44
# File 'lib/sanford/worker.rb', line 40

def initialize(socket)
  @socket     = socket
  @connection = Sanford::Protocol::Connection.new(@socket)
  @timeout    = (ENV['SANFORD_TIMEOUT'] || DEFAULT_TIMEOUT).to_f
end

Instance Attribute Details

#timeoutObject (readonly)

Returns the value of attribute timeout.



38
39
40
# File 'lib/sanford/worker.rb', line 38

def timeout
  @timeout
end

Instance Method Details

#closeObject



54
# File 'lib/sanford/worker.rb', line 54

def close;       @connection.close;          end

#close_writeObject



55
# File 'lib/sanford/worker.rb', line 55

def close_write; @connection.close_write;    end

#peek_dataObject



53
# File 'lib/sanford/worker.rb', line 53

def peek_data;   @connection.peek(@timeout); end

#read_dataObject



52
# File 'lib/sanford/worker.rb', line 52

def read_data;   @connection.read(@timeout); end

#write_data(data) ⇒ Object



46
47
48
49
50
# File 'lib/sanford/worker.rb', line 46

def write_data(data)
  TCPCork.apply(@socket)
  @connection.write data
  TCPCork.remove(@socket)
end