CSharpRTMP.Core.NetIO.TCPCarrier.SignalOutputData C# (CSharp) Method

SignalOutputData() public method

public SignalOutputData ( MemoryStream s = null ) : bool
s System.IO.MemoryStream
return bool
        public override bool SignalOutputData(MemoryStream s = null)
        {
            //if (!WriteEnabled)
            //{
            //    WriteEnabled = true;
            //}
            WriteEnabled = true;
            if (s == null) s = Protocol.OutputBuffer;
            var needToSend = s.Length;
            var buffer = s.GetBuffer();
            while (Socket.Connected && needToSend > 0)
            {
                try
                {
                    var sendCount = Socket.Send(buffer,
                                (int)s.Position,
                                (int)needToSend, SocketFlags.None);
                    if (sendCount <= 0)
                    {
                        throw new Exception("sendCount<=0");
                    }
                    Tx += sendCount;
                    needToSend -= sendCount;
                    s.Position += sendCount;
                }
                catch (Exception ex)
                {
                    Logger.FATAL("Unable to send data.{0}:{1} -> {2}:{3}", FarIP, FarPort, NearIP,
                            NearPort);
                    IOHandlerManager.EnqueueForDelete(this);
                    return false;
                }
            }
            s.SetLength(0);
            WriteEnabled = false;
            return true;
        }