Exemple #1
0
IOResult os_sendv_nonb(struct Client *acptr, struct MsgQ* buf, unsigned int* count_in,
		       unsigned int* count_out)
{
  int res;
  int count;
  struct iovec iov[IOV_MAX];

  assert(0 != buf);
  assert(0 != count_in);
  assert(0 != count_out);
  assert(0 != acptr);

  *count_in = 0;
  *count_out = 0;
  errno = 0;

  count = msgq_mapiov(buf, iov, IOV_MAX, count_in);
  msgq_process(acptr, iov, count);

  if (-1 < (res = writev(cli_fd(acptr), iov, count))) {
    *count_out = (unsigned) res;
    return IO_SUCCESS;
  }
  else if (EWOULDBLOCK == errno || EAGAIN == errno ||
	   ENOMEM == errno || ENOBUFS == errno)
    return IO_BLOCKED;

  return IO_FAILURE;
}
/** Attempt a vectored write on a connected socket.
 * @param[in] fd File descriptor to write to.
 * @param[in] buf Message queue to send from.
 * @param[out] count_in Number of bytes mapped from \a buf.
 * @param[out] count_out Receives number of bytes actually written.
 * @return An IOResult value indicating status.
 */
IOResult os_sendv_nonb(int fd, struct MsgQ* buf, unsigned int* count_in,
		       unsigned int* count_out)
{
  int res;
  int count;
  struct iovec iov[IOV_MAX];

  assert(0 != buf);
  assert(0 != count_in);
  assert(0 != count_out);

  *count_in = 0;
  count = msgq_mapiov(buf, iov, IOV_MAX, count_in);

  if (-1 < (res = writev(fd, iov, count))) {
    *count_out = (unsigned) res;
    return IO_SUCCESS;
  } else {
    *count_out = 0;
    return is_blocked(errno) ? IO_BLOCKED : IO_FAILURE;
  }
}