event_io_read — Initiate or continue a read operation for a fixed length
int **event_io_read** ( | e, | |
| | buf, | |
| | buflen, | |
| | state
); | |
Initiate or continue a read operation for a fixed length. If you need a record based reader, consider using the tryread APIs.
Initiates a read that will populate
buflen with the data requested. This function will not return success until it has completely obtained the length requested. It may return
EVENT_IO_ERROR if an error is encountered before that time.
This function is intended to be used with comparatively small buffers. If you anticipate moving large chunks of data (where large means larger than the
growbuf size) over a transport, you should consider using the growbuf code instead.
If the read cannot be satisfied immediately, this function stores state information into the state parameter and returns
EVENT_IO_PENDING. state->needmask will be set to the mask required for scheduling purposes. The caller should call event_io_read when the scheduler indicates that the underlying event is signalled with state->needmask.
If the read failed, this function returns
If the read completes, returns
EVENT_IO_DONE is returned, the caller provided buf and buflen will be populated with the requested data. If multiple event_io_read calls were required to completely satisfy the request, the buf and buflen passed to the most recent call are used; this function does not cache the caller provided buffer address, on the assumption that it might be a stack variable, and as such, will unwind between event_io_read calls.
state must not be
NULL, and must either be zero'ed out or be a value state structure previously used by other event_io_XXX routines.
It is advantageous to reuse state structures, as they try to avoid allocating memory if they already have an appropriately sized buffer.
When a state structure is no longer required, you should free resources by calling event_io_state_clean.
EVENT_IO_EOF when no more data can be read from the file descriptor. This constant is available starting from Momentum 3.0.11.
The buffer for storage.
The length of
This parameter must not be NULL, and must either be zero'ed out or be a value state structure previously used by other event_io_XXX routines. For a description of this data structure see “event_io_state”.
For the return values see the description above.
Only call this function from the