# Path: sippy/Core/Exceptions.py
# def dump_exception(msg, f = sys.stdout, extra = None):
#     exc_type, exc_value, exc_traceback = sys.exc_info()
#     if isinstance(exc_value, StdException):
#         cus_traceback = exc_value.traceback
#     else:
#         if hasattr(exc_value, 'traceback'):
#             exc_traceback = exc_value.traceback
#         cus_traceback = None
#     f.write('%s @%s[%d] %s:\n' % (datetime.now(), sys.argv[0], os.getpid(), msg))
#     f.write(SEPT)
#     if cus_traceback != None:
#         f.write('Traceback (most recent call last):\n')
#         print_list(cus_traceback, file = f)
#         f.write(format_exception_only(exc_type, exc_value)[0])
#     else:
#         print_exception(exc_type, exc_value, exc_traceback, file = f)
#     f.write(SEPT)
#     if extra != None:
#         f.write(extra)
#         f.write(SEPT)
#     f.flush()


from errno import ECONNRESET, ENOTCONN, ESHUTDOWN, EWOULDBLOCK, ENOBUFS, EAGAIN, \
  EINTR
from datetime import datetime
from time import sleep, time
from threading import Thread, Condition
from random import random
from sippy.Core.EventDispatcher import ED2
from sippy.Core.Exceptions import dump_exception
from sippy.Time.Timeout import Timeout
from sippy.Time.MonoTime import MonoTime
    from sys import exit
import socket

    def __init__(self, userv):
        Thread.__init__(self)
        self.userv = userv
        self.setDaemon(True)
        self.start()

    def run(self):
        maxemptydata = 100
        while True:
            try:
                data, address = self.userv.skt.recvfrom(8192)
                if not data and address == None:
                    # Ugly hack to detect socket being closed under us on Linux.
                    # The problem is that even call on non-closed socket can
                    # sometimes return empty data buffer, making AsyncReceiver
                    # to exit prematurely.
                    maxemptydata -= 1
                    if maxemptydata == 0:
                        break
                    continue
                else:
                    maxemptydata = 100
                rtime = MonoTime()
            except Exception as why:
                if isinstance(why, socket.error) and why[0] in (ECONNRESET, ENOTCONN, ESHUTDOWN):
                    break
                if isinstance(why, socket.error) and why[0] in (EINTR,):
                    continue
                else:

# Path: sippy/Core/Exceptions.py
# def dump_exception(msg, f = sys.stdout, extra = None):
#     exc_type, exc_value, exc_traceback = sys.exc_info()
#     if isinstance(exc_value, StdException):
#         cus_traceback = exc_value.traceback
#     else:
#         if hasattr(exc_value, 'traceback'):
#             exc_traceback = exc_value.traceback
#         cus_traceback = None
#     f.write('%s @%s[%d] %s:\n' % (datetime.now(), sys.argv[0], os.getpid(), msg))
#     f.write(SEPT)
#     if cus_traceback != None:
#         f.write('Traceback (most recent call last):\n')
#         print_list(cus_traceback, file = f)
#         f.write(format_exception_only(exc_type, exc_value)[0])
#     else:
#         print_exception(exc_type, exc_value, exc_traceback, file = f)
#     f.write(SEPT)
#     if extra != None:
#         f.write(extra)
#         f.write(SEPT)
#     f.flush()


# Path: sippy/Udp_server.py
from errno import ECONNRESET, ENOTCONN, ESHUTDOWN, EWOULDBLOCK, ENOBUFS, EAGAIN, \
  EINTR
from datetime import datetime
from time import sleep, time
from threading import Thread, Condition
from random import random
from sippy.Core.EventDispatcher import ED2
from sippy.Core.Exceptions import dump_exception
from sippy.Time.Timeout import Timeout
from sippy.Time.MonoTime import MonoTime
    from sys import exit
import socket


    def __init__(self, userv):
        Thread.__init__(self)
        self.userv = userv
        self.setDaemon(True)
        self.start()

    def run(self):
        maxemptydata = 100
        while True:
            try:
                data, address = self.userv.skt.recvfrom(8192)
                if not data and address == None:
                    # Ugly hack to detect socket being closed under us on Linux.
                    # The problem is that even call on non-closed socket can
                    # sometimes return empty data buffer, making AsyncReceiver
                    # to exit prematurely.
                    maxemptydata -= 1
                    if maxemptydata == 0:
                        break
                    continue
                else:
                    maxemptydata = 100
                rtime = MonoTime()
            except Exception as why:
                if isinstance(why, socket.error) and why[0] in (ECONNRESET, ENOTCONN, ESHUTDOWN):
                    break
                if isinstance(why, socket.error) and why[0] in (EINTR,):
                    continue
                else:

                    dump_exception('Udp_server: unhandled exception when receiving incoming data')