*/
int fr_control_message_send(fr_control_t *c, fr_ring_buffer_t *rb, uint32_t id, void *data, size_t data_size)
{
- ssize_t ret;
- int delay = 0;
(void) talloc_get_type_abort(c, fr_control_t);
if (c->same_thread) {
if (fr_control_message_push(c, rb, id, data, data_size) < 0) return -1;
-again:
- if ((ret = write(c->pipe[1], ".", 1)) == 1) return 0;
+redo:
+ if (write(c->pipe[1], ".", 1) >= 0) return 0;
+
+ if (errno == EINTR) goto redo;
+
+ /*
+ * EAGAIN means that the pipe is full, which means that the other end will eventually
+ * read from it.
+ */
+ if (errno == EAGAIN) return 0;
- if ((ret < 0) && (errno != EAGAIN)
#if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
- && (errno != EWOULDBLOCK)
+ if (errno == EWOULDBLOCK) return 0;
#endif
- ) {
- return -1;
- }
/*
- * @todo - this is pretty crap. We should instead have a better way to deal with things when the
- * pipe gets full.
+ * Other error, that's an issue.
*/
- delay += 10;
- usleep(delay);
- goto again;
+ return -1;
}