Example #1
0
        public void SendUnreliableAsync(object o)
        {
            lock (this.snd_sync)
            {
                if (this.isClosed)
                {
                    return;
                }

                try
                {
                    this.writerUdpMemory.Clear();
                    //conv使用kcp的序列写入,保证与kcp一致
                    var span = this.writerUdpMemory.GetWritableSpan(4);
                    this.kcpOperators.WriteUInt32(span, this.Conv);
                    writerUdpMemory.WriterAdvance(4);

                    var writer = new WrappedWriter(this.writerUdpMemory, this.Order, this.writerFlushDelegate);
                    this.Pipeline.OnTransportWrite(this, ref writer, o);
                    writer.Flush();
                }
                catch (Exception e)
                {
                    this.DeliverException(e);
                }
            }
        }
Example #2
0
        public void Write(EndPoint remoteAddress, object o)
        {
            lock (this.sync)
            {
                this.SndAddress = remoteAddress;
                var segment = this.SndPipeWriter.GetSegment();
                segment.Token = remoteAddress;
                try
                {
                    var writer = new WrappedWriter(segment, this.Order, this.writerFlushCallback);
                    this.filterPipeline.OnTransportWrite(this, ref writer, o);
                    writer.Flush();
                }
                catch (Exception e)
                {
                    this.DeliverException(e);

                    this.SndPipeWriter.Complete();
                }
            }
        }
Example #3
0
        public void SendReliableAsync(object o)
        {
            lock (this.snd_sync)
            {
                if (this.isClosed)
                {
                    return;
                }

                try
                {
                    var memory = this.sndPool.Pop();
                    var writer = new WrappedWriter(memory, this.Order, this.writerFlushDelegate);
                    this.Pipeline.OnTransportWrite(this, ref writer, o);
                    writer.Flush();
                }
                catch (Exception e)
                {
                    this.DeliverException(e);
                }
            }
        }
Example #4
0
        public override void Write(object o)
        {
            lock (sync)
            {
                if (this.isDisposed)
                {
                    return;
                }

                WrappedWriter writer = new WrappedWriter(this.Output, this.Order, this.writerFlushCallback);
                try
                {
                    this.filterPipeline.OnTransportWrite(this, ref writer, o);
                }
                catch (Exception e)
                {
                    this.DeliverException(e);
                }
                finally
                {
                    writer.Flush();
                }
            }
        }