# 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: 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/socktypes.py
# TCP_SERVER_BASE_TYPE = 0x00
# TCP_CLIENT_BASE_TYPE = 0x10
# UDP_SERVER_BASE_TYPE = 0x20
# UDP_CLIENT_BASE_TYPE = 0x30
# TCP_SERVER        = TCP_SERVER_BASE_TYPE | 0x01
# TCP_CLIENT_REMOTE = TCP_SERVER_BASE_TYPE | 0x02
# TCP_CLIENT_LOCAL  = TCP_CLIENT_BASE_TYPE | 0x10
# UDP_SERVER        = UDP_SERVER_BASE_TYPE | 0x00 # it's just like a sever
# UDP_CLIENT_REMOTE = UDP_SERVER_BASE_TYPE | 0x01
# UDP_CLIENT_LOCAL  = UDP_CLIENT_BASE_TYPE | 0x01


import socket
import threading
import select
import signals
from log import logger
from SigObject import sigObject
from log import logger
from net import socktypes
      
        n = self.sock.sendto(data, self.remoteAddr)
        total = len(data)
        if n < total:
            logger.warning("not all data sent")
        return n == total
    
    def stop(self):
        self.stopflag = True
    
    def send(self, data):
        self.sock.sendto()
    
    def close(self):
        logger.debug("udp server closed")
        self.sock.close()
        
    def run(self):
        while not self.stopflag:
            rfds, _, efds = select.select([self.sock], [], [self.sock], 0.1)
            if len(efds) > 0:
                logger.error("remote client error")
                break
                
            if len(rfds) < 1:
                continue
            
            try:
                data, self.remoteAddr = self.sock.recvfrom(UdpServer.RECV_SIZE)
                logger.debug("recv data -> %s from -> %s:%d" % (data, self.remoteAddr[0], self.remoteAddr[1]))

# 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: 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/socktypes.py
# TCP_SERVER_BASE_TYPE = 0x00
# TCP_CLIENT_BASE_TYPE = 0x10
# UDP_SERVER_BASE_TYPE = 0x20
# UDP_CLIENT_BASE_TYPE = 0x30
# TCP_SERVER        = TCP_SERVER_BASE_TYPE | 0x01
# TCP_CLIENT_REMOTE = TCP_SERVER_BASE_TYPE | 0x02
# TCP_CLIENT_LOCAL  = TCP_CLIENT_BASE_TYPE | 0x10
# UDP_SERVER        = UDP_SERVER_BASE_TYPE | 0x00 # it's just like a sever
# UDP_CLIENT_REMOTE = UDP_SERVER_BASE_TYPE | 0x01
# UDP_CLIENT_LOCAL  = UDP_CLIENT_BASE_TYPE | 0x01


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

      
        n = self.sock.sendto(data, self.remoteAddr)
        total = len(data)
        if n < total:
            logger.warning("not all data sent")
        return n == total
    
    def stop(self):
        self.stopflag = True
    
    def send(self, data):
        self.sock.sendto()
    
    def close(self):
        logger.debug("udp server closed")
        self.sock.close()
        
    def run(self):
        while not self.stopflag:
            rfds, _, efds = select.select([self.sock], [], [self.sock], 0.1)
            if len(efds) > 0:
                logger.error("remote client error")
                break
                
            if len(rfds) < 1:
                continue
            
            try:
                data, self.remoteAddr = self.sock.recvfrom(UdpServer.RECV_SIZE)
                logger.debug("recv data -> %s from -> %s:%d" % (data, self.remoteAddr[0], self.remoteAddr[1]))

                sigObject.emit(signals.SIG_DATA_RECVED, self._id, data)