Class: Async::IO::SSLServer

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Server
Defined in:
lib/async/io/ssl_socket.rb

Overview

We reimplement this from scratch because the native implementation doesn’t expose the underlying server/context that we need to implement non-blocking accept.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Server

#accept_each

Constructor Details

#initialize(server, context) ⇒ SSLServer

Returns a new instance of SSLServer.



111
112
113
114
# File 'lib/async/io/ssl_socket.rb', line 111

def initialize(server, context)
	@server = server
	@context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



127
128
129
# File 'lib/async/io/ssl_socket.rb', line 127

def context
  @context
end

#serverObject (readonly)

Returns the value of attribute server.



126
127
128
# File 'lib/async/io/ssl_socket.rb', line 126

def server
  @server
end

Instance Method Details

#accept(task: Task.current, **options) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/async/io/ssl_socket.rb', line 133

def accept(task: Task.current, **options)
	peer, address = @server.accept(**options)
	
	wrapper = SSLSocket.new(peer, @context)
	
	return wrapper, address unless block_given?
	
	task.async do
		task.annotate "accepting secure connection #{address.inspect}"
		
		begin
			# You want to do this in a nested async task or you might suffer from head-of-line blocking.
			wrapper.accept
			
			yield wrapper, address
		ensure
			wrapper.close
		end
	end
end

#dupObject



120
121
122
# File 'lib/async/io/ssl_socket.rb', line 120

def dup
	self.class.new(@server.dup, @context)
end

#filenoObject



116
117
118
# File 'lib/async/io/ssl_socket.rb', line 116

def fileno
	@server.fileno
end

#listen(*args) ⇒ Object



129
130
131
# File 'lib/async/io/ssl_socket.rb', line 129

def listen(*args)
	@server.listen(*args)
end