Skip to content

How to use jansson with non-blocking I/O? #647

@milasudril

Description

@milasudril

From the documentation:

json_t *json_loadfd(int input, size_t flags, json_error_t *error)

It is important to note that this function can only succeed on stream file descriptors (such as SOCK_STREAM). Using this function on a non-stream file descriptor will result in undefined behavior. For non-stream file descriptors, see instead json_loadb(). In addition, please note that this function cannot be used on non-blocking file descriptors (such as a non-blocking socket). Using this function on non-blocking file descriptors has a high risk of data loss because it does not support resuming.

So this one is no-go.

json_load_callback_t

On success, the function should write at most buflen bytes to buffer, and return the number of bytes written; a returned value of 0 indicates that no data was produced and that the end of file has been reached. On error, the function should return (size_t)-1 to abort the decoding process.

But I want to keep the context, so this cannot work either.

I guess it is not possible to do this, or is it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions