internal static bool TrySendMessage(IMalockSocket socket, Stream message) { if (socket == null || message == null) { return(false); } MemoryStream ms = (MemoryStream)message; return(socket.Send(ms.GetBuffer(), 0, Convert.ToInt32(ms.Position))); }
public virtual bool Send(byte[] buffer, int ofs, int len) { IMalockSocket socket = null; lock (this.syncobj) { socket = this.preferred; } if (socket == null) { return(false); } return(socket.Send(buffer, ofs, len)); }
internal static bool TrySendMessage(IMalockSocket socket, MalockMessage message, byte[] buffer, int ofs, int len) { if (socket == null || message == null) { return(false); } using (MemoryStream ms = (MemoryStream)message.Serialize()) { if (buffer != null) { ms.Write(buffer, ofs, len); } return(socket.Send(ms.GetBuffer(), 0, Convert.ToInt32(ms.Position))); } }
internal static bool TrySendMessage(IMalockSocket malock, MalockMessage message, ref Exception exception) { if (malock == null) { throw new ArgumentNullException("malock"); } if (message == null) { throw new ArgumentNullException("message"); } using (MemoryStream ms = (MemoryStream)message.Serialize()) { if (!malock.Send(ms.GetBuffer(), 0, unchecked ((int)ms.Position))) { exception = new InvalidOperationException("The malock send returned results do not match the expected"); return(false); } } return(true); }