.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mojo::IOLoop::Server 3pm" .TH Mojo::IOLoop::Server 3pm 2026-05-02 "perl v5.40.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Mojo::IOLoop::Server \- Non\-blocking TCP and UNIX domain socket server .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::IOLoop::Server; \& \& # Create listen socket \& my $server = Mojo::IOLoop::Server\->new; \& $server\->on(accept => sub ($server, $handle) {...}); \& $server\->listen(port => 3000); \& \& # Start and stop accepting connections \& $server\->start; \& $server\->stop; \& \& # Start reactor if necessary \& $server\->reactor\->start unless $server\->reactor\->is_running; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" Mojo::IOLoop::Server accepts TCP/IP and UNIX domain socket connections for Mojo::IOLoop. .SH EVENTS .IX Header "EVENTS" Mojo::IOLoop::Server inherits all events from Mojo::EventEmitter and can emit the following new ones. .SS accept .IX Subsection "accept" .Vb 1 \& $server\->on(accept => sub ($server, $handle) {...}); .Ve .PP Emitted for each accepted connection. .SH ATTRIBUTES .IX Header "ATTRIBUTES" Mojo::IOLoop::Server implements the following attributes. .SS reactor .IX Subsection "reactor" .Vb 2 \& my $reactor = $server\->reactor; \& $server = $server\->reactor(Mojo::Reactor::Poll\->new); .Ve .PP Low-level event reactor, defaults to the \f(CW\*(C`reactor\*(C'\fR attribute value of the global Mojo::IOLoop singleton. Note that this attribute is weakened. .SH METHODS .IX Header "METHODS" Mojo::IOLoop::Server inherits all methods from Mojo::EventEmitter and implements the following new ones. .SS generate_port .IX Subsection "generate_port" .Vb 1 \& my $port = Mojo::IOLoop::Server\->generate_port; .Ve .PP Find a free TCP port, primarily used for tests. .SS handle .IX Subsection "handle" .Vb 1 \& my $handle = $server\->handle; .Ve .PP Get handle for server, usually an IO::Socket::IP object. .SS is_accepting .IX Subsection "is_accepting" .Vb 1 \& my $bool = $server\->is_accepting; .Ve .PP Check if connections are currently being accepted. .SS listen .IX Subsection "listen" .Vb 2 \& $server\->listen(port => 3000); \& $server\->listen({port => 3000}); .Ve .PP Create a new listen socket. Note that TLS support depends on IO::Socket::SSL (2.009+). .PP These options are currently available: .IP address 2 .IX Item "address" .Vb 1 \& address => \*(Aq127.0.0.1\*(Aq .Ve .Sp Local address to listen on, defaults to \f(CW0.0.0.0\fR. .IP backlog 2 .IX Item "backlog" .Vb 1 \& backlog => 128 .Ve .Sp Maximum backlog size, defaults to \f(CW\*(C`SOMAXCONN\*(C'\fR. .IP fd 2 .IX Item "fd" .Vb 1 \& fd => 3 .Ve .Sp File descriptor with an already prepared listen socket. .IP path 2 .IX Item "path" .Vb 1 \& path => \*(Aq/tmp/myapp.sock\*(Aq .Ve .Sp Path for UNIX domain socket to listen on. .IP port 2 .IX Item "port" .Vb 1 \& port => 80 .Ve .Sp Port to listen on, defaults to a random port. .IP reuse 2 .IX Item "reuse" .Vb 1 \& reuse => 1 .Ve .Sp Allow multiple servers to use the same port with the \f(CW\*(C`SO_REUSEPORT\*(C'\fR socket option. .IP single_accept 2 .IX Item "single_accept" .Vb 1 \& single_accept => 1 .Ve .Sp Only accept one connection at a time. .IP tls 2 .IX Item "tls" .Vb 1 \& tls => 1 .Ve .Sp Enable TLS. .IP tls_ca 2 .IX Item "tls_ca" .Vb 1 \& tls_ca => \*(Aq/etc/tls/ca.crt\*(Aq .Ve .Sp Path to TLS certificate authority file. .IP tls_cert 2 .IX Item "tls_cert" .Vb 2 \& tls_cert => \*(Aq/etc/tls/server.crt\*(Aq \& tls_cert => {\*(Aqmojolicious.org\*(Aq => \*(Aq/etc/tls/mojo.crt\*(Aq} .Ve .Sp Path to the TLS cert file, defaults to a built-in test certificate. .IP tls_key 2 .IX Item "tls_key" .Vb 2 \& tls_key => \*(Aq/etc/tls/server.key\*(Aq \& tls_key => {\*(Aqmojolicious.org\*(Aq => \*(Aq/etc/tls/mojo.key\*(Aq} .Ve .Sp Path to the TLS key file, defaults to a built-in test key. .IP tls_options 2 .IX Item "tls_options" .Vb 1 \& tls_options => {SSL_alpn_protocols => [\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq], SSL_verify_mode => 0x00} .Ve .Sp Additional options for IO::Socket::SSL. .SS port .IX Subsection "port" .Vb 1 \& my $port = $server\->port; .Ve .PP Get port this server is listening on. .SS start .IX Subsection "start" .Vb 1 \& $server\->start; .Ve .PP Start or resume accepting connections. .SS stop .IX Subsection "stop" .Vb 1 \& $server\->stop; .Ve .PP Stop accepting connections. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .