本文整理汇总了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()
示例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()
示例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()
示例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()
示例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))
示例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]