.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 "2019-02-05" "perl v5.28.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 { \& my ($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 \s-1TCP/IP\s0 and \s-1UNIX\s0 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 4 \& $server\->on(accept => sub { \& my ($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 \s-1TCP\s0 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 \s-1TLS\s0 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 \s-1UNIX\s0 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 \s-1TLS.\s0 .IP "tls_ca" 2 .IX Item "tls_ca" .Vb 1 \& tls_ca => \*(Aq/etc/tls/ca.crt\*(Aq .Ve .Sp Path to \s-1TLS\s0 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 \s-1TLS\s0 cert file, defaults to a built-in test certificate. .IP "tls_ciphers" 2 .IX Item "tls_ciphers" .Vb 1 \& tls_ciphers => \*(AqAES128\-GCM\-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH\*(Aq .Ve .Sp \&\s-1TLS\s0 cipher specification string. For more information about the format see . .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 \s-1TLS\s0 key file, defaults to a built-in test key. .IP "tls_protocols" 2 .IX Item "tls_protocols" .Vb 1 \& tls_protocols => [\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq] .Ve .Sp \&\s-1ALPN\s0 protocols to negotiate. .IP "tls_verify" 2 .IX Item "tls_verify" .Vb 1 \& tls_verify => 0x00 .Ve .Sp \&\s-1TLS\s0 verification mode. .IP "tls_version" 2 .IX Item "tls_version" .Vb 1 \& tls_version => \*(AqTLSv1_2\*(Aq .Ve .Sp \&\s-1TLS\s0 protocol version. .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, .