I'm currently writing a socks server. It works well, except the proxying itself. I'm currently using the following as a way to test the protocol stuff works (it does), but it obviously doesnt scale:

while (con.connected && sockscon.connected)
{
	try
	{
		while (con.dataAvailableForRead)
		{
			sockscon.write(con, con.leastSize);
			yield();
		}
		while (sockscon.dataAvailableForRead)
		{
			con.write(sockscon, sockscon.leastSize);
			yield();
		}
		yield();
		sleep(1.msecs);
	}
	catch
	{
		break;
	}						
}

How would I go about efficiently proxying one tcp connection into another?