Skip to content

Commit a28d02b

Browse files
committed
Deprecate old code path for sending app messages
1 parent 4b1de75 commit a28d02b

3 files changed

Lines changed: 11 additions & 80 deletions

File tree

crates/hotfix/src/initiator.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ impl<Outbound: OutboundMessage> Initiator<Outbound> {
6868
self.session_handle.send_forget(msg).await
6969
}
7070

71-
#[deprecated(since = "0.7.2", note = "use `send` or `send_forget` instead")]
72-
#[allow(deprecated)]
73-
pub async fn send_message(&self, msg: Outbound) -> Result<()> {
74-
self.session_handle.send_message(msg).await?;
75-
76-
Ok(())
77-
}
78-
7971
pub fn is_interested(&self, sender_comp_id: &str, target_comp_id: &str) -> bool {
8072
self.config.sender_comp_id == sender_comp_id && self.config.target_comp_id == target_comp_id
8173
}

crates/hotfix/src/session.rs

Lines changed: 11 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -802,36 +802,14 @@ where
802802
.reset_peer_timer(self.config.heartbeat_interval, test_request_id);
803803
}
804804

805-
async fn send_app_message(&mut self, message: Outbound) -> Result<()> {
806-
match self.application.on_outbound_message(&message).await {
807-
OutboundDecision::Send => {
808-
self.send_message(message)
809-
.await
810-
.context("failed to send app message")?;
811-
}
812-
OutboundDecision::Drop => {
813-
debug!("dropped outbound message as instructed by the application");
814-
}
815-
OutboundDecision::TerminateSession => {
816-
warn!("the application indicated we should terminate the session");
817-
self.state.disconnect_writer().await;
818-
}
819-
}
820-
821-
Ok(())
822-
}
823-
824-
async fn send_app_message_with_confirmation(
825-
&mut self,
826-
message: Outbound,
827-
) -> Result<SendOutcome, SendError> {
805+
async fn send_app_message(&mut self, message: Outbound) -> Result<SendOutcome, SendError> {
828806
if !self.state.is_connected() {
829807
return Err(SendError::Disconnected);
830808
}
831809

832810
match self.application.on_outbound_message(&message).await {
833811
OutboundDecision::Send => {
834-
let sequence_number = self.send_message_returning_seq(message).await?;
812+
let sequence_number = self.send_message(message).await?;
835813
Ok(SendOutcome::Sent { sequence_number })
836814
}
837815
OutboundDecision::Drop => {
@@ -846,10 +824,7 @@ where
846824
}
847825
}
848826

849-
async fn send_message_returning_seq(
850-
&mut self,
851-
message: impl OutboundMessage,
852-
) -> Result<u64, SendError> {
827+
async fn send_message(&mut self, message: impl OutboundMessage) -> Result<u64, SendError> {
853828
let seq_num = self.store.next_sender_seq_number();
854829
let msg_type = message.message_type().as_bytes().to_vec();
855830
let msg = generate_message(
@@ -881,31 +856,6 @@ where
881856
Ok(seq_num)
882857
}
883858

884-
async fn send_message(&mut self, message: impl OutboundMessage) -> Result<()> {
885-
let seq_num = self.store.next_sender_seq_number();
886-
let msg_type = message.message_type().as_bytes().to_vec();
887-
let msg = generate_message(
888-
&self.config.begin_string,
889-
&self.config.sender_comp_id,
890-
&self.config.target_comp_id,
891-
seq_num,
892-
message,
893-
)
894-
.context("failed to generate message")?;
895-
self.store
896-
.increment_sender_seq_number()
897-
.await
898-
.context("failed to increment sender seq number")?;
899-
900-
self.store
901-
.add(seq_num, &msg)
902-
.await
903-
.context("failed to add message to store")?;
904-
self.send_raw(&msg_type, msg).await;
905-
906-
Ok(())
907-
}
908-
909859
async fn send_raw(&mut self, message_type: &[u8], data: Vec<u8>) {
910860
self.state
911861
.send_message(message_type, RawFixMessage::new(data))
@@ -935,7 +885,8 @@ where
935885

936886
async fn send_resend_request(&mut self, begin: u64, end: u64) -> Result<()> {
937887
let request = ResendRequest::new(begin, end);
938-
self.send_message(request).await
888+
self.send_message(request).await.map(|_| ())?;
889+
Ok(())
939890
}
940891

941892
async fn send_logon(&mut self) -> Result<()> {
@@ -949,12 +900,14 @@ where
949900

950901
let logon = Logon::new(self.config.heartbeat_interval, reset_config);
951902

952-
self.send_message(logon).await
903+
self.send_message(logon).await.map(|_| ())?;
904+
Ok(())
953905
}
954906

955907
async fn send_logout(&mut self, reason: &str) -> Result<()> {
956908
let logout = Logout::with_reason(reason.to_string());
957-
self.send_message(logout).await
909+
self.send_message(logout).await.map(|_| ())?;
910+
Ok(())
958911
}
959912

960913
/// Sends a logout message and immediately disconnects the counterparty.
@@ -1021,14 +974,14 @@ where
1021974

1022975
async fn handle_outbound_message(&mut self, request: OutboundRequest<Outbound>) {
1023976
let OutboundRequest { message, confirm } = request;
977+
let result = self.send_app_message(message).await;
1024978
match confirm {
1025979
Some(tx) => {
1026-
let result = self.send_app_message_with_confirmation(message).await;
1027980
// Ignore send errors - receiver may have been dropped
1028981
let _ = tx.send(result);
1029982
}
1030983
None => {
1031-
if let Err(err) = self.send_app_message(message).await {
984+
if let Err(err) = result {
1032985
error!(err = ?err, "failed to send app message: {err}");
1033986
}
1034987
}

crates/hotfix/src/session/session_handle.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::session::admin_request::AdminRequest;
22
use crate::session::error::{SendError, SendOutcome};
33
use crate::session::session_ref::OutboundRequest;
44
use crate::session::{InternalSessionRef, SessionInfo};
5-
use anyhow::anyhow;
65
use tokio::sync::{mpsc, oneshot};
76

87
/// A public handle to the session that can be used to interact with the session.
@@ -62,19 +61,6 @@ impl<Outbound> SessionHandle<Outbound> {
6261
Ok(())
6362
}
6463

65-
#[deprecated(since = "0.5.0", note = "use `send` or `send_forget` instead")]
66-
pub async fn send_message(&self, msg: Outbound) -> anyhow::Result<()> {
67-
self.outbound_message_sender
68-
.send(OutboundRequest {
69-
message: msg,
70-
confirm: None,
71-
})
72-
.await
73-
.map_err(|_| anyhow!("failed to send message"))?;
74-
75-
Ok(())
76-
}
77-
7864
pub async fn shutdown(&self, reconnect: bool) -> anyhow::Result<()> {
7965
self.admin_request_sender
8066
.send(AdminRequest::InitiateGracefulShutdown { reconnect })

0 commit comments

Comments
 (0)