1Mojo::IOLoop::Server(3)User Contributed Perl DocumentatioMnojo::IOLoop::Server(3)
2
3
4

NAME

6       Mojo::IOLoop::Server - Non-blocking TCP and UNIX domain socket server
7

SYNOPSIS

9         use Mojo::IOLoop::Server;
10
11         # Create listen socket
12         my $server = Mojo::IOLoop::Server->new;
13         $server->on(accept => sub ($server, $handle) {...});
14         $server->listen(port => 3000);
15
16         # Start and stop accepting connections
17         $server->start;
18         $server->stop;
19
20         # Start reactor if necessary
21         $server->reactor->start unless $server->reactor->is_running;
22

DESCRIPTION

24       Mojo::IOLoop::Server accepts TCP/IP and UNIX domain socket connections
25       for Mojo::IOLoop.
26

EVENTS

28       Mojo::IOLoop::Server inherits all events from Mojo::EventEmitter and
29       can emit the following new ones.
30
31   accept
32         $server->on(accept => sub ($server, $handle) {...});
33
34       Emitted for each accepted connection.
35

ATTRIBUTES

37       Mojo::IOLoop::Server implements the following attributes.
38
39   reactor
40         my $reactor = $server->reactor;
41         $server     = $server->reactor(Mojo::Reactor::Poll->new);
42
43       Low-level event reactor, defaults to the "reactor" attribute value of
44       the global Mojo::IOLoop singleton. Note that this attribute is
45       weakened.
46

METHODS

48       Mojo::IOLoop::Server inherits all methods from Mojo::EventEmitter and
49       implements the following new ones.
50
51   generate_port
52         my $port = Mojo::IOLoop::Server->generate_port;
53
54       Find a free TCP port, primarily used for tests.
55
56   handle
57         my $handle = $server->handle;
58
59       Get handle for server, usually an IO::Socket::IP object.
60
61   is_accepting
62         my $bool = $server->is_accepting;
63
64       Check if connections are currently being accepted.
65
66   listen
67         $server->listen(port => 3000);
68         $server->listen({port => 3000});
69
70       Create a new listen socket. Note that TLS support depends on
71       IO::Socket::SSL (2.009+).
72
73       These options are currently available:
74
75       address
76           address => '127.0.0.1'
77
78         Local address to listen on, defaults to 0.0.0.0.
79
80       backlog
81           backlog => 128
82
83         Maximum backlog size, defaults to "SOMAXCONN".
84
85       fd
86           fd => 3
87
88         File descriptor with an already prepared listen socket.
89
90       path
91           path => '/tmp/myapp.sock'
92
93         Path for UNIX domain socket to listen on.
94
95       port
96           port => 80
97
98         Port to listen on, defaults to a random port.
99
100       reuse
101           reuse => 1
102
103         Allow multiple servers to use the same port with the "SO_REUSEPORT"
104         socket option.
105
106       single_accept
107           single_accept => 1
108
109         Only accept one connection at a time.
110
111       tls
112           tls => 1
113
114         Enable TLS.
115
116       tls_ca
117           tls_ca => '/etc/tls/ca.crt'
118
119         Path to TLS certificate authority file.
120
121       tls_cert
122           tls_cert => '/etc/tls/server.crt'
123           tls_cert => {'mojolicious.org' => '/etc/tls/mojo.crt'}
124
125         Path to the TLS cert file, defaults to a built-in test certificate.
126
127       tls_key
128           tls_key => '/etc/tls/server.key'
129           tls_key => {'mojolicious.org' => '/etc/tls/mojo.key'}
130
131         Path to the TLS key file, defaults to a built-in test key.
132
133       tls_options
134           tls_options => {SSL_alpn_protocols => ['foo', 'bar'], SSL_verify_mode => 0x00}
135
136         Additional options for IO::Socket::SSL.
137
138   port
139         my $port = $server->port;
140
141       Get port this server is listening on.
142
143   start
144         $server->start;
145
146       Start or resume accepting connections.
147
148   stop
149         $server->stop;
150
151       Stop accepting connections.
152

SEE ALSO

154       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
155
156
157
158perl v5.38.0                      2023-09-11           Mojo::IOLoop::Server(3)
Impressum