private void SendMessageInternal(FIXTMessage1_1 fixMsg) { var fixString = fixMsg.ToString(); if (debug) { string view = fixString.Replace(FIXTBuffer.EndFieldStr, " "); log.Debug("Send FIX message: \n" + view); } var packet = Socket.CreatePacket(); packet.DataOut.Write(fixString.ToCharArray()); var end = Factory.Parallel.TickCount + (long)heartbeatDelay * 1000L; while (!Socket.TrySendPacket(packet)) { if (IsInterrupted) { return; } if (Factory.Parallel.TickCount > end) { throw new ApplicationException("Timeout while sending heartbeat."); } Factory.Parallel.Yield(); } }
protected void ResendMessageProtected(FIXTMessage1_1 fixMessage) { if (isConnectionLost) { return; } var writePacket = fixSocket.MessageFactory.Create(); var message = fixMessage.ToString(); writePacket.DataOut.Write(message.ToCharArray()); writePacket.SendUtcTime = TimeStamp.UtcNow.Internal; if (debug) { log.Debug("Resending simulated FIX Message: " + fixMessage); } SendMessageInternal(writePacket); }
public void SendMessage(FIXTMessage1_1 fixMessage) { FixFactory.AddHistory(fixMessage); if (isConnectionLost) { RemoveTickSync(fixMessage); return; } var simulator = simulators[SimulatorType.SendDisconnect]; if (simulator.CheckSequence(fixMessage.Sequence)) { if (debug) { log.Debug("Ignoring message: " + fixMessage); } ProviderSimulator.SwitchBrokerState("disconnect", false); isConnectionLost = true; return; } if (simulateSendFailed && IsRecovered && random.Next(50) == 4) { if (debug) { log.Debug("Skipping send of sequence # " + fixMessage.Sequence + " to simulate lost message. " + fixMessage); } if (fixMessage.Type == "1") { isHeartbeatPending = TimeStamp.MaxValue; } if (debug) { log.Debug("Message type is: " + fixMessage.Type); } return; } var writePacket = fixSocket.MessageFactory.Create(); var message = fixMessage.ToString(); writePacket.DataOut.Write(message.ToCharArray()); writePacket.SendUtcTime = TimeStamp.UtcNow.Internal; if (debug) { log.Debug("Simulating FIX Message: " + fixMessage); } try { fixPacketQueue.Enqueue(writePacket, writePacket.SendUtcTime); } catch (QueueException ex) { if (ex.EntryType == EventType.Terminate) { log.Warn("fix packet queue returned queue exception " + ex.EntryType + ". Dropping message due to dispose."); Dispose(); } else { throw; } } simulator = simulators[SimulatorType.SendServerOffline]; if (IsRecovered && FixFactory != null && simulator.CheckSequence(fixMessage.Sequence)) { if (debug) { log.Debug("Skipping message: " + fixMessage); } ProviderSimulator.SwitchBrokerState("offline", false); ProviderSimulator.SetOrderServerOffline(); if (requestSessionStatus) { SendSessionStatus("3"); } else { log.Info("RequestSessionStatus is false so not sending order server offline message."); } } }