-/* Licensed under BSD-MIT - see LICENSE file for details */
+/* Licensed under LGPLv2.1+ - see LICENSE file for details */
#include "io.h"
#include "backend.h"
#include <sys/types.h>
conn->fd.finish_arg = conn->fd.next_arg = arg;
conn->state = NEXT;
conn->duplex = NULL;
+ conn->timeout = NULL;
if (!add_conn(conn)) {
free(conn);
return NULL;
conn->fd.finish_arg = conn->fd.next_arg = arg;
conn->state = NEXT;
conn->duplex = old;
+ conn->timeout = NULL;
if (!add_duplex(conn)) {
free(conn);
return NULL;
return to_ionext(conn);
}
+bool io_timeout_(struct io_conn *conn, struct timespec ts,
+ struct io_op *(*next)(struct io_conn *, void *), void *arg)
+{
+ if (!conn->timeout) {
+ conn->timeout = malloc(sizeof(*conn->timeout));
+ if (!conn->timeout)
+ return false;
+ } else
+ assert(!timeout_active(conn));
+
+ conn->timeout->next = next;
+ conn->timeout->next_arg = arg;
+ backend_add_timeout(conn, ts);
+ return true;
+}
+
/* Queue some data to be written. */
struct io_op *io_write(const void *data, size_t len, struct io_next *next)
{
static struct io_op *do_next(struct io_conn *conn)
{
+ if (timeout_active(conn))
+ backend_del_timeout(conn);
return conn->fd.next(conn, conn->fd.next_arg);
}