comparison common-channel.c @ 936:d93a6bcf616f

Improve handling lots of concurrent forwarded connections. Increase connection backlog, avoid check_close() for channels that haven't had IO
author Matt Johnston <matt@ucc.asn.au>
date Wed, 25 Jun 2014 23:42:39 +0800
parents 4696755c4cac
children 4ad38e223ccd
comparison
equal deleted inserted replaced
935:25692c60479e 936:d93a6bcf616f
206 } 206 }
207 207
208 /* Iterate through the channels, performing IO if available */ 208 /* Iterate through the channels, performing IO if available */
209 void channelio(fd_set *readfds, fd_set *writefds) { 209 void channelio(fd_set *readfds, fd_set *writefds) {
210 210
211 /* Listeners such as TCP, X11, agent-auth */
211 struct Channel *channel; 212 struct Channel *channel;
212 unsigned int i; 213 unsigned int i;
213 214
214 /* foreach channel */ 215 /* foreach channel */
215 for (i = 0; i < ses.chansize; i++) { 216 for (i = 0; i < ses.chansize; i++) {
217 /* Close checking only needs to occur for channels that had IO events */
218 int do_check_close = 0;
216 219
217 channel = ses.channels[i]; 220 channel = ses.channels[i];
218 if (channel == NULL) { 221 if (channel == NULL) {
219 /* only process in-use channels */ 222 /* only process in-use channels */
220 continue; 223 continue;
222 225
223 /* read data and send it over the wire */ 226 /* read data and send it over the wire */
224 if (channel->readfd >= 0 && FD_ISSET(channel->readfd, readfds)) { 227 if (channel->readfd >= 0 && FD_ISSET(channel->readfd, readfds)) {
225 TRACE(("send normal readfd")) 228 TRACE(("send normal readfd"))
226 send_msg_channel_data(channel, 0); 229 send_msg_channel_data(channel, 0);
230 do_check_close = 1;
227 } 231 }
228 232
229 /* read stderr data and send it over the wire */ 233 /* read stderr data and send it over the wire */
230 if (ERRFD_IS_READ(channel) && channel->errfd >= 0 234 if (ERRFD_IS_READ(channel) && channel->errfd >= 0
231 && FD_ISSET(channel->errfd, readfds)) { 235 && FD_ISSET(channel->errfd, readfds)) {
232 TRACE(("send normal errfd")) 236 TRACE(("send normal errfd"))
233 send_msg_channel_data(channel, 1); 237 send_msg_channel_data(channel, 1);
238 do_check_close = 1;
234 } 239 }
235 240
236 /* write to program/pipe stdin */ 241 /* write to program/pipe stdin */
237 if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) { 242 if (channel->writefd >= 0 && FD_ISSET(channel->writefd, writefds)) {
238 if (channel->initconn) { 243 if (channel->initconn) {
240 check_in_progress(channel); 245 check_in_progress(channel);
241 continue; /* Important not to use the channel after 246 continue; /* Important not to use the channel after
242 check_in_progress(), as it may be NULL */ 247 check_in_progress(), as it may be NULL */
243 } 248 }
244 writechannel(channel, channel->writefd, channel->writebuf); 249 writechannel(channel, channel->writefd, channel->writebuf);
250 do_check_close = 1;
245 } 251 }
246 252
247 /* stderr for client mode */ 253 /* stderr for client mode */
248 if (ERRFD_IS_WRITE(channel) 254 if (ERRFD_IS_WRITE(channel)
249 && channel->errfd >= 0 && FD_ISSET(channel->errfd, writefds)) { 255 && channel->errfd >= 0 && FD_ISSET(channel->errfd, writefds)) {
250 writechannel(channel, channel->errfd, channel->extrabuf); 256 writechannel(channel, channel->errfd, channel->extrabuf);
257 do_check_close = 1;
251 } 258 }
252 259
253 /* handle any channel closing etc */ 260 /* handle any channel closing etc */
254 check_close(channel); 261 if (do_check_close) {
255 262 check_close(channel);
256 } 263 }
257 264 }
258 /* Listeners such as TCP, X11, agent-auth */ 265
259 #ifdef USING_LISTENERS 266 #ifdef USING_LISTENERS
260 handle_listeners(readfds); 267 handle_listeners(readfds);
261 #endif 268 #endif
262 } 269 }
263 270