crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

handle.cc (1142B)


      1 #include "tcpdispatcher"
      2 
      3 void TcpDispatcher::handle() {
      4     
      5     debugmsg("TCP dispatcher: About to shuttle between client fd " <<
      6 	     clientfd().fd() << " and backend fd " << backendfd().fd() <<
      7 	     '\n');
      8     
      9     Fdset readset(maxtimeout(config.client_read_timeout(),
     10 			     config.backend_read_timeout()));
     11     readset.add(clientfd());
     12     readset.add(backendfd());
     13     while (1) {
     14 	Socket sock, othersock;
     15 	int timeout;
     16 
     17 	readset.wait_r();	
     18 	if (readset.readable(clientfd())) {
     19 	    sock = clientfd();
     20 	    othersock = backendfd();
     21 	    timeout = config.backend_write_timeout();
     22 	} else if (readset.readable(backendfd())) {
     23 	    sock = backendfd();
     24 	    othersock = clientfd();
     25 	    timeout = config.client_write_timeout();
     26 	} else
     27 	    break;
     28 
     29 	if (!netbuffer.netread(sock))
     30 	    break;
     31 	debugmsg("Had data on " << sock.fd() <<
     32 		 ", sending to " << othersock.fd() << '\n');
     33 	netbuffer.netwrite (othersock, timeout);
     34 	if (sock == backendfd())
     35 	    balancer.backend(targetbackend()).addbytes(netbuffer.bufsz());
     36 	else
     37 	    IPStore::activity(clientfd().clientaddr().sin_addr,
     38 			      targetbackend());
     39 
     40 	netbuffer.reset();
     41     }
     42 }