Ejemplo n.º 1
0
        /*
         * void OnConnectionAccepted(object sender, SocketAsyncEventArgs e)
         * {
         *      var brr = new ByteReaderAndRequest(new ByteReader(RecFactory));
         *      OpenSockets[Socket] = brr;
         * }
         */

        /// <summary>
        /// Accepts all pending connections on a socket asynchronously.
        /// </summary>
        private void BeginAcceptNewConnections(Socket listenSocket)
        {
            Socket newConnection;

            try
            {
                // The commented implementation crashes Mono with a too many heaps warning on Mono 3.0.7... investigate later

                /*
                 * SocketAsyncEventArgs args;
                 * do
                 * {
                 *      args = new SocketAsyncEventArgs();
                 *      args.Completed += OnConnectionAccepted;
                 * }
                 * while (listenSocket.AcceptAsync(args) == true);*/

                newConnection = listenSocket.Accept();
                //var request = new SocketRequest(newConnection, false);

                //OpenSockets[newConnection] = new RecordFactoryAndRequest(new RecordFactory(), newConnection, Logger);
                var request = new FosRequest(newConnection, Logger);
                request.OnSocketClose     += () => OnNormalSocketClose(newConnection, request);
                OpenSockets[newConnection] = request;
                if (Logger != null)
                {
                    Logger.LogConnectionReceived(newConnection);
                }
            }
            catch (Exception e)
            {
                if (Logger != null)
                {
                    Logger.LogSocketError(listenSocket, e, "Error when accepting connection on the listen socket.");
                }
            }
        }