Ejemplo n.º 1
0
        public bool Write(ArraySegment <byte> data, Action continuation)
        {
            state.BeginWrite(data.Count > 0);

            if (data.Count == 0)
            {
                return(false);
            }

            if (this.continuation != null)
            {
                throw new InvalidOperationException("Write was pending.");
            }

            if (buffer == null)
            {
                buffer = new OutputBuffer();
            }

            var bufferSize = buffer.Size;

            // XXX copy! could optimize here?
            buffer.Add(data);
            Debug.WriteLine("KayakSocket: added " + data.Count + " bytes to buffer, buffer size was " + bufferSize + ", buffer size is " + buffer.Size);

            if (bufferSize > 0)
            {
                // we're between an async beginsend and endsend,
                // and user did not provide continuation

                if (continuation != null)
                {
                    this.continuation = continuation;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                var result = BeginSend();

                // tricky: potentially throwing away fact that send will complete async
                if (continuation == null)
                {
                    result = false;
                }

                if (result)
                {
                    this.continuation = continuation;
                }

                return(result);
            }
        }
Ejemplo n.º 2
0
        public bool Write(ArraySegment<byte> data, Action continuation)
        {
            state.BeginWrite(data.Count > 0);

            if (data.Count == 0) return false;

            if (this.continuation != null)
                throw new InvalidOperationException("Write was pending.");

            if (buffer == null)
                buffer = new OutputBuffer();

            var bufferSize = buffer.Size;

            // XXX copy! could optimize here?
            buffer.Add(data);
            Debug.WriteLine("KayakSocket: added " + data.Count + " bytes to buffer, buffer size was " + bufferSize + ", buffer size is " + buffer.Size);

            if (bufferSize > 0)
            {
                // we're between an async beginsend and endsend,
                // and user did not provide continuation

                if (continuation != null)
                {
                    this.continuation = continuation;
                    return true;
                }
                else
                    return false;
            }
            else
            {
                var result = BeginSend();

                // tricky: potentially throwing away fact that send will complete async
                if (continuation == null)
                    result = false;

                if (result)
                    this.continuation = continuation;

                return result;
            }
        }
Ejemplo n.º 3
0
        public bool Write(ArraySegment<byte> data, Action continuation)
        {
            state.EnsureCanWrite();

            if (this.continuation != null)
                throw new InvalidOperationException("Write was pending.");

            if (data.Count == 0) return false;

            this.continuation = continuation;

            if (buffer == null)
                buffer = new OutputBuffer();

            var size = buffer.Size;

            // XXX copy! could optimize here?
            buffer.Add(data);

            if (size > 0)
            {
                if (this.continuation != null)
                    return true;
                else
                    return false;
            }
            else
            {
                var result = BeginSend();

                if (this.continuation == null)
                    result = false;
                else if (!result)
                {
                    this.continuation = null;
                }

                return result;
            }
        }