stream: Clarify that some methods must not be called from callbacks

This commit is contained in:
Tobias Brunner
2026-02-20 12:44:55 +01:00
parent 14cbe0bf24
commit 589c74009b
+10 -3
View File
@@ -37,13 +37,14 @@ typedef stream_t*(*stream_constructor_t)(char *uri);
/** /**
* Callback function prototype, called when stream is ready. * Callback function prototype, called when stream is ready.
* *
* It is not allowed to destroy the stream nor to call on_read()/on_write/()
* during the callback.
*
* As select() may return even if a read()/write() would actually block, it is * As select() may return even if a read()/write() would actually block, it is
* recommended to use the non-blocking calls and handle return values * recommended to use the non-blocking calls and handle return values
* appropriately. * appropriately.
* *
* @warning It is not allowed to destroy the passed stream nor to call
* stream_t::on_read()/on_write() during the callback. Such calls
* must be handled asynchronously (e.g. from a separate job).
*
* @param data data passed during callback registration * @param data data passed during callback registration
* @param stream associated stream * @param stream associated stream
* @return FALSE unregisters the invoked callback, TRUE keeps it * @return FALSE unregisters the invoked callback, TRUE keeps it
@@ -84,6 +85,8 @@ struct stream_t {
/** /**
* Register a callback to invoke when stream has data to read. * Register a callback to invoke when stream has data to read.
* *
* @warning Must not be called from callbacks (see \ref stream_cb_t).
*
* @param cb callback function, NULL to unregister * @param cb callback function, NULL to unregister
* @param data data to pass to callback * @param data data to pass to callback
*/ */
@@ -117,6 +120,8 @@ struct stream_t {
/** /**
* Register a callback to invoke when a write would not block. * Register a callback to invoke when a write would not block.
* *
* @warning Must not be called from callbacks (see \ref stream_cb_t).
*
* @param cb callback function, NULL to unregister * @param cb callback function, NULL to unregister
* @param data data to pass to callback * @param data data to pass to callback
*/ */
@@ -131,6 +136,8 @@ struct stream_t {
/** /**
* Destroy a stream_t. * Destroy a stream_t.
*
* @warning Must not be called from callbacks (see \ref stream_cb_t).
*/ */
void (*destroy)(stream_t *this); void (*destroy)(stream_t *this);
}; };