while (1) { print "before accept\n"; if (my $browser = $browser_listener->accept()) { #I am still receiving new connections while waiting for responses from existing connections my $req = recv_req($browser); my $remote = send_req($browser, $req); if ($remote) { $selector->add($remote); $pairs{$remote} = $browser; }; } print "after accept\n"; #with can_read, slow site is not blocking site with quick responses. foreach my $remote ($selector->can_read(1)) { print "can read res from site " . inet_ntoa($remote->peeraddr()) . "\n"; my $res = read_res($remote);#this is just one chunk of response, and we move to the next connection, so short responses are not blocked by big files if ($res) { send_res($pairs{$remote}, $res); } else { $selector->remove($remote); $remote->close(); $pairs{$remote}->close(); delete $pairs{$remote}; } } print "finished checking can read\n"; }