예제 #1
0
        public bool TryReceive(ref Frame frame)
        {            
            if (m_handshake.State != HandshakeStateMachine.HandshakeState.Ready)
                return false;

            return m_receiveStateMachine.TryReceive(ref frame);
        }     
예제 #2
0
파일: Dealer.cs 프로젝트: fabsenet/ZMTP.NET
        protected override bool TryReceiveInternal(ref Frame frame)
        {
            if (m_endpoint == null)
                return false;

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

            return m_sendStateMachine.TrySend(ref frame);                    
        }
예제 #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();
        }
예제 #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;
        }
예제 #6
0
파일: Socket.cs 프로젝트: fabsenet/ZMTP.NET
        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();
            }
        }
예제 #7
0
파일: Socket.cs 프로젝트: fabsenet/ZMTP.NET
 protected abstract bool TryReceiveInternal(ref Frame frame);
예제 #8
0
파일: Socket.cs 프로젝트: fabsenet/ZMTP.NET
 protected abstract bool TrySendInternal(ref Frame frame);