All pastes #632798 Raw Edit

Gopneg

public text v1 · immutable
#632798 ·published 2007-07-25 05:12 UTC
rendered paste body
public void ListenSockThreadProc()
		{
			byte[] buf;
			int bytes;			

			StructSession structSes = serverSessions.sesList[forward.session] as StructSession;
			if ( (structSes == null) || (structSes.SesSocket == null) )
				return;
			
			while (structSes.SesSocket.Connected)
			{
				try
				{
					bytes = Common.ReceiveBuffer(structSes.SesSocket, out buf);
					totalBytesReceivedFromServer += bytes;
					TunnelClient.totalBytesReceivedFromServer += bytes;
				}
				catch (ThreadAbortException)
				{
					Common.Log("Socket server thread was successfully shutdowned. " + structSes.SesForward.ip + ":" + 
						structSes.SesForward.port + " " + structSes.SesForward.proto + ". Session \"" + 
						structSes.SesForward.session + "\"." + Common.CRLF, Common.LogType.Event);
					break;
				}
				catch (Exception e)
				{
					buf = new byte[0];
					bytes = 0;
					Common.Log("Could not receive data from remote server " + structSes.SesForward.ip + ":" + 
						structSes.SesForward.port + " " + structSes.SesForward.proto + ". Session \"" + 
						structSes.SesForward.session + "\". " + e.Message + Common.CRLF, Common.LogType.Error);
				}

				if (Common.debugMode)
				{
					if ( (structSes.SesSocket != null) && (structSes.SesSocket.Connected) )
						Common.Log("=Receive from server============" + 
							structSes.SesSocket.LocalEndPoint.ToString() + " " + structSes.SesSocket.RemoteEndPoint.ToString() + " " + 
							structSes.SesSocket.ProtocolType.ToString() + Common.CRLF, Common.LogType.Event);
					else
						Common.Log("=Receive from server============" + Common.CRLF, Common.LogType.Event);
					
					Common.Log(enc.GetString(buf, 0, bytes) + Common.CRLF, Common.LogType.Raw);
				}
				
				lock (serverSessions.sesList)
				{
					if (bytes <= 0)
					{
						Common.Log("Connection with server closed (receive 0 bytes)" + Common.CRLF, Common.LogType.Event);
						structSes.SocketState = SesSockState.Closed;
						if (structSes.SesSocket.Connected)
							structSes.SesSocket.Close();
						break;
					}
					else					
						structSes.SesStream.Write(buf, 0, buf.Length);
				}
				if (!forward.ping)
				{
					int pingCount = 0;
					SendDataToClient(structSes, ref pingCount, clnSck);
				}
			}
			Common.Log("Total: " + 
						totalBytesReceivedFromClient + " " +
						totalBytesReceivedFromServer + " " +
						totalBytesSendedToClient + " " +
						totalBytesSendedToServer + Common.CRLF, Common.LogType.Event);
		}
	}