Class: Docker::API::Transport::Tcp

Inherits:
Base
  • Object
show all
Defined in:
lib/docker/api/transport/tcp.rb

Overview

A daemon reached over plain TCP. Unencrypted, so appropriate only on a trusted network or a loopback address.

Direct Known Subclasses

Tls

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, open_timeout: 10) ⇒ Tcp

Returns a new instance of Tcp.

Parameters:

  • host (String)

    the host to dial

  • port (Integer)

    the port to dial

  • open_timeout (Numeric) (defaults to: 10)

    seconds to wait for the connection



21
22
23
24
25
26
# File 'lib/docker/api/transport/tcp.rb', line 21

def initialize(host:, port:, open_timeout: 10)
  super()
  @host = host
  @port = Integer(port)
  @open_timeout = open_timeout
end

Instance Attribute Details

#hostString (readonly)

Returns the host.

Returns:

  • (String)

    the host



13
14
15
# File 'lib/docker/api/transport/tcp.rb', line 13

def host
  @host
end

#portInteger (readonly)

Returns the port.

Returns:

  • (Integer)

    the port



16
17
18
# File 'lib/docker/api/transport/tcp.rb', line 16

def port
  @port
end

Instance Method Details

#connectIO

Returns a connected TCP socket.

Returns:

  • (IO)

    a connected TCP socket

Raises:



30
31
32
33
34
# File 'lib/docker/api/transport/tcp.rb', line 30

def connect
  dial("tcp://#{host}:#{port}") do
    Socket.tcp(host, port, connect_timeout: @open_timeout)
  end
end

#host_headerString

Returns:

  • (String)


37
38
39
# File 'lib/docker/api/transport/tcp.rb', line 37

def host_header
  "#{host}:#{port}"
end

#to_sString Also known as: inspect

Returns:

  • (String)


42
43
44
# File 'lib/docker/api/transport/tcp.rb', line 42

def to_s
  "#<Docker::API::Transport::Tcp host=#{host} port=#{port}>"
end