Fix format in custom_protocol.md

This commit is contained in:
38elements 2016-12-29 13:25:04 +09:00 committed by GitHub
parent 83e9d08853
commit 6bb4dae5e0

View File

@ -1,29 +1,29 @@
# Custom Protocol # Custom Protocol
You can change the behavior of protocol by using custom protocol. You can change the behavior of protocol by using custom protocol.
If you want to use custom protocol, you should put subclass of [protocol class](https://docs.python.org/3/library/asyncio-protocol.html#protocol-classes) in the protocol keyword argument of `sanic.run()`. The constructor of custom protocol class gets following keyword arguments from Sanic. If you want to use custom protocol, you should put subclass of [protocol class](https://docs.python.org/3/library/asyncio-protocol.html#protocol-classes) in the protocol keyword argument of `sanic.run()`. The constructor of custom protocol class gets following keyword arguments from Sanic.
* loop * loop
`loop` is an asyncio compatible event loop. `loop` is an asyncio compatible event loop.
* connections * connections
`connections` is a `set object` to store protocol objects. `connections` is a `set object` to store protocol objects.
When Sanic receives `SIGINT` or `SIGTERM`, Sanic executes `protocol.close_if_idle()` for a `protocol objects` stored in connections. When Sanic receives `SIGINT` or `SIGTERM`, Sanic executes `protocol.close_if_idle()` for a `protocol objects` stored in connections.
* signal * signal
`signal` is a `sanic.server.Signal object` with `stopped attribute`. `signal` is a `sanic.server.Signal object` with `stopped attribute`.
When Sanic receives `SIGINT` or `SIGTERM`, `signal.stopped` becomes `True`. When Sanic receives `SIGINT` or `SIGTERM`, `signal.stopped` becomes `True`.
* request_handler * request_handler
`request_handler` is a coroutine that takes a `sanic.request.Request` object and a `response callback` as arguments. `request_handler` is a coroutine that takes a `sanic.request.Request` object and a `response callback` as arguments.
* error_handler * error_handler
`error_handler` is a `sanic.exceptions.Handler` object. `error_handler` is a `sanic.exceptions.Handler` object.
* request_timeout * request_timeout
`request_timeout` is seconds for timeout. `request_timeout` is seconds for timeout.
* request_max_size * request_max_size
`request_max_size` is bytes of max request size. `request_max_size` is bytes of max request size.
## Example ## Example