Esempio n. 1
0
        protected virtual bool Process(Event e)
        {
            switch (e.GetTypeId())
            {
                case (int)LinkEventType.HandshakeReq:
                    {
                        var req = (HandshakeReq)e;
                        var resp = new HandshakeResp { _Transform = false };
                        byte[] response = null;
                        try
                        {
                            ManualResetEvent waitHandle =
                                LinkWaitHandlePool.Acquire(InternalHandle);
                            waitHandle.WaitOne(new TimeSpan(0, 0, 30));
                            LinkWaitHandlePool.Release(InternalHandle);
                            response = BufferTransform.Handshake(req.Data);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("{0} {1} error handshaking : {2}",
                                link.Name, InternalHandle, ex.ToString());
                        }
                        if (response != null)
                        {
                            resp.Data = response;
                        }
                        Send(resp);
                    }
                    break;
                case (int)LinkEventType.HandshakeResp:
                    {
                        var ack = new HandshakeAck { _Transform = false };
                        var resp = (HandshakeResp)e;
                        try
                        {
                            if (BufferTransform.FinalizeHandshake(resp.Data))
                            {
                                rxTransformReady = true;
                                ack.Result = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error("{0} {1} error finishing handshake : {2}",
                                link.Name, InternalHandle, ex.ToString());
                        }
                        Send(ack);
                    }
                    break;
                case (int)LinkEventType.HandshakeAck:
                    {
                        var ack = (HandshakeAck)e;
                        bool result = ack.Result;

                        if (result)
                        {
                            txTransformReady = true;
                        }

                        link.OnLinkSessionConnectedInternal(result, (result ? this : null));
                    }
                    break;
                case (int)LinkEventType.SessionReq:
                    if (link.SessionRecoveryEnabled && polarity == false)
                    {
                        var server = (ServerLink)link;
                        server.OnSessionReq(this, (SessionReq)e);
                    }
                    break;
                case (int)LinkEventType.SessionResp:
                    if (link.SessionRecoveryEnabled && polarity == true)
                    {
                        var client = (ClientLink)link;
                        client.OnSessionResp(this, (SessionResp)e);
                    }
                    break;
                case (int)LinkEventType.SessionAck:
                    if (link.SessionRecoveryEnabled && polarity == false)
                    {
                        var server = (ServerLink)link;
                        server.OnSessionAck(this, (SessionAck)e);
                    }
                    break;
                case (int)LinkEventType.SessionEnd:
                    if (link.SessionRecoveryEnabled)
                    {
                        closing = true;
                    }
                    break;
                default:
                    return false;
            }
            return true;
        }
Esempio n. 2
0
        protected virtual bool Process(Event e)
        {
            switch (e.GetTypeId())
            {
                case (int)LinkEventType.HandshakeReq:
                    {
                        var req = (HandshakeReq)e;
                        var resp = new HandshakeResp { _Transform = false };
                        byte[] response = null;
                        try
                        {
                            response = BufferTransform.Handshake(req.Data);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("{0} {1} error handshaking : {2}",
                                link.Name, Handle, ex.ToString());
                        }
                        if (response != null)
                        {
                            resp.Data = response;
                        }
                        Send(resp);
                    }
                    break;
                case (int)LinkEventType.HandshakeResp:
                    {
                        var ack = new HandshakeAck { _Transform = false };
                        var resp = (HandshakeResp)e;
                        try
                        {
                            if (BufferTransform.FinalizeHandshake(resp.Data))
                            {
                                rxTransformReady = true;
                                ack.Result = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error("{0} {1} error finishing handshake : {2}",
                                link.Name, Handle, ex.ToString());
                        }
                        Send(ack);
                    }
                    break;
                case (int)LinkEventType.HandshakeAck:
                    {
                        var ack = (HandshakeAck)e;
                        bool result = ack.Result;

                        if (result)
                        {
                            txTransformReady = true;
                        }

                        Link.NotifySessionConnected(result, (result ? this : null));
                    }
                    break;
                default:
                    return false;
            }
            return true;
        }