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


Python netutil.bind_unix_socket方法代码示例

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


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

示例1: test_unix_socket

# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import bind_unix_socket [as 别名]
def test_unix_socket(self):
        sockfile = os.path.join(self.tmpdir, "test.sock")
        sock = netutil.bind_unix_socket(sockfile)
        app = Application([("/hello", HelloWorldRequestHandler)])
        server = HTTPServer(app, io_loop=self.io_loop)
        server.add_socket(sock)
        stream = IOStream(socket.socket(socket.AF_UNIX), io_loop=self.io_loop)
        stream.connect(sockfile, self.stop)
        self.wait()
        stream.write(b"GET /hello HTTP/1.0\r\n\r\n")
        stream.read_until(b"\r\n", self.stop)
        response = self.wait()
        self.assertEqual(response, b"HTTP/1.0 200 OK\r\n")
        stream.read_until(b"\r\n\r\n", self.stop)
        headers = HTTPHeaders.parse(self.wait().decode('latin1'))
        stream.read_bytes(int(headers["Content-Length"]), self.stop)
        body = self.wait()
        self.assertEqual(body, b"Hello world")
        stream.close()
        server.stop() 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:22,代码来源:httpserver_test.py

示例2: test_unix_socket

# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import bind_unix_socket [as 别名]
def test_unix_socket(self):
        sockfile = os.path.join(self.tmpdir, "test.sock")
        sock = netutil.bind_unix_socket(sockfile)
        app = Application([("/hello", HelloWorldRequestHandler)])
        server = HTTPServer(app, io_loop=self.io_loop)
        server.add_socket(sock)
        stream = IOStream(socket.socket(socket.AF_UNIX), io_loop=self.io_loop)
        stream.connect(sockfile, self.stop)
        self.wait()
        stream.write(b("GET /hello HTTP/1.0\r\n\r\n"))
        stream.read_until(b("\r\n"), self.stop)
        response = self.wait()
        self.assertEqual(response, b("HTTP/1.0 200 OK\r\n"))
        stream.read_until(b("\r\n\r\n"), self.stop)
        headers = HTTPHeaders.parse(self.wait().decode('latin1'))
        stream.read_bytes(int(headers["Content-Length"]), self.stop)
        body = self.wait()
        self.assertEqual(body, b("Hello world"))
        stream.close()
        server.stop() 
开发者ID:omererdem,项目名称:honeything,代码行数:22,代码来源:httpserver_test.py

示例3: cmd_web

# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import bind_unix_socket [as 别名]
def cmd_web(unix_socket, debug):
    app = make_app(debug=debug)
    server = HTTPServer(app)
    if os.path.exists(unix_socket):
        try:
            r = requests.get('http+unix://{0}'.format(unix_socket.replace('/', '%2F')))
            if r.text.strip() == 'atx.taskqueue':
                print 'Already listening'
                return
        except:
            print 'Unlink unix socket'
            os.unlink(unix_socket)

    socket = bind_unix_socket(unix_socket)
    server.add_socket(socket)
    IOLoop.current().start() 
开发者ID:NetEaseGame,项目名称:ATX,代码行数:18,代码来源:__main__.py

示例4: setUp

# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import bind_unix_socket [as 别名]
def setUp(self):
        super(UnixSocketTest, self).setUp()
        self.tmpdir = tempfile.mkdtemp()
        self.sockfile = os.path.join(self.tmpdir, "test.sock")
        sock = netutil.bind_unix_socket(self.sockfile)
        app = Application([("/hello", HelloWorldRequestHandler)])
        self.server = HTTPServer(app, io_loop=self.io_loop)
        self.server.add_socket(sock)
        self.stream = IOStream(socket.socket(socket.AF_UNIX), io_loop=self.io_loop)
        self.stream.connect(self.sockfile, self.stop)
        self.wait() 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:httpserver_test.py

示例5: setUp

# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import bind_unix_socket [as 别名]
def setUp(self):
        super(UnixSocketTest, self).setUp()
        self.tmpdir = tempfile.mkdtemp()
        self.sockfile = os.path.join(self.tmpdir, "test.sock")
        sock = netutil.bind_unix_socket(self.sockfile)
        app = Application([("/hello", HelloWorldRequestHandler)])
        self.server = HTTPServer(app)
        self.server.add_socket(sock)
        self.stream = IOStream(socket.socket(socket.AF_UNIX))
        self.io_loop.run_sync(lambda: self.stream.connect(self.sockfile)) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:12,代码来源:httpserver_test.py

示例6: build_listener

# 需要导入模块: from tornado import netutil [as 别名]
# 或者: from tornado.netutil import bind_unix_socket [as 别名]
def build_listener(address, backlog=0):
    """address: tuple ('0.0.0.0', 1234) or unix domain socket path such as '/tmp/tmp.sock'"""

    address_type = get_address_type(address)

    if address_type == 'tcp':
        host, port = address
        socks = netutil.bind_sockets(port, address=host, backlog=backlog)
        return socks

    if address_type == 'uds':
        sock = netutil.bind_unix_socket(address, mode=0o600, backlog=backlog)
        return [sock] 
开发者ID:yoki123,项目名称:torpc,代码行数:15,代码来源:util.py


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