// Throws ObjectDisposedExpection if the connection has been disposed of. Returns null if not // connected or if send fails. Otherwise returns sequence number of the sent message. // // Can be called concurrently -- all calls are serialized internally. public DurableSeqNum Send(Mantle.Fix44.IMessage msg) { lock (_sendMonitor) { Session session = TryGetSession(null); if (session == null) { _log.Warn("Unable to publish a messge: not connected."); return(null); } try { return(new DurableSeqNum { SessionID = session.ID, SeqNum = session.Send(msg) }); } catch (Exception e) { if (!_cancellation.IsCancellationRequested) { _log.Error(e, "Failed to publish a message."); } } finally { session.DecRef(); } Invalidate(session); return(null); } }
public long Send(Mantle.Fix44.IMessage msg) { msg.Header.MsgSeqNum.Value = ++_lastSeqNum; using (var buf = new MemoryStream(1 << 10)) { Mantle.Publisher.Publish(buf, Mantle.Fix44.Protocol.Value, msg); byte[] bytes = buf.ToArray(); _strm.Write(bytes, 0, bytes.Length); _strm.Flush(); } return(_lastSeqNum); }
// Requires: ref count is not zero for the whole duration of Send(). // Concurrent calls are not allowed. public long Send(Mantle.Fix44.IMessage msg) { return(_connection.Send(msg)); }