From owner-svn-src-head@FreeBSD.ORG Wed Feb 2 15:42:00 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 671321065679; Wed, 2 Feb 2011 15:42:00 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 54DB58FC18; Wed, 2 Feb 2011 15:42:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p12Fg08e013718; Wed, 2 Feb 2011 15:42:00 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p12Fg05o013711; Wed, 2 Feb 2011 15:42:00 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201102021542.p12Fg05o013711@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Wed, 2 Feb 2011 15:42:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r218192 - head/sbin/hastd X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Feb 2011 15:42:00 -0000 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) {