Class: Ione::Io::Acceptor

Inherits:
Object
  • Object
show all
Defined in:
lib/ione/io/acceptor.rb

Overview

An acceptor wraps a server socket and accepts client connections.

Since:

  • v1.1.0

Constant Summary collapse

BINDING_STATE =

Since:

  • v1.1.0

0
CONNECTED_STATE =

Since:

  • v1.1.0

1
CLOSED_STATE =

Since:

  • v1.1.0

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#backlogObject (readonly)

Since:

  • v1.1.0



16
17
18
# File 'lib/ione/io/acceptor.rb', line 16

def backlog
  @backlog
end

Instance Method Details

#closeObject

Stop accepting connections

Since:

  • v1.1.0



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ione/io/acceptor.rb', line 63

def close
  @lock.synchronize do
    return false if @state == CLOSED_STATE
    @state = CLOSED_STATE
  end
  if @io
    begin
      @io.close
    rescue SystemCallError, IOError
      # nothing to do, the socket was most likely already closed
    ensure
      @io = nil
    end
  end
  true
end

#closed?Boolean

Returns true if the acceptor has stopped accepting connections

Returns:

  • (Boolean)

Since:

  • v1.1.0



86
87
88
# File 'lib/ione/io/acceptor.rb', line 86

def closed?
  @state == CLOSED_STATE
end

#connected?Boolean

Returns true if the acceptor is accepting connections

Returns:

  • (Boolean)

Since:

  • v1.1.0



91
92
93
# File 'lib/ione/io/acceptor.rb', line 91

def connected?
  @state != CLOSED_STATE
end

#on_accept {|the| ... } ⇒ Object

Register a listener to be notified when client connections are accepted

Yield Parameters:

Since:

  • v1.1.0



35
36
37
38
39
# File 'lib/ione/io/acceptor.rb', line 35

def on_accept(&listener)
  @lock.synchronize do
    @accept_listeners << listener
  end
end