Date: Wed, 2 Feb 2011 15:42:00 +0000 (UTC) From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r218192 - head/sbin/hastd Message-ID: <201102021542.p12Fg05o013711@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pjd Date: Wed Feb 2 15:42:00 2011 New Revision: 218192 URL: http://svn.freebsd.org/changeset/base/218192 Log: Allow to specify connection timeout by the caller. MFC after: 1 week Modified: head/sbin/hastd/primary.c head/sbin/hastd/proto.c head/sbin/hastd/proto.h head/sbin/hastd/proto_impl.h head/sbin/hastd/proto_tcp4.c head/sbin/hastd/proto_uds.c Modified: head/sbin/hastd/primary.c ============================================================================== --- head/sbin/hastd/primary.c Wed Feb 2 15:23:07 2011 (r218191) +++ head/sbin/hastd/primary.c Wed Feb 2 15:42:00 2011 (r218192) @@ -515,7 +515,7 @@ init_remote(struct hast_resource *res, s res->hr_remoteaddr); } /* Try to connect, but accept failure. */ - if (proto_connect(out) < 0) { + if (proto_connect(out, HAST_TIMEOUT) < 0) { pjdlog_errno(LOG_WARNING, "Unable to connect to %s", res->hr_remoteaddr); goto close; @@ -582,7 +582,7 @@ init_remote(struct hast_resource *res, s res->hr_remoteaddr); } /* Try to connect, but accept failure. */ - if (proto_connect(in) < 0) { + if (proto_connect(in, HAST_TIMEOUT) < 0) { pjdlog_errno(LOG_WARNING, "Unable to connect to %s", res->hr_remoteaddr); goto close; Modified: head/sbin/hastd/proto.c ============================================================================== --- head/sbin/hastd/proto.c Wed Feb 2 15:23:07 2011 (r218191) +++ head/sbin/hastd/proto.c Wed Feb 2 15:42:00 2011 (r218192) @@ -165,7 +165,7 @@ proto_client(const char *addr, struct pr } int -proto_connect(struct proto_conn *conn) +proto_connect(struct proto_conn *conn, int timeout) { int ret; @@ -174,8 +174,9 @@ proto_connect(struct proto_conn *conn) PJDLOG_ASSERT(conn->pc_side == PROTO_SIDE_CLIENT); PJDLOG_ASSERT(conn->pc_proto != NULL); PJDLOG_ASSERT(conn->pc_proto->hp_connect != NULL); + PJDLOG_ASSERT(timeout >= 0); - ret = conn->pc_proto->hp_connect(conn->pc_ctx); + ret = conn->pc_proto->hp_connect(conn->pc_ctx, timeout); if (ret != 0) { errno = ret; return (-1); Modified: head/sbin/hastd/proto.h ============================================================================== --- head/sbin/hastd/proto.h Wed Feb 2 15:23:07 2011 (r218191) +++ head/sbin/hastd/proto.h Wed Feb 2 15:42:00 2011 (r218192) @@ -38,7 +38,7 @@ struct proto_conn; int proto_client(const char *addr, struct proto_conn **connp); -int proto_connect(struct proto_conn *conn); +int proto_connect(struct proto_conn *conn, int timeout); int proto_server(const char *addr, struct proto_conn **connp); int proto_accept(struct proto_conn *conn, struct proto_conn **newconnp); int proto_send(const struct proto_conn *conn, const void *data, size_t size); Modified: head/sbin/hastd/proto_impl.h ============================================================================== --- head/sbin/hastd/proto_impl.h Wed Feb 2 15:23:07 2011 (r218191) +++ head/sbin/hastd/proto_impl.h Wed Feb 2 15:42:00 2011 (r218192) @@ -40,7 +40,7 @@ #define __constructor __attribute__((constructor)) typedef int hp_client_t(const char *, void **); -typedef int hp_connect_t(void *); +typedef int hp_connect_t(void *, int); typedef int hp_server_t(const char *, void **); typedef int hp_accept_t(void *, void **); typedef int hp_send_t(void *, const unsigned char *, size_t); Modified: head/sbin/hastd/proto_tcp4.c ============================================================================== --- head/sbin/hastd/proto_tcp4.c Wed Feb 2 15:23:07 2011 (r218191) +++ head/sbin/hastd/proto_tcp4.c Wed Feb 2 15:42:00 2011 (r218192) @@ -211,7 +211,7 @@ tcp4_client(const char *addr, void **ctx } static int -tcp4_connect(void *ctx) +tcp4_connect(void *ctx, int timeout) { struct tcp4_ctx *tctx = ctx; struct timeval tv; @@ -223,6 +223,7 @@ tcp4_connect(void *ctx) PJDLOG_ASSERT(tctx->tc_magic == TCP4_CTX_MAGIC); PJDLOG_ASSERT(tctx->tc_side == TCP4_SIDE_CLIENT); PJDLOG_ASSERT(tctx->tc_fd >= 0); + PJDLOG_ASSERT(timeout >= 0); flags = fcntl(tctx->tc_fd, F_GETFL); if (flags == -1) { @@ -255,7 +256,7 @@ tcp4_connect(void *ctx) * Connection can't be established immediately, let's wait * for HAST_TIMEOUT seconds. */ - tv.tv_sec = HAST_TIMEOUT; + tv.tv_sec = timeout; tv.tv_usec = 0; again: FD_ZERO(&fdset); Modified: head/sbin/hastd/proto_uds.c ============================================================================== --- head/sbin/hastd/proto_uds.c Wed Feb 2 15:23:07 2011 (r218191) +++ head/sbin/hastd/proto_uds.c Wed Feb 2 15:42:00 2011 (r218192) @@ -123,7 +123,7 @@ uds_client(const char *addr, void **ctxp } static int -uds_connect(void *ctx) +uds_connect(void *ctx, int timeout) { struct uds_ctx *uctx = ctx; @@ -131,6 +131,7 @@ uds_connect(void *ctx) PJDLOG_ASSERT(uctx->uc_magic == UDS_CTX_MAGIC); PJDLOG_ASSERT(uctx->uc_side == UDS_SIDE_CLIENT); PJDLOG_ASSERT(uctx->uc_fd >= 0); + PJDLOG_ASSERT(timeout >= 0); if (connect(uctx->uc_fd, (struct sockaddr *)&uctx->uc_sun, sizeof(uctx->uc_sun)) < 0) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201102021542.p12Fg05o013711>