# Path: ss/utils.py
# PY2 = sys.version_info[0] == 2
# def compat_ord(s):
# def compat_chr(d):
# def to_bytes(s):
# def to_str(s):
# def inet_ntop(family, ipstr):
# def inet_pton(family, addr):
# def is_ip(address):
# def patch_socket():
# def pack_addr(address):
# def errno_from_exception(e):
# def get_sock_error(sock):
# def merge_prefix(deque, size):
# 
# Path: ss/settings.py
# class Settings(object):
#     DEFAULT_TIMEOUT = 300
#     _LOCK = RLock()
#     def __init__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, val):
#     def get(self, name, default=None):
#     def __contains__(self, name):
#     def update(self, config):
#     def dict(self):
#     def __repr__(self):


import os
import time
import socket
import select
import errno
import logging
import threading
                    import traceback
from collections import defaultdict
from ss import utils
from ss.settings import settings
        if mode & IOLoop.WRITE:
            events.append(select.kevent(fd, select.KQ_FILTER_WRITE, flags))
        for e in events:
            self._kqueue.control([e], 0)

    def poll(self, timeout):
        if timeout < 0:
            timeout = None  # kqueue behaviour
        events = self._kqueue.control(None, KqueueLoop.MAX_EVENTS, timeout)
        results = defaultdict(lambda: 0x00)
        for e in events:
            fd = e.ident
            if e.filter == select.KQ_FILTER_READ:
                results[fd] |= IOLoop.READ
            if e.filter == select.KQ_FILTER_WRITE:
                if e.flags & select.KQ_EV_EOF:
                    # If an asynchronous connection is refused, kqueue
                    # returns a write event with the EOF flag set.
                    # Turn this into an error for consistency with the
                    # other IOLoop implementations.
                    # Note that for read events, EOF may be returned before
                    # all data has been consumed from the socket buffer,
                    # so we only check for EOF on write events.
                    results[fd] = IOLoop.ERROR
                else:
                    results[fd] |= IOLoop.WRITE
            if e.flags & select.KQ_EV_ERROR:
                results[fd] |= IOLoop.ERROR
        return results.items()


# Path: ss/utils.py
# PY2 = sys.version_info[0] == 2
# def compat_ord(s):
# def compat_chr(d):
# def to_bytes(s):
# def to_str(s):
# def inet_ntop(family, ipstr):
# def inet_pton(family, addr):
# def is_ip(address):
# def patch_socket():
# def pack_addr(address):
# def errno_from_exception(e):
# def get_sock_error(sock):
# def merge_prefix(deque, size):
# 
# Path: ss/settings.py
# class Settings(object):
#     DEFAULT_TIMEOUT = 300
#     _LOCK = RLock()
#     def __init__(self):
#     def __getitem__(self, name):
#     def __setitem__(self, name, val):
#     def get(self, name, default=None):
#     def __contains__(self, name):
#     def update(self, config):
#     def dict(self):
#     def __repr__(self):


# Path: ss/ioloop.py
import os
import time
import socket
import select
import errno
import logging
import threading
                    import traceback
from collections import defaultdict
from ss import utils
from ss.settings import settings

        if mode & IOLoop.WRITE:
            events.append(select.kevent(fd, select.KQ_FILTER_WRITE, flags))
        for e in events:
            self._kqueue.control([e], 0)

    def poll(self, timeout):
        if timeout < 0:
            timeout = None  # kqueue behaviour
        events = self._kqueue.control(None, KqueueLoop.MAX_EVENTS, timeout)
        results = defaultdict(lambda: 0x00)
        for e in events:
            fd = e.ident
            if e.filter == select.KQ_FILTER_READ:
                results[fd] |= IOLoop.READ
            if e.filter == select.KQ_FILTER_WRITE:
                if e.flags & select.KQ_EV_EOF:
                    # If an asynchronous connection is refused, kqueue
                    # returns a write event with the EOF flag set.
                    # Turn this into an error for consistency with the
                    # other IOLoop implementations.
                    # Note that for read events, EOF may be returned before
                    # all data has been consumed from the socket buffer,
                    # so we only check for EOF on write events.
                    results[fd] = IOLoop.ERROR
                else:
                    results[fd] |= IOLoop.WRITE
            if e.flags & select.KQ_EV_ERROR:
                results[fd] |= IOLoop.ERROR
        return results.items()


    def register(self, fd, mode):