diff options
author | Matt Johnston <matt@ucc.asn.au> | 2015-02-20 23:38:05 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2015-02-20 23:38:05 +0800 |
commit | f04a3a2cfa6a2787e84b07d6d22cb1e9837ff6af (patch) | |
tree | 0e0fca0c506d49ce51f636237db6f8f89b8cc38f /netio.c | |
parent | 364a53577eb33f20bed877fc5d4a54de829707d8 (diff) |
Fixes for backwards compatibility
--HG--
branch : fastopen
Diffstat (limited to 'netio.c')
-rw-r--r-- | netio.c | 85 |
1 files changed, 38 insertions, 47 deletions
@@ -68,6 +68,11 @@ void cancel_connect(struct dropbear_progress_connection *c) { static void connect_try_next(struct dropbear_progress_connection *c) { struct addrinfo *r; + int res = 0; + int fastopen = 0; +#ifdef DROPBEAR_TCP_FAST_OPEN + struct msghdr message; +#endif if (!c->res_iter) { return; @@ -89,59 +94,45 @@ static void connect_try_next(struct dropbear_progress_connection *c) { set_piggyback_ack(c->sock); #endif -#ifdef PROGRESS_CONNECT_FALLBACK -#if 0 - if (connect(c->sock, r->ai_addr, r->ai_addrlen) < 0) { - if (errno == EINPROGRESS) { - TRACE(("Connect in progress")) - break; - } else { - close(c->sock); - c->sock = -1; - continue; +#ifdef DROPBEAR_TCP_FAST_OPEN + fastopen = (c->writequeue != NULL); + + memset(&message, 0x0, sizeof(message)); + message.msg_name = r->ai_addr; + message.msg_namelen = r->ai_addrlen; + + if (c->writequeue) { + int iovlen; /* Linux msg_iovlen is a size_t */ + message.msg_iov = packet_queue_to_iovec(c->writequeue, &iovlen); + message.msg_iovlen = iovlen; + res = sendmsg(c->sock, &message, MSG_FASTOPEN); + if (res < 0 && errno == EOPNOTSUPP) { + TRACE(("Fastopen not supported")); + /* No kernel MSG_FASTOPEN support. Fall back below */ + fastopen = 0; + /* Set to NULL to avoid trying again */ + c->writequeue = NULL; + } + m_free(message.msg_iov); + if (res > 0) { + packet_queue_consume(c->writequeue, res); } } - - break; /* Success. Treated the same as EINPROGRESS */ #endif -#else - { - struct msghdr message; - int res = 0; - memset(&message, 0x0, sizeof(message)); - message.msg_name = r->ai_addr; - message.msg_namelen = r->ai_addrlen; - - if (c->writequeue) { - int iovlen; /* Linux msg_iovlen is a size_t */ - message.msg_iov = packet_queue_to_iovec(c->writequeue, &iovlen); - message.msg_iovlen = iovlen; - res = sendmsg(c->sock, &message, MSG_FASTOPEN); - if (res < 0 && errno == EOPNOTSUPP) { - TRACE(("Fastopen not supported")); - /* No kernel MSG_FASTOPEN support. Fall back below */ - c->writequeue = NULL; - } - m_free(message.msg_iov); - if (res > 0) { - packet_queue_consume(c->writequeue, res); - } - } - if (!c->writequeue) { - res = connect(c->sock, r->ai_addr, r->ai_addrlen); - } - if (res < 0 && errno != EINPROGRESS) { - close(c->sock); - c->sock = -1; - continue; - } else { - break; - } + /* Normal connect(), used as fallback for TCP fastopen too */ + if (!fastopen) { + res = connect(c->sock, r->ai_addr, r->ai_addrlen); } -#endif - } + if (res < 0 && errno != EINPROGRESS) { + close(c->sock); + c->sock = -1; + continue; + } else { + break; + } + } if (r) { c->res_iter = r->ai_next; |