akheron / jansson

C library for encoding, decoding and manipulating JSON data
http://www.digip.org/jansson/
Other
3.02k stars 807 forks source link

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

Open milasudril opened 1 year ago

milasudril commented 1 year ago

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?

Zer0-One commented 1 year ago

https://github.com/akheron/jansson/issues/410