|
284 | 284 | Sets an IPROTO request handler with the provided context for the given request type.
|
285 | 285 | The function yields.
|
286 | 286 |
|
287 |
| - Possible values: |
| 287 | + :param uint32_t request_type: request type code from the ``iproto_type`` enumeration |
| 288 | + :param iproto_handler_t handler: IPROTO request handler. To reset the request handler, set the ``handler`` parameter to ``NULL``. |
288 | 289 |
|
289 |
| - * a type code from the :ref:`box.iproto.type <reference_lua-box_iproto_type>` (except |
290 |
| - ``box.iproto.type.UNKNOWN``) -- override the existing request type. |
| 290 | + See the full parameter description in the :ref:`Handler function <box_box_iproto_override-handler>` section. |
291 | 291 |
|
292 |
| - * ``box.iproto.type.UNKNOWN`` -- override an unknown request type. |
| 292 | + :param iproto_handler_destroy_t destroy: IPROTO request handler destructor. The destructor is called when the |
| 293 | + corresponding handler is removed. See the full parameter description |
| 294 | + in the :ref:`Handler destructor function <box_box_iproto_override-destroy>` section. |
293 | 295 |
|
294 |
| - :param uint32_t request_type: request type code from the ``iproto_type`` enumeration |
295 |
| - :param iproto_handler_t handler: IPROTO request handler. To reset the request handler, set the ``handler`` parameter to ``NULL``. |
296 |
| - :param iproto_handler_destroy_t destroy: IPROTO request handler destructor |
297 | 296 | :param void* ctx: a context passed to the ``handler`` and ``destroy`` callbacks
|
298 | 297 |
|
299 | 298 | :return: 0 on success
|
|
307 | 306 | * :errcode:`ER_PROC_LUA` -- the exception is thrown, diagnostic is not set.
|
308 | 307 | * diagnostics from ``src/box/errcode.h`` -- the exception is thrown, diagnostic is set.
|
309 | 308 |
|
310 |
| - For details, see `src/box/errcode.h <https://github.com/tarantool/tarantool/blob/master/src/box/errcode.h>`__. |
| 309 | + For details, see `src/box/errcode.h <https://github.com/tarantool/tarantool/blob/master/src/box/errcode.h>`__. |
| 310 | +
|
| 311 | +.. _box_box_iproto_override-handler: |
| 312 | +
|
| 313 | + **Handler function** |
| 314 | +
|
| 315 | + The signature of a handler function (the ``handler`` parameter): |
| 316 | +
|
| 317 | + .. code-block:: c |
| 318 | +
|
| 319 | + enum iproto_handler_status { |
| 320 | + IPROTO_HANDLER_OK, |
| 321 | + IPROTO_HANDLER_ERROR, |
| 322 | + IPROTO_HANDLER_FALLBACK, |
| 323 | + } |
| 324 | +
|
| 325 | + typedef enum iproto_handler_status |
| 326 | + (*iproto_handler_t)(const char *header, const char *header_end, |
| 327 | + const char *body, const char *body_end, void *ctx); |
| 328 | +
|
| 329 | + where: |
| 330 | +
|
| 331 | + * ``header``(const char*) -- a MsgPack-encoded header |
| 332 | + * ``header_end``(const char*) -- end of a header encoded as MsgPack |
| 333 | + * ``body``(const char*) -- a MsgPack-encoded body |
| 334 | + * ``header_end``(const char*) -- end of a body encoded as MsgPack |
| 335 | +
|
| 336 | + The handler returns a status code. Possible statuses: |
| 337 | +
|
| 338 | + * ``IPROTO_REQUEST_HANDLER_OK`` -- success |
| 339 | + * ``IPROTO_REQUEST_HANDLER_ERROR`` -- error, diagnostic must be set by handler |
| 340 | + * ``IPROTO_REQUEST_HANDLER_FALLBACK`` -- fallback to the system handler |
| 341 | +
|
| 342 | +.. _box_box_iproto_override-destroy: |
| 343 | +
|
| 344 | + **Handler destructor function** |
| 345 | +
|
| 346 | + The signature of a destructor function (the ``destroy`` parameter): |
| 347 | +
|
| 348 | + .. code-block:: c |
| 349 | +
|
| 350 | + typedef void (*iproto_handler_destroy_t)(void *ctx); |
| 351 | +
|
| 352 | + where: |
| 353 | +
|
| 354 | + * ``ctx`` (void*): the context provided by ``box_iproto_override()`` function. |
0 commit comments