SetRequestReceivedCallback() public méthode

Sets the callback used to receive notifications of new events.
public SetRequestReceivedCallback ( TcpChannelRequestEventHandler callback ) : void
callback TcpChannelRequestEventHandler
Résultat void
Exemple #1
0
        /// <summary>
        /// Handles a new connection.
        /// </summary>
        private void OnAcceptIPv6(IAsyncResult result)
        {
            TcpServerChannel channel = null;

            lock (m_lock)
            {
                // check if the socket has been closed.
                if (m_listeningSocketIPv6 == null)
                {
                    return;
                }

                try
                {
                    // accept the socket.
                    Socket socket = m_listeningSocketIPv6.EndAccept(result);

                    // create the channel to manage incoming messages.
                    channel = new TcpServerChannel(
                        m_listenerId,
                        this,
                        m_bufferManager,
                        m_quotas,
                        m_serverCertificate,
                        m_descriptions);
                    //channel.ServerCertificateChain = m_serverCertificateChain;

                    // start accepting messages on the channel.
                    channel.Attach(++m_lastChannelId, socket);

                    // save the channel for shutdown and reconnects.
                    m_channels.Add(m_lastChannelId, channel);

                    if (m_callback != null)
                    {
                        channel.SetRequestReceivedCallback(new TcpChannelRequestEventHandler(OnRequestReceived));
                    }

                    // Utils.Trace("Channel {0} created.", m_lastChannelId);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Unexpected error accepting a new connection.");
                }

                // go back and wait for the next connection.
                try
                {
                    m_listeningSocketIPv6.BeginAccept(OnAcceptIPv6, null);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Unexpected error listening for a new IPv6 connection.");
                }
            }
        }
        /// <summary>
        /// Handles a new connection.
        /// </summary>
        private void OnAccept(object sender, SocketAsyncEventArgs e)
        {
            TcpServerChannel channel = null;

            lock (m_lock)
            {
                // check if the accept socket has been created.
                if (e.AcceptSocket == null || e.SocketError != SocketError.Success)
                {
                    Utils.Trace("OnAccept: No accept socket or error." + e.SocketError.ToString());
                    return;
                }

                try
                {
                    // create the channel to manage incoming messages.
                    channel = new TcpServerChannel(
                        m_listenerId,
                        this,
                        m_bufferManager,
                        m_quotas,
                        m_serverCertificate,
                        m_descriptions);

                    // start accepting messages on the channel.
                    channel.Attach(++m_lastChannelId, e.AcceptSocket);

                    // save the channel for shutdown and reconnects.
                    m_channels.Add(m_lastChannelId, channel);

                    if (m_callback != null)
                    {
                        channel.SetRequestReceivedCallback(new TcpChannelRequestEventHandler(OnRequestReceived));
                    }
                }
                catch (Exception ex)
                {
                    Utils.Trace(ex, "Unexpected error accepting a new connection.");
                }

                // go back and wait for the next connection.
                try
                {
                    Socket listeningSocket    = e.UserToken as Socket;
                    SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                    args.Completed += OnAccept;
                    args.UserToken  = listeningSocket;
                    listeningSocket.AcceptAsync(args);
                }
                catch (Exception ex)
                {
                    Utils.Trace(ex, "Unexpected error listening for a new connection.");
                }
            }
        }
Exemple #3
0
        internal UaTcpReplyChannel(
            ChannelManagerBase manager,
            string listenerId,
            EndpointAddress address,
            TcpServerChannel channel,
            TcpChannelQuotas quotas)
            :
            base(manager)
        {
            m_listenerId = listenerId;
            m_address    = address;
            m_channel    = channel;
            m_quotas     = quotas;

            m_requestQueue   = new Queue <RequestContext>();
            m_operationQueue = new Queue <TcpAsyncOperation <RequestContext> >();

            m_RequestReceivedCallback = new TcpChannelRequestEventHandler(OnRequestReceived);

            // register for notifications.
            m_channel.SetRequestReceivedCallback(m_RequestReceivedCallback);
        }
Exemple #4
0
        /// <summary>
        /// Handles a new connection.
        /// </summary>
        private void OnAcceptIPv6(IAsyncResult result)
        {
            TcpServerChannel channel = null;

            lock (m_lock)
            {
                // check if the socket has been closed.
                if (m_listeningSocketIPv6 == null)
                {
                    return;
                }

                try
                {
                    // accept the socket.
                    Socket socket = m_listeningSocketIPv6.EndAccept(result);      
                        
                    // create the channel to manage incoming messages.
                    channel = new TcpServerChannel(
                        m_listenerId,
                        this,
                        m_bufferManager,
                        m_quotas,
                        m_serverCertificate,
                        m_descriptions);
                    //channel.ServerCertificateChain = m_serverCertificateChain;

                    // start accepting messages on the channel.
                    channel.Attach(++m_lastChannelId, socket);
                    
                    // save the channel for shutdown and reconnects.
                    m_channels.Add(m_lastChannelId, channel);

                    if (m_callback != null)
                    {
                        channel.SetRequestReceivedCallback(new TcpChannelRequestEventHandler(OnRequestReceived));
                    }

                    // Utils.Trace("Channel {0} created.", m_lastChannelId);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Unexpected error accepting a new connection.");
                }

                // go back and wait for the next connection.
                try
                {
                    m_listeningSocketIPv6.BeginAccept(OnAcceptIPv6, null);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Unexpected error listening for a new IPv6 connection.");
                }
            }   
        }
        /// <summary>
        /// Handles a new connection.
        /// </summary>
        private void OnAccept(object sender, SocketAsyncEventArgs e)
        {
            TcpServerChannel channel = null;

            lock (m_lock)
            {
                Socket listeningSocket = e.UserToken as Socket;

                if (listeningSocket == null)
                {
                    Utils.Trace("OnAccept: Listensocket was null." );
                    e.Dispose();
                    return;
                }

                // check if the accept socket has been created.
                if (e.AcceptSocket != null && e.SocketError == SocketError.Success)
                {
                    try
                    {
                        // create the channel to manage incoming messages.
                        channel = new TcpServerChannel(
                            m_listenerId,
                            this,
                            m_bufferManager,
                            m_quotas,
                            m_serverCertificate,
                            m_descriptions);

                        // start accepting messages on the channel.
                        channel.Attach(++m_lastChannelId, e.AcceptSocket);

                        // save the channel for shutdown and reconnects.
                        m_channels.Add(m_lastChannelId, channel);

                        if (m_callback != null)
                        {
                            channel.SetRequestReceivedCallback(new TcpChannelRequestEventHandler(OnRequestReceived));
                        }
                    }
                    catch (Exception ex)
                    {
                        Utils.Trace(ex, "Unexpected error accepting a new connection.");
                    }
                }

                e.Dispose();

                // go back and wait for the next connection.
                try
                {
                    e = new SocketAsyncEventArgs();
                    e.Completed += OnAccept;
                    e.UserToken = listeningSocket;
                    listeningSocket.AcceptAsync(e);
                }
                catch (Exception ex)
                {
                    Utils.Trace(ex, "Unexpected error listening for a new connection.");
                }
            }
        }
        /// <summary>
        /// Handles a new connection.
        /// </summary>
        private void OnAccept(object sender, SocketAsyncEventArgs e)
        {
            TcpServerChannel channel      = null;
            bool             repeatAccept = false;

            do
            {
                repeatAccept = false;
                lock (m_lock)
                {
                    Socket listeningSocket = e.UserToken as Socket;

                    if (listeningSocket == null)
                    {
                        Utils.Trace("OnAccept: Listensocket was null.");
                        e.Dispose();
                        return;
                    }

                    // check if the accept socket has been created.
                    if (e.AcceptSocket != null && e.SocketError == SocketError.Success)
                    {
                        try
                        {
                            // create the channel to manage incoming messages.
                            channel = new TcpServerChannel(
                                m_listenerId,
                                this,
                                m_bufferManager,
                                m_quotas,
                                m_serverCertificate,
                                m_serverCertificateChain,
                                m_descriptions);

                            if (m_callback != null)
                            {
                                channel.SetRequestReceivedCallback(new TcpChannelRequestEventHandler(OnRequestReceived));
                            }

                            // start accepting messages on the channel.
                            channel.Attach(++m_lastChannelId, e.AcceptSocket);

                            // save the channel for shutdown and reconnects.
                            m_channels.Add(m_lastChannelId, channel);
                        }
                        catch (Exception ex)
                        {
                            Utils.Trace(ex, "Unexpected error accepting a new connection.");
                        }
                    }

                    e.Dispose();

                    if (e.SocketError != SocketError.OperationAborted)
                    {
                        // go back and wait for the next connection.
                        try
                        {
                            e            = new SocketAsyncEventArgs();
                            e.Completed += OnAccept;
                            e.UserToken  = listeningSocket;
                            if (!listeningSocket.AcceptAsync(e))
                            {
                                repeatAccept = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            Utils.Trace(ex, "Unexpected error listening for a new connection.");
                        }
                    }
                }
            } while (repeatAccept);
        }