Exemple #1
0
from __future__ import division

import sys
import traceback

from pycopia import protocols
from pycopia import socket
from pycopia import asyncio


# Socket protocol handlers

CLOSED = 0
CONNECTED = 1

poller = asyncio.Poll()


class AsyncServerHandler(asyncio.PollerInterface):
    """Generic asynchronous server handler.
    Register an instance of this, with a worker class and a protocol, with the
    poller.
    """

    def __init__(self, sock, workerclass, protocol):
        self._sock = sock
        _host, self.server_port = sock.getsockname()
        self.server_name = socket.getfqdn(_host)
        self._workerclass = workerclass
        self.protocol = protocol
        sock.setblocking(0)
Exemple #2
0
 def __init__(self, poller=None):
     self._expireq = []
     self._poller = poller or asyncio.Poll()
     self._duration_timer = FDTimer(CLOCK_REALTIME)
     self._poller.register_fd(self._duration_timer.fileno(),
                              asyncio.EPOLLIN, self._duration_timeout)
Exemple #3
0
 def __getattr__(self, name):
     global poller
     from pycopia import asyncio
     poller = asyncio.Poll()
     return getattr(poller, name)
Exemple #4
0
 def __init__(self, poller=None):
     self._expireq = []
     self._poller = poller or asyncio.Poll()
     self._duration_timer = FDTimer(CLOCK_MONOTONIC, nonblocking=1)
     self._poller.register_fd(self._duration_timer.fileno(),
                              asyncio.EPOLLIN, self._duration_timeout)