int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src) { return xs_msg_move ((xs_msg_t*) dest->content, (xs_msg_t*) src->content); }
int xs_instream_recv (xs_instream *self, xs_msg *msg) { int rc; ssize_t nbytes; /* If there's a message available, return is straight away. */ if (self->state == 2) { xs_msg_move (msg, &self->msg); self->state = 0; return 0; } /* If message is being asynchronously received at the moment, there's no message to return yet. */ if (self->state == 1) return -EINPROGRESS; /* Try to read the message in a synchronous way. */ nbytes = recv (self->fd, self->sizebuf, 8, MSG_DONTWAIT); /* Sanitation of the result. */ if (unlikely (nbytes == 0)) { errno = ECONNREFUSED; nbytes = -1; } else if (unlikely (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))) nbytes = 0; errno_assert (nbytes >= 0); if (nbytes < 8) { self->recvd = nbytes; /* TODO: xs_instream_launch_async (self); */ return -EINPROGRESS; } rc = xs_msg_init (&self->msg, xs_getll (self->sizebuf)); err_assert (rc); nbytes = recv (self->fd, xs_msg_data (&self->msg), xs_msg_size (&self->msg), MSG_DONTWAIT); /* Sanitation of the result. */ if (unlikely (nbytes == 0)) { errno = ECONNREFUSED; nbytes = -1; } else if (unlikely (nbytes == -1 && (errno == EAGAIN || errno == EWOULDBLOCK))) nbytes = 0; if (nbytes < xs_msg_size (&self->msg)) { self->recvd = nbytes + 8; /* TODO: xs_instream_launch_async (self); */ return -EINPROGRESS; } /* Synchronous receive was successful. */ xs_msg_move (msg, &self->msg); return 0; }