Exemplo n.º 1
0
        protected void InternalSend(ISocketSession session, IProtoHandler protoHandler, ArraySegment<byte> segment)
        {
            if (!session.CanSend() || (protoHandler != null && !protoHandler.CanSend()))
                return;

            if (InternalTrySend(session, protoHandler, segment))
                return;

            var sendTimeOut = m_SendTimeOut;

            //Don't retry, timeout directly
            if (sendTimeOut < 0)
            {
                throw new TimeoutException("The sending attempt timed out");
            }

            var timeOutTime = sendTimeOut > 0 ? DateTime.Now.AddMilliseconds(sendTimeOut) : DateTime.Now;

            var spinWait = new SpinWait();

            while (session.CanSend())
            {
                spinWait.SpinOnce();

                if (InternalTrySend(session, protoHandler, segment))
                    return;

                //If sendTimeOut = 0, don't have timeout check
                if (sendTimeOut > 0 && DateTime.Now >= timeOutTime)
                {
                    throw new TimeoutException("The sending attempt timed out");
                }
            }
        }
Exemplo n.º 2
0
        public virtual bool TrySend(ISocketSession session, IProtoHandler protoHandler, ArraySegment <byte> data)
        {
            if (!session.CanSend() || (protoHandler != null && !protoHandler.CanSend()))
            {
                return(false);
            }

            return(InternalTrySend(session, protoHandler, data));
        }
Exemplo n.º 3
0
        protected void InternalSend(ISocketSession session, IProtoHandler protoHandler, ArraySegment <byte> segment)
        {
            if (!session.CanSend() || (protoHandler != null && !protoHandler.CanSend()))
            {
                return;
            }

            if (InternalTrySend(session, protoHandler, segment))
            {
                return;
            }

            var sendTimeOut = m_SendTimeOut;

            //Don't retry, timeout directly
            if (sendTimeOut < 0)
            {
                throw new TimeoutException("The sending attempt timed out");
            }

            var timeOutTime = sendTimeOut > 0 ? DateTime.Now.AddMilliseconds(sendTimeOut) : DateTime.Now;

            var spinWait = new SpinWait();

            while (session.CanSend())
            {
                spinWait.SpinOnce();

                if (InternalTrySend(session, protoHandler, segment))
                {
                    return;
                }

                //If sendTimeOut = 0, don't have timeout check
                if (sendTimeOut > 0 && DateTime.Now >= timeOutTime)
                {
                    throw new TimeoutException("The sending attempt timed out");
                }
            }
        }
Exemplo n.º 4
0
        public virtual bool TrySend(ISocketSession session, IProtoHandler protoHandler, ArraySegment<byte> data)
        {
            if (!session.CanSend() || (protoHandler != null && !protoHandler.CanSend()))
                return false;

            return InternalTrySend(session, protoHandler, data);
        }