Class: Celluloid::SMTP::Server
- Inherits:
-
Object
- Object
- Celluloid::SMTP::Server
show all
- Extended by:
- Extensions
- Includes:
- IO, Extensions
- Defined in:
- lib/celluloid/smtp.rb,
lib/celluloid/smtp/server.rb,
lib/celluloid/smtp/server/protector.rb
Defined Under Namespace
Classes: Handler, Transporter
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Extensions
included
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/celluloid/smtp/server.rb', line 35
def initialize(options={})
@options = options
@host = options.fetch(:host, DEFAULT_HOST)
@port = options.fetch(:port, DEFAULT_PORT)
@behavior = options.fetch(:behavior, DEFAULT_BEHAVIOR)
@hostname = options.fetch(:hostname, DEFAULT_HOSTNAME)
@backlog = options.fetch(:backlog, DEFAULT_BACKLOG)
@server = Celluloid::IO::TCPServer.new(@host, @port)
@server.listen(options.fetch(:backlog, @backlog))
console("Celluloid::IO SMTP Server #{SMTP::VERSION} @ #{@host}:#{@port}")
@options[:rescue] ||= []
@options[:rescue] += [
Errno::ECONNRESET,
Errno::EPIPE,
Errno::EINPROGRESS,
Errno::ETIMEDOUT,
Errno::EHOSTUNREACH
]
async.run
end
|
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
7
8
9
|
# File 'lib/celluloid/smtp/server.rb', line 7
def logger
@logger
end
|
Class Method Details
.launch(options) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/celluloid/smtp/server.rb', line 8
def launch(options)
unless @logger
Celluloid::SMTP::Logging.supervise as: :logger
@logger = Celluloid[:logger]
end
if SMTP::Constants::HANDLERS > 0
Celluloid::SMTP::Server::Handler.supervise as: :handler, size: SMTP::Constants::HANDLERS
end
supervise(as: :smtpd, args:[options])
Celluloid[:smtpd]
end
|
.protector(io) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/celluloid/smtp/server/protector.rb', line 4
def protector(io)
Thread.new {
Timeout.timeout(TIMEOUT) {
yield(io)
}
}.value
rescue EOFError, IOError
warn "Premature disconnect."
rescue Timeout::Error
warn "Timeout handling connection."
rescue Exception => ex
exception(ex, "Unknown connection error")
ensure
io.close
end
|
.run(options = {}) ⇒ Object
22
23
24
25
|
# File 'lib/celluloid/smtp/server.rb', line 22
def run(options={})
launch(options)
sleep
end
|
.run!(options = {}) ⇒ Object
19
20
21
|
# File 'lib/celluloid/smtp/server.rb', line 19
def run!(options={})
launch(options)
end
|
Instance Method Details
#ceased ⇒ Object
30
31
32
33
|
# File 'lib/celluloid/smtp/server.rb', line 30
def ceased
@server.close rescue nil
warn "SMTP Server offline."
end
|
#shutdown ⇒ Object
59
60
61
62
63
|
# File 'lib/celluloid/smtp/server.rb', line 59
def shutdown
@online = false
sleep 0.126
@server.close if @server rescue nil
end
|