Class: Net::PTTH::Socket

Inherits:
Struct
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/net/ptth/socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject

Returns the value of attribute host

Returns:

  • (Object)

    the current value of host



6
7
8
# File 'lib/net/ptth/socket.rb', line 6

def host
  @host
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



6
7
8
# File 'lib/net/ptth/socket.rb', line 6

def port
  @port
end

Instance Method Details

#closeObject



29
30
31
32
33
# File 'lib/net/ptth/socket.rb', line 29

def close
  close_socket
rescue IOError => e
  # I'm already closed
end

#open?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/net/ptth/socket.rb', line 35

def open?
  !raw_socket.closed?
end

#read(bytes = 4096*10) ⇒ Object



9
10
11
# File 'lib/net/ptth/socket.rb', line 9

def read(bytes = 4096*10)
  raw_socket.readpartial(bytes)
end

#write(data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/net/ptth/socket.rb', line 13

def write(data)
  retry_count = 3
  begin
    raw_socket.write(data)
  rescue Errno::EPIPE => e
    close unless open?

    retry_count -= 1
    if retry_count > 0
      retry
    else
      raise SocketError.new("Couldn't reconnect! Errno::EPIPE")
    end
  end
end