public void AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state = null)
        {
            var arg = _sendPool.PopFront();

            arg.SetBuffer(data, offset, size);
            arg.SendCallback = callback;
            arg.UserToken    = state;
            arg.Socket       = this;

            if (_socket != null)
            {
                if (!_socket.SendAsync(arg))
                {
                    //The receive was processed synchronously which means the callback wont be executed.
                    OnSendComplete(arg);
                }
            }
            else if (_connection != null)
            {
                if (!_connection.Client.SendAsync(arg))
                {
                    //The receive was processed synchronously which means the callback wont be executed.
                    OnSendComplete(arg);
                }
            }
        }
示例#2
0
        public void AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state = null)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (offset < 0 || size < 0 || size > data.Length - offset)
            {
                throw new ArgumentOutOfRangeException(nameof(data));
            }

            _sendQueue.Enqueue(new SendRequest()
            {
                segment  = new ArraySegment <byte>(data, offset, size),
                callback = callback,
                state    = state
            });

            lock (_sendQueue)
            {
                if (!sending)
                {
                    sending = SendMore();
                }
            }
        }
        void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
        {
            try
            {
                if (this._connection != null && this._connection.Client.Poll(-1, SelectMode.SelectWrite))
                {
                    if (Tools.RuntimePlatform == RuntimePlatform.Mono)
                    {
                        this._connection.GetStream().Write(data, offset, size);
                        if (callback != null)
                        {
                            callback(state);
                        }
                    }
                    else
                    {
                        this._connection.GetStream().BeginWrite(data, 0, size, new AsyncCallback(this.SendCallback), new Tuple <SocketSendCallback, object>(callback, state));
                    }
                }
            }
            catch (ObjectDisposedException)
            {
            }
            catch (Exception e)
            {
//                Tools.WriteLine(e);
                throw e;
            }
        }
示例#4
0
//		void ISocket.SendQueuedPackets()
//		{
//		}

        void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
        {
            byte[] array = LegacyNetBufferPool.RequestBuffer(data, offset, size);
            this._connection.GetStream().BeginWrite(array, 0, size, new AsyncCallback(this.SendCallback), new object[]
            {
                new Tuple <SocketSendCallback, object>(callback, state),
                array
            });
        }
示例#5
0
 void ISocket.AsyncSend(
     byte[] data,
     int offset,
     int size,
     SocketSendCallback callback,
     object state)
 {
     this._connection.GetStream().BeginWrite(data, 0, size, new AsyncCallback(this.SendCallback), (object)new Tuple <SocketSendCallback, object>(callback, state));
 }
示例#6
0
 void ISocket.AsyncSend(
     byte[] data,
     int offset,
     int size,
     SocketSendCallback callback,
     object state)
 {
     SocialAPI.Network.Send(this._remoteAddress, data, size);
     callback.BeginInvoke(state, (AsyncCallback)null, (object)null);
 }
示例#7
0
 public void AsyncSend(byte[] data, int offset, int count, SocketSendCallback callback, object state = null)
 {
     var bytes = new byte[count];
     Array.Copy(data, offset, bytes, 0, count);
     Send(new Message()
     {
         data = bytes,
         callback = callback,
         state = state
     });
 }
示例#8
0
        public void AsyncSend(byte[] data, int offset, int count, SocketSendCallback callback, object state = null)
        {
            var bytes = new byte[count];

            Array.Copy(data, offset, bytes, 0, count);
            Send(new Message()
            {
                data     = bytes,
                callback = callback,
                state    = state
            });
        }
示例#9
0
        void Terraria.Net.Sockets.ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
        {
            if (((ISocket)this).IsConnected() == false)
            {
                return;
            }

            try
            {
                this._connection.GetStream().Write(data, offset, size);
            }
            catch (Exception ex)
            {
                //Write failed
            }
        }
        void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
        {
            #if Full_API
            Main.ignoreErrors = false;
            var bt = new byte[size];
            Buffer.BlockCopy(data, offset, bt, 0, size);
            this.Send(bt);
            bt = null;

            if (callback != null)
            {
                callback(state);
            }

            this.Flush();
            #endif
        }
示例#11
0
 void Terraria.Net.Sockets.ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
 {
     SocialAPI.Network.Send(this._remoteAddress, data, size);
     callback.BeginInvoke(state, null, null);
 }
        void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
        {
            #if Full_API
            Main.ignoreErrors = false;
            var bt = new byte[size];
            Buffer.BlockCopy(data, offset, bt, 0, size);
            this.Send(bt);
            bt = null;

            if (callback != null)
                callback(state);

            this.Flush();
            #endif
        }
示例#13
0
        void Terraria.Net.Sockets.ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
        {
            if (((ISocket)this).IsConnected() == false)
            {
                return;
            }

            try
            {
                this._connection.GetStream().Write(data, offset, size);
            }
            catch (Exception ex)
            {
                //Write failed
            }
        }
示例#14
0
 public void AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state = null)
 {
     _client?.AsyncSend(data, offset, size, callback, state);
 }
        void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
        {
            Main.ignoreErrors = false;
            var bt = new byte[size];
            Buffer.BlockCopy(data, offset, bt, 0, size);
            this.Send(bt);
            //bt = null;

            if (callback != null)
                callback(state);

            DespatchData();
        }
        void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
        {
            #if Full_API
            //            Main.ignoreErrors = false;
            var ctx = new HookContext()
            {
                Connection = this
            };
            var args = new HookArgs.SendClientData()
            {
                Data = data,
                Offset = offset,
                Size = size,
                Callback = callback,
                State = state
            };

            HookPoints.SendClientData.Invoke(ref ctx, ref args);

            if (ctx.Result == HookResult.DEFAULT)
            {
                var bt = new byte[size];
                Buffer.BlockCopy(data, offset, bt, 0, size);
                this.Send(bt);
                bt = null;

                if (callback != null)
                    callback(state);

                this.Flush();
            }
            #endif
        }
示例#17
0
 void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
 {
     this._connection.GetStream().BeginWrite(data, 0, size, new AsyncCallback(this.SendCallback), (object)new Tuple<SocketSendCallback, object>(callback, state));
 }
 void ISocket.AsyncSend(byte[] data, int offset, int size, SocketSendCallback callback, object state)
 {
     try
     {
         if (this._connection != null && this._connection.Client.Poll(-1, SelectMode.SelectWrite))
         {
             if (Tools.RuntimePlatform == RuntimePlatform.Mono)
             {
                 this._connection.GetStream().Write(data, offset, size);
                 if (callback != null)
                     callback(state);
             }
             else
                 this._connection.GetStream().BeginWrite(data, 0, size, new AsyncCallback(this.SendCallback), new Tuple<SocketSendCallback, object>(callback, state));
         }
     }
     catch (ObjectDisposedException)
     {
     }
     catch (Exception e)
     {
     //                Tools.WriteLine(e);
         throw e;
     }
 }