Ejemplo n.º 1
0
 public override void OnAccept(IAsyncResult ar)
 {
     try
     {
         Socket newClientSocket = m_socket.EndAccept(ar);
         ClientSideProxy clientSideProxy = null;
         switch (m_ProxyType)
         {
             case (byte)ProxyLibTypes.ClientSideProxyTypes.CLIENT_SIDE_PROXY_PACK:
                 clientSideProxy = new PackClientSide(newClientSocket, m_serverSideEndPoint);
                 break;
             case (byte)ProxyLibTypes.ClientSideProxyTypes.CLIENT_SIDE_PROXY_GENERAL:
                 clientSideProxy = new ClientSideProxy(newClientSocket, m_serverSideEndPoint);
                 break;
         }
         Proxy.OnGotResults cbk = new Proxy.OnGotResults(OnGotResults);
         clientSideProxy.SetOnGotResults(cbk);
         Proxy.OnDisposed ondisp = new Proxy.OnDisposed(OnDisposed);
         clientSideProxy.SetOnDisposed(ondisp);
         /*Monitor.Enter(listLock);
         clientsList.Add(clientSideProxy);
         Monitor.Exit(listLock);*/
         clientSideProxy.Start();
         IAsyncResult ar2 = m_socket.BeginAccept(m_OnAccept, null);
         if (ar2.CompletedSynchronously)
         {
             LogUtility.LogUtility.LogFile(" completed synchronously ", LogUtility.LogLevels.LEVEL_LOG_HIGH);
             OnAccept(ar2);
         }
     }
     catch (Exception exc)
     {
         LogUtility.LogUtility.LogFile("EXCEPTION: " + exc.Message + " " + exc.StackTrace, LogUtility.LogLevels.LEVEL_LOG_HIGH);
     }
 }
Ejemplo n.º 2
0
        protected virtual void m_AcceptArgs_Completed(object sender, SocketAsyncEventArgs e)
        {
            Socket listenSocket = (Socket)sender;

            do
            {
                try
                {
                    if (e.SocketError != SocketError.Success)
                    {
                        LogUtility.LogUtility.LogFile("Error in Accept " + Convert.ToString(e.SocketError), LogUtility.LogLevels.LEVEL_LOG_HIGH);
                        continue;
                    }
                    Proxy  serverSideProxy = null;
                    Socket newClientSocket = e.AcceptSocket;
                    LogUtility.LogUtility.LogFile("Accepted " + Convert.ToString(e.BytesTransferred) + " " + Convert.ToString(newClientSocket != null), LogUtility.LogLevels.LEVEL_LOG_HIGH);
                    switch (m_ProxyType)
                    {
                    case (byte)ProxyLibTypes.ServerSideProxyTypes.SERVER_SIDE_PROXY_RAW:
                        serverSideProxy = new RawServerSideProxy(newClientSocket);
                        break;

                    case (byte)ProxyLibTypes.ServerSideProxyTypes.SERVER_SIDE_PROXY_HTTP:
                        serverSideProxy = new HttpServerSideProxy(newClientSocket);
                        break;

                    case (byte)ProxyLibTypes.ServerSideProxyTypes.SERVER_SIDE_PROXY_PACK_HTTP:
                        serverSideProxy = new PackHttpServerSide(newClientSocket);
                        break;

                    case (byte)ProxyLibTypes.ServerSideProxyTypes.SERVER_SIDE_PROXY_PACK_RAW:
                        serverSideProxy = new PackRawServerSide(newClientSocket);
                        break;
                    }
                    if (serverSideProxy != null)
                    {
                        Proxy.OnGotResults cbk = new Proxy.OnGotResults(OnGotResults);
                        serverSideProxy.SetOnGotResults(cbk);
                        Proxy.OnDisposed ondisp = new Proxy.OnDisposed(OnDisposed);
                        serverSideProxy.SetOnDisposed(ondisp);

                        /*Monitor.Enter(listLock);
                         * clientsList.Add(serverSideProxy);
                         * Monitor.Exit(listLock);*/
                        serverSideProxy.SetRemoteEndpoint(m_remoteEndpoint);
                        serverSideProxy.Start();
                    }
                }
                catch (Exception exc)
                {
                    LogUtility.LogUtility.LogFile("EXCEPTION: " + exc.Message + " " + exc.StackTrace, LogUtility.LogLevels.LEVEL_LOG_HIGH);
                }
                finally
                {
                    e.AcceptSocket = null; // to enable reuse
                }
            } while (!listenSocket.AcceptAsync(e));
        }
Ejemplo n.º 3
0
        public virtual void OnAccept(IAsyncResult ar)
        {
            try
            {
                Socket newClientSocket = m_socket.EndAccept(ar);
                Proxy  serverSideProxy = null;
                switch (m_ProxyType)
                {
                case (byte)ProxyLibTypes.ServerSideProxyTypes.SERVER_SIDE_PROXY_RAW:
                    serverSideProxy = new RawServerSideProxy(newClientSocket);
                    break;

                case (byte)ProxyLibTypes.ServerSideProxyTypes.SERVER_SIDE_PROXY_HTTP:
                    serverSideProxy = new HttpServerSideProxy(newClientSocket);
                    break;

                case (byte)ProxyLibTypes.ServerSideProxyTypes.SERVER_SIDE_PROXY_PACK_HTTP:
                    serverSideProxy = new PackHttpServerSide(newClientSocket);
                    break;

                case (byte)ProxyLibTypes.ServerSideProxyTypes.SERVER_SIDE_PROXY_PACK_RAW:
                    serverSideProxy = new PackRawServerSide(newClientSocket);
                    break;
                }
                if (serverSideProxy != null)
                {
                    Proxy.OnGotResults cbk = new Proxy.OnGotResults(OnGotResults);
                    serverSideProxy.SetOnGotResults(cbk);
                    Proxy.OnDisposed ondisp = new Proxy.OnDisposed(OnDisposed);
                    serverSideProxy.SetOnDisposed(ondisp);

                    /*Monitor.Enter(listLock);
                     * clientsList.Add(serverSideProxy);
                     * Monitor.Exit(listLock);*/
                    serverSideProxy.SetRemoteEndpoint(m_remoteEndpoint);
                    serverSideProxy.Start();
                }
                IAsyncResult ar2 = m_socket.BeginAccept(m_OnAccept, null);
                if (ar2.CompletedSynchronously)
                {
                    LogUtility.LogUtility.LogFile(" completed synchronously ", LogUtility.LogLevels.LEVEL_LOG_HIGH);
                    OnAccept(ar2);
                }
            }
            catch (Exception exc)
            {
                LogUtility.LogUtility.LogFile("EXCEPTION: " + exc.Message + " " + exc.StackTrace, LogUtility.LogLevels.LEVEL_LOG_HIGH);
            }
        }
Ejemplo n.º 4
0
 protected override void m_AcceptArgs_Completed(object sender, SocketAsyncEventArgs e)
 {
     Socket listenSocket = (Socket)sender;
     do
     {
         try
         {
             if (e.SocketError != SocketError.Success)
             {
                 LogUtility.LogUtility.LogFile("Error in Accept " + Convert.ToString(e.SocketError), LogUtility.LogLevels.LEVEL_LOG_HIGH);
                 continue;
             }
             Socket newClientSocket = e.AcceptSocket;
             LogUtility.LogUtility.LogFile("Accepted " + Convert.ToString(e.BytesTransferred) + " " + Convert.ToString(newClientSocket != null), LogUtility.LogLevels.LEVEL_LOG_HIGH);
             ClientSideProxy clientSideProxy = null;
             switch (m_ProxyType)
             {
                 case (byte)ProxyLibTypes.ClientSideProxyTypes.CLIENT_SIDE_PROXY_PACK:
                     clientSideProxy = new PackClientSide(newClientSocket, m_serverSideEndPoint);
                     break;
                 case (byte)ProxyLibTypes.ClientSideProxyTypes.CLIENT_SIDE_PROXY_GENERAL:
                     clientSideProxy = new ClientSideProxy(newClientSocket, m_serverSideEndPoint);
                     break;
             }
             Proxy.OnGotResults cbk = new Proxy.OnGotResults(OnGotResults);
             clientSideProxy.SetOnGotResults(cbk);
             Proxy.OnDisposed ondisp = new Proxy.OnDisposed(OnDisposed);
             clientSideProxy.SetOnDisposed(ondisp);
             /*Monitor.Enter(listLock);
             clientsList.Add(clientSideProxy);
             Monitor.Exit(listLock);*/
             clientSideProxy.Start();
         }
         catch (Exception exc)
         {
              LogUtility.LogUtility.LogFile("EXCEPTION: " + exc.Message + " " +  exc.StackTrace, LogUtility.LogLevels.LEVEL_LOG_HIGH);
         }
         finally
         {
             e.AcceptSocket = null; // to enable reuse
         }
     } while (!listenSocket.AcceptAsync(e));
 }