Allow to specify connection timeout by the caller.
MFC after: 1 week
This commit is contained in:
parent
5ee1703532
commit
9d70b24b93
@ -515,7 +515,7 @@ init_remote(struct hast_resource *res, struct proto_conn **inp,
|
||||
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, struct proto_conn **inp,
|
||||
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;
|
||||
|
@ -165,7 +165,7 @@ proto_client(const char *addr, struct proto_conn **connp)
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -211,7 +211,7 @@ tcp4_client(const char *addr, void **ctxp)
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user