noc.core.ioloop.udpserver

Module Contents

class noc.core.ioloop.udpserver.UDPServer(io_loop=None)

Bases: object

has_reuseport
has_frebind
listen(self, port, address='')

Starts accepting connections on the given port.

This method may be called more than once to listen on multiple ports. listen takes effect immediately; it is not necessary to call UDPServer.start afterwards. It is, however, necessary to start the .IOLoop.

add_sockets(self, sockets)

Makes this server start accepting connections on the given sockets.

The sockets parameter is a list of socket objects such as those returned by ~tornado.netutil.bind_sockets. add_sockets is typically used in combination with that method and tornado.process.fork_processes to provide greater control over the initialization of a multi-process server.

add_socket(self, socket)

Singular version of add_sockets. Takes a single socket object.

bind(self, port, address=None, family=socket.AF_UNSPEC, backlog=128)

Binds this server to the given port on the given address.

To start the server, call start. If you want to run this server in a single process, you can call listen as a shortcut to the sequence of bind and start calls.

Address may be either an IP address or hostname. If it’s a hostname, the server will listen on all IP addresses associated with the name. Address may be an empty string or None to listen on all available interfaces. Family may be set to either socket.AF_INET or socket.AF_INET6 to restrict to IPv4 or IPv6 addresses, otherwise both will be used if available.

The backlog argument has the same meaning as for socket.listen <socket.socket.listen>.

This method may be called multiple times prior to start to listen on multiple ports or interfaces.

start(self, num_processes=1)

Starts this server in the .IOLoop.

By default, we run the server in this process and do not fork any additional child process.

If num_processes is None or <= 0, we detect the number of cores available on this machine and fork that number of child processes. If num_processes is given and > 1, we fork that specific number of sub-processes.

Since we use processes and not threads, there is no shared memory between any server code.

Note that multiple processes are not compatible with the autoreload module (or the autoreload=True option to tornado.web.Application which defaults to True when debug=True). When using multiple processes, no IOLoops can be created or referenced until after the call to TCPServer.start(n).

stop(self)

Stops listening for new connections.

Requests currently in progress may still continue after the server is stopped.

accept_handler(self, fd, events)
on_read(self, data, address)

To be overriden

bind_udp_sockets(self, port, address=None, family=socket.AF_UNSPEC, flags=None)

Creates listening sockets bound to the given port and address.

Returns a list of socket objects (multiple sockets are returned if the given address maps to multiple IP addresses, which is most common for mixed IPv4 and IPv6 use).

Address may be either an IP address or hostname. If it’s a hostname, the server will listen on all IP addresses associated with the name. Address may be an empty string or None to listen on all available interfaces. Family may be set to either socket.AF_INET or socket.AF_INET6 to restrict to IPv4 or IPv6 addresses, otherwise both will be used if available.

The backlog argument has the same meaning as for socket.listen() <socket.socket.listen>.

flags is a bitmask of AI_* flags to ~socket.getaddrinfo, like socket.AI_PASSIVE | socket.AI_NUMERICHOST.

enable_reuseport(self)

Override if SO_REUSEPORT should be set :return:

enable_freebind(self)

Override if IP_FREEBIND should be set :return:

setup_socket(self, sock)

Called after socket created but before .bind(). Can be overriden to adjust socket options in superclasses :param sock: socket instance :return: None

get_ip_freebind(self)

Many python distributions does not include IP_FREEBIND to socket module :return: IP_FREEBIND value or None