ext/iodine/fio.c
/**
 * `fio_read` attempts to read up to count bytes from the socket into the
 * buffer starting at `buffer`.
 *
 * `fio_read`'s return values are wildly different then the native return
 * values and they aim at making far simpler sense.
 *
 * `fio_read` returns the number of bytes read (0 is a valid return value which
 * simply means that no bytes were read from the buffer).
 *
 * On a fatal connection error that leads to the connection being closed (or if
 * the connection is already closed), `fio_read` returns -1.
 *
 * The value 0 is the valid value indicating no data was read.
 *
 * Data might be available in the kernel's buffer while it is not available to
 * be read using `fio_read` (i.e., when using a transport layer, such as TLS).
 */
`fio_read` attempts to read up to count bytes from the socket into the
buffer starting at `buffer`.

`fio_read`'s return values are wildly different then the native return
values and they aim at making far simpler sense.

`fio_read` returns the number of bytes read (0 is a valid return value which
simply means that no bytes were read from the buffer).

On a fatal connection error that leads to the connection being closed (or if
the connection is already closed), `fio_read` returns -1.

The value 0 is the valid value indicating no data was read.

Data might be available in the kernel's buffer while it is not available to
be read using `fio_read` .
` fio_read ` attempts to read up to count bytes from the socket into the buffer starting at ` buffer ` . ` fio_read ` ' s return values are wildly different then the native return values and they aim at making far simpler sense . ` fio_read ` returns the number of bytes read ( 0 is a valid return value which simply means that no bytes were read from the buffer ) . On a fatal connection error that leads to the connection being closed ( or if the connection is already closed ) ` fio_read ` returns - 1 . The value 0 is the valid value indicating no data was read . Data might be available in the kernel ' s buffer while it is not available to be read using ` fio_read ` .
ssize_t fio_read(intptr_t uuid, void *buffer, size_t count) {
  if (!uuid_is_valid(uuid) || !uuid_data(uuid).open) {
    errno = EBADF;
    return -1;
  }
  if (count == 0)
    return 0;
  fio_lock(&uuid_data(uuid).sock_lock);
  ssize_t (*rw_read)(intptr_t, void *, void *, size_t) =
      uuid_data(uuid).rw_hooks->read;
  void *udata = uuid_data(uuid).rw_udata;
  fio_unlock(&uuid_data(uuid).sock_lock);
  int old_errno = errno;
  ssize_t ret;
retry_int:
  ret = rw_read(uuid, udata, buffer, count);
  if (ret > 0) {
    fio_touch(uuid);
    return ret;
  }
  if (ret < 0 && errno == EINTR)
    goto retry_int;
  if (ret < 0 &&
      (errno == EWOULDBLOCK || errno == EAGAIN || errno == ENOTCONN)) {
    errno = old_errno;
    return 0;
  }
  fio_force_close(uuid);
  return -1;
}
ssize_t fio_read ( intptr_t uuid , void * buffer , size_t count ) { if ( ! uuid_is_valid ( uuid ) || ! uuid_data ( uuid ) . open ) { errno = EBADF ; return -1 ; } if ( count == 0 ) return 0 ; fio_lock ( & uuid_data ( uuid ) . sock_lock ) ; ssize_t ( * rw_read ) ( intptr_t , void * , void * , size_t ) = uuid_data ( uuid ) . rw_hooks -> read ; void * udata = uuid_data ( uuid ) . rw_udata ; fio_unlock ( & uuid_data ( uuid ) . sock_lock ) ; int old_errno = errno ; ssize_t ret ; retry_int : ret = rw_read ( uuid , udata , buffer , count ) ; if ( ret > 0 ) { fio_touch ( uuid ) ; return ret ; } if ( ret < 0 && errno == EINTR ) goto retry_int ; if ( ret < 0 && ( errno == EWOULDBLOCK || errno == EAGAIN || errno == ENOTCONN ) ) { errno = old_errno ; return 0 ; } fio_force_close ( uuid ) ; return -1 ; }
`fio_read` attempts to read up to count bytes from the socket into the
 buffer starting at `buffer`.
` fio_read ` attempts to read up to count bytes from the socket into the buffer starting at ` buffer ` .