From: Volker Lendecke Date: Thu, 12 Mar 2020 15:05:58 +0000 (+0100) Subject: lib: Add ctdbd_init_async_connection() X-Git-Tag: ldb-2.2.0~861 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c70b8f069bb4c9f305556bc59e0466e312ad43bf;p=thirdparty%2Fsamba.git lib: Add ctdbd_init_async_connection() Prepare for ctdb_req_send/recv doing tevent_req based async ctdb requests Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h index f6040ad833b..123294ff782 100644 --- a/source3/include/ctdbd_conn.h +++ b/source3/include/ctdbd_conn.h @@ -34,6 +34,11 @@ struct messaging_rec; int ctdbd_init_connection(TALLOC_CTX *mem_ctx, const char *sockname, int timeout, struct ctdbd_connection **pconn); +int ctdbd_init_async_connection( + TALLOC_CTX *mem_ctx, + const char *sockname, + int timeout, + struct ctdbd_connection **pconn); int ctdbd_reinit_connection(TALLOC_CTX *mem_ctx, const char *sockname, int timeout, struct ctdbd_connection *conn); diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index 498f477a3be..35e5e34f49c 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -80,6 +80,11 @@ struct ctdbd_connection { /* Lists of pending async reads and writes */ struct ctdb_pkt_recv_state *recv_list; struct ctdb_pkt_send_state *send_list; + + /* + * Outgoing queue for writev_send of asynchronous ctdb requests + */ + struct tevent_queue *outgoing; }; static void ctdbd_async_socket_handler(struct tevent_context *ev, @@ -572,6 +577,37 @@ int ctdbd_reinit_connection(TALLOC_CTX *mem_ctx, return 0; } +int ctdbd_init_async_connection( + TALLOC_CTX *mem_ctx, + const char *sockname, + int timeout, + struct ctdbd_connection **pconn) +{ + struct ctdbd_connection *conn = NULL; + int ret; + + ret = ctdbd_init_connection(mem_ctx, sockname, timeout, &conn); + if (ret != 0) { + return ret; + } + + ret = set_blocking(conn->fd, false); + if (ret == -1) { + int err = errno; + TALLOC_FREE(conn); + return err; + } + + conn->outgoing = tevent_queue_create(conn, "ctdb async outgoing"); + if (conn->outgoing == NULL) { + TALLOC_FREE(conn); + return ENOMEM; + } + + *pconn = conn; + return 0; +} + int ctdbd_conn_get_fd(struct ctdbd_connection *conn) { return conn->fd;