public static ValueTask SendAsync(this IRoutingIdSocket socket, uint routingId, string message) { if (socket.TrySend(routingId, message)) { return(new ValueTask()); } return(new ValueTask(Task.Factory.StartNew(() => Send(socket, routingId, message), TaskCreationOptions.LongRunning))); }
public static ValueTask SendAsync(this IRoutingIdSocket socket, uint routingId, byte[] data, int length) { if (socket.TrySend(routingId, data, length)) { return(new ValueTask()); } return(new ValueTask(Task.Factory.StartNew(() => Send(socket, routingId, data, length), TaskCreationOptions.LongRunning))); }
public static bool TrySend(this IRoutingIdSocket socket, TimeSpan timeout, uint routingId, byte[] data, int length) { var msg = new Msg(); msg.InitPool(length); msg.RoutingId = routingId; data.CopyTo(msg); if (!socket.TrySend(ref msg, timeout)) { msg.Close(); return(false); } msg.Close(); return(true); }
public static bool TrySend(this IRoutingIdSocket socket, TimeSpan timeout, uint routingId, 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)); msg.RoutingId = routingId; // Encode the string into the buffer SendReceiveConstants.DefaultEncoding.GetBytes(message, msg); if (!socket.TrySend(ref msg, timeout)) { msg.Close(); return(false); } msg.Close(); return(true); }