当前位置: 首页>>代码示例>>Python>>正文


Python asyncore.socket_map方法代码示例

本文整理汇总了Python中asyncore.socket_map方法的典型用法代码示例。如果您正苦于以下问题:Python asyncore.socket_map方法的具体用法?Python asyncore.socket_map怎么用?Python asyncore.socket_map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在asyncore的用法示例。


在下文中一共展示了asyncore.socket_map方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def __init__(self, localaddr, remoteaddr):
        self._localaddr = localaddr
        self._remoteaddr = remoteaddr
        asyncore.dispatcher.__init__(self)
        try:
            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
            # try to re-use a server port if possible
            self.set_reuse_addr()
            self.bind(localaddr)
            self.listen(5)
        except:
            # cleanup asyncore.socket_map before raising
            self.close()
            raise
        else:
            print >> DEBUGSTREAM, \
                  '%s started at %s\n\tLocal addr: %s\n\tRemote addr:%s' % (
                self.__class__.__name__, time.ctime(time.time()),
                localaddr, remoteaddr) 
开发者ID:glmcdona,项目名称:meddle,代码行数:21,代码来源:smtpd.py

示例2: closeall_check

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def closeall_check(self, usedefault):
        # Check that close_all() closes everything in a given map

        l = []
        testmap = {}
        for i in range(10):
            c = dummychannel()
            l.append(c)
            self.assertEqual(c.socket.closed, False)
            testmap[i] = c

        if usedefault:
            socketmap = asyncore.socket_map
            try:
                asyncore.socket_map = testmap
                asyncore.close_all()
            finally:
                testmap, asyncore.socket_map = asyncore.socket_map, socketmap
        else:
            asyncore.close_all(testmap)

        self.assertEqual(len(testmap), 0)

        for c in l:
            self.assertEqual(c.socket.closed, True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_asyncore.py

示例3: rtl_tcp_asyncore_reset

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def rtl_tcp_asyncore_reset(timeout):
	global rtl_tcp_core
	global rtl_tcp_resetting
	if rtl_tcp_resetting: return
	#print "rtl_tcp_asyncore_reset"
	rtl_tcp_resetting=True
	time.sleep(timeout)
	try:
		rtl_tcp_core.close()
	except:
		pass
	try:
		del rtl_tcp_core
	except:
		pass
	rtl_tcp_core=rtl_tcp_asyncore()
	#print asyncore.socket_map
	rtl_tcp_resetting=False 
开发者ID:ha7ilm,项目名称:rtl_mus,代码行数:20,代码来源:rtl_mus.py

示例4: __init__

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def __init__(self, localaddr, map, debug=False, esmtp=True):
        self._localaddr = localaddr
        self._remoteaddr = None
        self.__smtpchannel = _SMTPChannel if esmtp else smtpd.SMTPChannel
        self.__debug = debug
        self.__messages = []
        asyncore.dispatcher.__init__(self, map=map)
        try:
            self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
            # try to re-use a server port if possible
            self.set_reuse_addr()
            self.bind(localaddr)
            self.listen(5)
        except:
            # cleanup asyncore.socket_map before raising
            self.close()
            raise 
开发者ID:exasol,项目名称:script-languages,代码行数:19,代码来源:__init__.py

示例5: _make_epasv

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def _make_epasv(self, extmode=False):
        """Initialize a passive data channel with remote client which
        issued a PASV or EPSV command.
        If extmode argument is True we assume that client issued EPSV in
        which case extended passive mode will be used (see RFC-2428).
        """
        # close establishing DTP instances, if any
        self._shutdown_connecting_dtp()

        # close established data connections, if any
        if self.data_channel is not None:
            self.data_channel.close()
            self.data_channel = None

        # make sure we are not hitting the max connections limit
        if self.server.max_cons:
            if len(asyncore.socket_map) >= self.server.max_cons:
                msg = "Too many connections. Can't open data channel."
                self.respond("425 %s" %msg)
                self.log(msg)
                return

        # open data channel
        self._dtp_acceptor = self.passive_dtp(self, extmode) 
开发者ID:exasol,项目名称:script-languages,代码行数:26,代码来源:ftpserver.py

示例6: loop

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def loop(timeout=0.001, use_poll=False, map=None, count=None):
    """Start asyncore and scheduler loop.
    Use this as replacement of the original asyncore.loop() function.
    """
    if use_poll and hasattr(asyncore.select, 'poll'):
        poll_fun = asyncore.poll2
    else:
        poll_fun = asyncore.poll
    if map is None:
        map = asyncore.socket_map
    if count is None:
        while (map or _tasks):
            poll_fun(timeout, map)
            _scheduler()
    else:
        while (map or _tasks) and count > 0:
            poll_fun(timeout, map)
            _scheduler()
            count -= 1 
开发者ID:ActiveState,项目名称:code,代码行数:21,代码来源:recipe-577808.py

示例7: run

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def run(self):
        self.active = True
        self.__flag.set()
        while self.active and asyncore.socket_map:
            self.active_lock.acquire()
            asyncore.loop(timeout=0.1, count=1)
            self.active_lock.release()
        asyncore.close_all(ignore_all=True) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_ftplib.py

示例8: debugging_server

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def debugging_server(serv, serv_evt, client_evt):
    serv_evt.set()

    try:
        if hasattr(select, 'poll'):
            poll_fun = asyncore.poll2
        else:
            poll_fun = asyncore.poll

        n = 1000
        while asyncore.socket_map and n > 0:
            poll_fun(0.01, asyncore.socket_map)

            # when the client conversation is finished, it will
            # set client_evt, and it's then ok to kill the server
            if client_evt.is_set():
                serv.close()
                break

            n -= 1

    except socket.timeout:
        pass
    finally:
        if not client_evt.is_set():
            # allow some time for the client to read the result
            time.sleep(0.5)
            serv.close()
        asyncore.close_all()
        serv_evt.set() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:32,代码来源:test_smtplib.py

示例9: loop_waiting_for_flag

# 需要导入模块: import asyncore [as 别名]
# 或者: from asyncore import socket_map [as 别名]
def loop_waiting_for_flag(self, instance, timeout=5):
        timeout = float(timeout) / 100
        count = 100
        while asyncore.socket_map and count > 0:
            asyncore.loop(timeout=0.01, count=1, use_poll=self.use_poll)
            if instance.flag:
                return
            count -= 1
            time.sleep(timeout)
        self.fail("flag not set") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_asyncore.py


注:本文中的asyncore.socket_map方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。