public static void Send(this IThreadSafeOutSocket socket, byte[] data, int length)
        {
            var msg = new Msg();

            msg.InitPool(length);
            data.Slice(0, length).CopyTo(msg);
            socket.Send(ref msg);
            msg.Close();
        }
        public static ValueTask SendAsync(this IThreadSafeOutSocket socket, string message)
        {
            if (socket.TrySend(message))
            {
                return(new ValueTask());
            }

            return(new ValueTask(Task.Factory.StartNew(() => Send(socket, message), TaskCreationOptions.LongRunning)));
        }
        public static ValueTask SendAsync(this IThreadSafeOutSocket socket, byte[] data, int length)
        {
            if (socket.TrySend(data, length))
            {
                return(new ValueTask());
            }

            return(new ValueTask(Task.Factory.StartNew(() => Send(socket, data, length), TaskCreationOptions.LongRunning)));
        }
        public static bool TrySend(this IThreadSafeOutSocket socket, TimeSpan timeout, byte[] data, int length)
        {
            var msg = new Msg();

            msg.InitPool(length);
            data.CopyTo(msg);
            if (!socket.TrySend(ref msg, timeout))
            {
                msg.Close();
                return(false);
            }

            msg.Close();
            return(true);
        }
        public static void Send(this IThreadSafeOutSocket socket, string message)
        {
            var msg = new Msg();

            // Count the number of bytes required to encode the string.
            // Note that non-ASCII strings may not have an equal number of characters
            // and bytes. The encoding must be queried for this answer.
            // With this number, request a buffer from the pool.
            msg.InitPool(SendReceiveConstants.DefaultEncoding.GetByteCount(message));

            // Encode the string into the buffer
            SendReceiveConstants.DefaultEncoding.GetBytes(message, msg);

            socket.Send(ref msg);
            msg.Close();
        }
 public static bool TrySend(this IThreadSafeOutSocket socket, byte[] data)
 {
     return(TrySend(socket, TimeSpan.Zero, data));
 }
 public static bool TrySend(this IThreadSafeOutSocket socket, TimeSpan timeout, byte[] data)
 {
     return(TrySend(socket, timeout, data, data.Length));
 }
 public static bool TrySend(this IThreadSafeOutSocket socket, string message)
 {
     return(TrySend(socket, TimeSpan.Zero, message));
 }
 public static void Send(this IThreadSafeOutSocket socket, byte[] data)
 {
     Send(socket, data, data.Length);
 }