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



4
5
6
# File 'lib/net/ptth/socket.rb', line 4

def host
  @host
end

#portObject

Returns the value of attribute port

Returns:

  • (Object)

    the current value of port



4
5
6
# File 'lib/net/ptth/socket.rb', line 4

def port
  @port
end

Instance Method Details

#closeObject



15
16
17
18
19
# File 'lib/net/ptth/socket.rb', line 15

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

#open?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/net/ptth/socket.rb', line 21

def open?
  !raw_socket.closed?
end

#raw_socketObject



25
26
27
# File 'lib/net/ptth/socket.rb', line 25

def raw_socket
  @_socket ||= TCPSocket.new(host, port)
end

#read(bytes = 4096*10) ⇒ Object



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

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

#write(data) ⇒ Object



11
12
13
# File 'lib/net/ptth/socket.rb', line 11

def write(data)
  raw_socket.write(data)
end