本文整理匯總了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]