comparison netio.c @ 1035:8ed1d37e75a6 fastopen

get rid of some unnecessary code
author Matt Johnston <matt@ucc.asn.au>
date Sat, 21 Feb 2015 00:43:32 +0800
parents 107b013e9d9d
children e6c4cd0510d9
comparison
equal deleted inserted replaced
1034:107b013e9d9d 1035:8ed1d37e75a6
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; 71 int res = 0;
72 int fastopen = 0; 72 int fastopen = 0;
73 #ifdef DROPBEAR_TCP_FAST_OPEN 73 #ifdef DROPBEAR_TCP_FAST_OPEN
74 struct msghdr message; 74 struct msghdr message;
75 #endif 75 #endif
76
77 if (!c->res_iter) {
78 return;
79 }
80 76
81 for (r = c->res_iter; r; r = r->ai_next) 77 for (r = c->res_iter; r; r = r->ai_next)
82 { 78 {
83 assert(c->sock == -1); 79 assert(c->sock == -1);
84 80
86 if (c->sock < 0) { 82 if (c->sock < 0) {
87 continue; 83 continue;
88 } 84 }
89 85
90 ses.maxfd = MAX(ses.maxfd, c->sock); 86 ses.maxfd = MAX(ses.maxfd, c->sock);
87 set_sock_nodelay(c->sock);
91 setnonblocking(c->sock); 88 setnonblocking(c->sock);
92 89
93 #if defined(__linux__) && defined(TCP_DEFER_ACCEPT) 90 #if defined(__linux__) && defined(TCP_DEFER_ACCEPT)
94 set_piggyback_ack(c->sock); 91 set_piggyback_ack(c->sock);
95 #endif 92 #endif
112 fastopen = 0; 109 fastopen = 0;
113 /* Set to NULL to avoid trying again */ 110 /* Set to NULL to avoid trying again */
114 c->writequeue = NULL; 111 c->writequeue = NULL;
115 } 112 }
116 m_free(message.msg_iov); 113 m_free(message.msg_iov);
117 if (res > 0) { 114 packet_queue_consume(c->writequeue, res);
118 packet_queue_consume(c->writequeue, res);
119 }
120 } 115 }
121 #endif 116 #endif
122 117
123 /* Normal connect(), used as fallback for TCP fastopen too */ 118 /* Normal connect(), used as fallback for TCP fastopen too */
124 if (!fastopen) { 119 if (!fastopen) {
125 res = connect(c->sock, r->ai_addr, r->ai_addrlen); 120 res = connect(c->sock, r->ai_addr, r->ai_addrlen);
126 } 121 }
127 122
128 if (res < 0 && errno != EINPROGRESS) { 123 if (res < 0 && errno != EINPROGRESS) {
124 /* failure */
129 close(c->sock); 125 close(c->sock);
130 c->sock = -1; 126 c->sock = -1;
131 continue; 127 continue;
132 } else { 128 } else {
129 /* new connection was successful, wait for it to complete */
133 break; 130 break;
134 } 131 }
135 } 132 }
136 133
137 if (r) { 134 if (r) {
138 c->res_iter = r->ai_next; 135 c->res_iter = r->ai_next;
139 } else { 136 } else {
140 c->res_iter = NULL; 137 c->res_iter = NULL;
141 }
142
143 if (c->sock >= 0 || (errno == EINPROGRESS)) {
144 /* Success */
145 set_sock_nodelay(c->sock);
146 return;
147 } else {
148 if (!c->res_iter)
149 {
150
151 }
152 /* XXX - returning error message through */
153 #if 0
154 /* Failed */
155 if (errstring != NULL && *errstring == NULL) {
156 int len;
157 len = 20 + strlen(strerror(err));
158 *errstring = (char*)m_malloc(len);
159 snprintf(*errstring, len, "Error connecting: %s", strerror(err));
160 }
161 TRACE(("Error connecting: %s", strerror(err)))
162 #endif
163 } 138 }
164 } 139 }
165 140
166 /* Connect via TCP to a host. */ 141 /* Connect via TCP to a host. */
167 struct dropbear_progress_connection *connect_remote(const char* remotehost, const char* remoteport, 142 struct dropbear_progress_connection *connect_remote(const char* remotehost, const char* remoteport,