Mercurial > dropbear
comparison netio.c @ 1033:ca71904cf3ee fastopen
Fixes for backwards compatibility
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 20 Feb 2015 23:38:05 +0800 |
parents | 0da8ba489c23 |
children | 107b013e9d9d |
comparison
equal
deleted
inserted
replaced
1032:0da8ba489c23 | 1033:ca71904cf3ee |
---|---|
66 c->cb_data = NULL; | 66 c->cb_data = NULL; |
67 } | 67 } |
68 | 68 |
69 static void connect_try_next(struct dropbear_progress_connection *c) { | 69 static void connect_try_next(struct dropbear_progress_connection *c) { |
70 struct addrinfo *r; | 70 struct addrinfo *r; |
71 int res = 0; | |
72 int fastopen = 0; | |
73 #ifdef DROPBEAR_TCP_FAST_OPEN | |
74 struct msghdr message; | |
75 #endif | |
71 | 76 |
72 if (!c->res_iter) { | 77 if (!c->res_iter) { |
73 return; | 78 return; |
74 } | 79 } |
75 | 80 |
87 | 92 |
88 #if defined(__linux__) && defined(TCP_DEFER_ACCEPT) | 93 #if defined(__linux__) && defined(TCP_DEFER_ACCEPT) |
89 set_piggyback_ack(c->sock); | 94 set_piggyback_ack(c->sock); |
90 #endif | 95 #endif |
91 | 96 |
92 #ifdef PROGRESS_CONNECT_FALLBACK | 97 #ifdef DROPBEAR_TCP_FAST_OPEN |
93 #if 0 | 98 fastopen = (c->writequeue != NULL); |
94 if (connect(c->sock, r->ai_addr, r->ai_addrlen) < 0) { | 99 |
95 if (errno == EINPROGRESS) { | 100 memset(&message, 0x0, sizeof(message)); |
96 TRACE(("Connect in progress")) | 101 message.msg_name = r->ai_addr; |
97 break; | 102 message.msg_namelen = r->ai_addrlen; |
98 } else { | 103 |
99 close(c->sock); | 104 if (c->writequeue) { |
100 c->sock = -1; | 105 int iovlen; /* Linux msg_iovlen is a size_t */ |
101 continue; | 106 message.msg_iov = packet_queue_to_iovec(c->writequeue, &iovlen); |
107 message.msg_iovlen = iovlen; | |
108 res = sendmsg(c->sock, &message, MSG_FASTOPEN); | |
109 if (res < 0 && errno == EOPNOTSUPP) { | |
110 TRACE(("Fastopen not supported")); | |
111 /* No kernel MSG_FASTOPEN support. Fall back below */ | |
112 fastopen = 0; | |
113 /* Set to NULL to avoid trying again */ | |
114 c->writequeue = NULL; | |
102 } | 115 } |
103 } | 116 m_free(message.msg_iov); |
104 | 117 if (res > 0) { |
105 break; /* Success. Treated the same as EINPROGRESS */ | 118 packet_queue_consume(c->writequeue, res); |
106 #endif | |
107 #else | |
108 { | |
109 struct msghdr message; | |
110 int res = 0; | |
111 memset(&message, 0x0, sizeof(message)); | |
112 message.msg_name = r->ai_addr; | |
113 message.msg_namelen = r->ai_addrlen; | |
114 | |
115 if (c->writequeue) { | |
116 int iovlen; /* Linux msg_iovlen is a size_t */ | |
117 message.msg_iov = packet_queue_to_iovec(c->writequeue, &iovlen); | |
118 message.msg_iovlen = iovlen; | |
119 res = sendmsg(c->sock, &message, MSG_FASTOPEN); | |
120 if (res < 0 && errno == EOPNOTSUPP) { | |
121 TRACE(("Fastopen not supported")); | |
122 /* No kernel MSG_FASTOPEN support. Fall back below */ | |
123 c->writequeue = NULL; | |
124 } | |
125 m_free(message.msg_iov); | |
126 if (res > 0) { | |
127 packet_queue_consume(c->writequeue, res); | |
128 } | |
129 } | 119 } |
130 | 120 } |
131 if (!c->writequeue) { | 121 #endif |
132 res = connect(c->sock, r->ai_addr, r->ai_addrlen); | 122 |
133 } | 123 /* Normal connect(), used as fallback for TCP fastopen too */ |
134 if (res < 0 && errno != EINPROGRESS) { | 124 if (!fastopen) { |
135 close(c->sock); | 125 res = connect(c->sock, r->ai_addr, r->ai_addrlen); |
136 c->sock = -1; | 126 } |
137 continue; | 127 |
138 } else { | 128 if (res < 0 && errno != EINPROGRESS) { |
139 break; | 129 close(c->sock); |
140 } | 130 c->sock = -1; |
141 } | 131 continue; |
142 #endif | 132 } else { |
143 } | 133 break; |
144 | 134 } |
135 } | |
145 | 136 |
146 if (r) { | 137 if (r) { |
147 c->res_iter = r->ai_next; | 138 c->res_iter = r->ai_next; |
148 } else { | 139 } else { |
149 c->res_iter = NULL; | 140 c->res_iter = NULL; |