Exemple #1
0
        // Asynchronous callback for BeginConnect
        private void OnConnect(IAsyncResult asyncResult)
        {
            var noti = new LinkSessionConnected { LinkName = Name };

            try
            {
                socket.EndConnect(asyncResult);

                // Adjust socket options.
                socket.NoDelay = NoDelay;

                Log.Info("{0} {1} connected to {2}", Name, socket.Handle, socket.RemoteEndPoint);

                noti.Result = true;

                ConnectInternal();

                session = new TcpLinkSession(this, socket);
                session.Polarity = true;

                if (BufferTransform != null)
                {
                    session.BufferTransform = BufferTransform;
                }

                noti.Context = session;
                Flow.Publish(noti);

                session.BeginReceive(true);
            }
            catch (Exception e)
            {
                Log.Warn("{0} connect error: {1}", Name, e.Message);

                var endpoint = (EndPoint)asyncResult.AsyncState;

                noti.Context = endpoint;
                Flow.Publish(noti);

                RetryInternal(endpoint);
            }
        }
Exemple #2
0
        // Asynchronous callback for BeginAccept
        private void OnAccept(IAsyncResult asyncResult)
        {
            try
            {
                var clientSocket = socket.EndAccept(asyncResult);

                Diag.IncrementConnectionCount();

                // Adjust client socket options.
                clientSocket.NoDelay = NoDelay;

                Log.Info("{0} {1} accepted from {2}",
                    Name, clientSocket.Handle, clientSocket.RemoteEndPoint);

                var session = new TcpLinkSession(this, clientSocket);

                if (BufferTransform != null)
                {
                    session.BufferTransform = (IBufferTransform)BufferTransform.Clone();
                }

                Flow.Publish(new LinkSessionConnected {
                    LinkName = Name,
                    Result = true,
                    Context = session
                });

                session.BeginReceive(true);

                AcceptImpl();
            }
            catch (Exception e)
            {
                Log.Warn("{0} accept error: {1}", Name, e.Message);
            }
        }