# Path: SigObject.py
# class SigObject(QObject):
#     def __init__(self):
# 
# Path: log.py
# class __NullLogger:
#     def debug(self, msg=""):    pass
#     def warning(self, msg=""):  pass
#     def info(self, msg=""):     pass
#     def error(self, msg=""):    pass
#     def fatal(self, msg=""):    pass


from TcpClient import TcpClient
from SigObject import sigObject
from log import logger
import signals
import socket
import socktypes
import threading
#-*- coding: utf-8 -*-

class TcpServer(threading.Thread):
    
    RCVBUF_SIZE = 262144
    SNDBUF_SIZE = 262144
    BACKLOG     = 10
    
    def __init__(self, port, ip="0.0.0.0"):
        threading.Thread.__init__(self)
        self.ip, self.port = ip, port
        
        self.tcpClients = {}
        self.stopflag = False
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.RCVBUF_SIZE)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, self.SNDBUF_SIZE)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.TCP_NODELAY, 1)
        #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR , 1) # do not turn on SO_REUSEADDR
        self.sock.settimeout(0.1)
        
        self._id = id(self.sock)

    def getId(self):

# Path: SigObject.py
# class SigObject(QObject):
#     def __init__(self):
# 
# Path: log.py
# class __NullLogger:
#     def debug(self, msg=""):    pass
#     def warning(self, msg=""):  pass
#     def info(self, msg=""):     pass
#     def error(self, msg=""):    pass
#     def fatal(self, msg=""):    pass


# Path: net/TcpServer.py
from TcpClient import TcpClient
from SigObject import sigObject
from log import logger
import signals
import socket
import socktypes
import threading

#-*- coding: utf-8 -*-

class TcpServer(threading.Thread):
    
    RCVBUF_SIZE = 262144
    SNDBUF_SIZE = 262144
    BACKLOG     = 10
    
    def __init__(self, port, ip="0.0.0.0"):
        threading.Thread.__init__(self)
        self.ip, self.port = ip, port
        
        self.tcpClients = {}
        self.stopflag = False
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, self.RCVBUF_SIZE)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, self.SNDBUF_SIZE)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.TCP_NODELAY, 1)
        #self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR , 1) # do not turn on SO_REUSEADDR
        self.sock.settimeout(0.1)
        
        self._id = id(self.sock)

    def getId(self):

        logger.debug("id: %d" % self._id)