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 {
14           my ($server, $handle) = @_;
15           ...
16         });
17         $server->listen(port => 3000);
18
19         # Start and stop accepting connections
20         $server->start;
21         $server->stop;
22
23         # Start reactor if necessary
24         $server->reactor->start unless $server->reactor->is_running;
25

DESCRIPTION

27       Mojo::IOLoop::Server accepts TCP/IP and UNIX domain socket connections
28       for Mojo::IOLoop.
29

EVENTS

31       Mojo::IOLoop::Server inherits all events from Mojo::EventEmitter and
32       can emit the following new ones.
33
34   accept
35         $server->on(accept => sub {
36           my ($server, $handle) = @_;
37           ...
38         });
39
40       Emitted for each accepted connection.
41

ATTRIBUTES

43       Mojo::IOLoop::Server implements the following attributes.
44
45   reactor
46         my $reactor = $server->reactor;
47         $server     = $server->reactor(Mojo::Reactor::Poll->new);
48
49       Low-level event reactor, defaults to the "reactor" attribute value of
50       the global Mojo::IOLoop singleton. Note that this attribute is
51       weakened.
52

METHODS

54       Mojo::IOLoop::Server inherits all methods from Mojo::EventEmitter and
55       implements the following new ones.
56
57   generate_port
58         my $port = Mojo::IOLoop::Server->generate_port;
59
60       Find a free TCP port, primarily used for tests.
61
62   handle
63         my $handle = $server->handle;
64
65       Get handle for server, usually an IO::Socket::IP object.
66
67   is_accepting
68         my $bool = $server->is_accepting;
69
70       Check if connections are currently being accepted.
71
72   listen
73         $server->listen(port => 3000);
74         $server->listen({port => 3000});
75
76       Create a new listen socket. Note that TLS support depends on
77       IO::Socket::SSL (2.009+).
78
79       These options are currently available:
80
81       address
82           address => '127.0.0.1'
83
84         Local address to listen on, defaults to 0.0.0.0.
85
86       backlog
87           backlog => 128
88
89         Maximum backlog size, defaults to "SOMAXCONN".
90
91       fd
92           fd => 3
93
94         File descriptor with an already prepared listen socket.
95
96       path
97           path => '/tmp/myapp.sock'
98
99         Path for UNIX domain socket to listen on.
100
101       port
102           port => 80
103
104         Port to listen on, defaults to a random port.
105
106       reuse
107           reuse => 1
108
109         Allow multiple servers to use the same port with the "SO_REUSEPORT"
110         socket option.
111
112       single_accept
113           single_accept => 1
114
115         Only accept one connection at a time.
116
117       tls
118           tls => 1
119
120         Enable TLS.
121
122       tls_ca
123           tls_ca => '/etc/tls/ca.crt'
124
125         Path to TLS certificate authority file.
126
127       tls_cert
128           tls_cert => '/etc/tls/server.crt'
129           tls_cert => {'mojolicious.org' => '/etc/tls/mojo.crt'}
130
131         Path to the TLS cert file, defaults to a built-in test certificate.
132
133       tls_ciphers
134           tls_ciphers => 'AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH'
135
136         TLS cipher specification string. For more information about the
137         format see
138         <https://www.openssl.org/docs/manmaster/apps/ciphers.html#CIPHER-STRINGS>.
139
140       tls_key
141           tls_key => '/etc/tls/server.key'
142           tls_key => {'mojolicious.org' => '/etc/tls/mojo.key'}
143
144         Path to the TLS key file, defaults to a built-in test key.
145
146       tls_protocols
147           tls_protocols => ['foo', 'bar']
148
149         ALPN protocols to negotiate.
150
151       tls_verify
152           tls_verify => 0x00
153
154         TLS verification mode.
155
156       tls_version
157           tls_version => 'TLSv1_2'
158
159         TLS protocol version.
160
161   port
162         my $port = $server->port;
163
164       Get port this server is listening on.
165
166   start
167         $server->start;
168
169       Start or resume accepting connections.
170
171   stop
172         $server->stop;
173
174       Stop accepting connections.
175

SEE ALSO

177       Mojolicious, Mojolicious::Guides, <https://mojolicious.org>.
178
179
180
181perl v5.32.0                      2020-07-28           Mojo::IOLoop::Server(3)
Impressum