Exemplo n.º 1
0
        public bool TryReceive(ref Frame frame)
        {            
            if (m_handshake.State != HandshakeStateMachine.HandshakeState.Ready)
                return false;

            return m_receiveStateMachine.TryReceive(ref frame);
        }     
Exemplo n.º 2
0
        protected override bool TryReceiveInternal(ref Frame frame)
        {
            if (m_endpoint == null)
                return false;

            return m_endpoint.TryReceive(ref frame);
        }
Exemplo n.º 3
0
        public bool TrySend(ref Frame frame)
        {         
            if (m_handshake.State != HandshakeStateMachine.HandshakeState.Ready)
                return false;

            return m_sendStateMachine.TrySend(ref frame);                    
        }
Exemplo n.º 4
0
        public static void Send(this Socket socket, string text)
        {
            Frame frame = new Frame();
            frame.Init(Encoding.UTF8.GetBytes(text));

            socket.TrySend(ref frame, Timeout.InfiniteTimeSpan);

            frame.Close();
        }
Exemplo n.º 5
0
        public static string ReceiveString(this Socket socket)
        {
            Frame frame = new Frame();

            socket.TryReceive(ref frame, Timeout.InfiniteTimeSpan);

            var text =  Encoding.UTF8.GetString(frame.Data, 0, frame.Size);

            frame.Close();

            return text;
        }
Exemplo n.º 6
0
        public bool TrySend(ref Frame frame, TimeSpan timeout)
        {
            m_context.Enter();

            try
            {
                bool isMessageSent = TrySendInternal(ref frame);

                if (isMessageSent)
                    return true;

                Stopwatch stopwatch = Stopwatch.StartNew();

                bool infinite = timeout == Timeout.InfiniteTimeSpan;

                while (infinite || stopwatch.Elapsed < timeout)
                {
                    TimeSpan actualTimeout = timeout - stopwatch.Elapsed;

                    if (actualTimeout.Ticks < 0)
                        actualTimeout = TimeSpan.Zero;

                    bool signalled;

                    if (infinite)
                    {
                        m_context.Wait();
                        signalled = true;
                    }
                    else
                        signalled = m_context.Wait(actualTimeout);

                    if (signalled)
                    {
                        isMessageSent = TrySendInternal(ref frame);

                        if (isMessageSent)
                            return true;
                    }
                }

                return false;
            }
            finally
            {
                m_context.Exit();
            }
        }
Exemplo n.º 7
0
 protected abstract bool TryReceiveInternal(ref Frame frame);
Exemplo n.º 8
0
 protected abstract bool TrySendInternal(ref Frame frame);