diff --git a/quickfix-ffi/quickfix-bind/src/quickfix_bind.cpp b/quickfix-ffi/quickfix-bind/src/quickfix_bind.cpp index 2e03751..8232d2f 100644 --- a/quickfix-ffi/quickfix-bind/src/quickfix_bind.cpp +++ b/quickfix-ffi/quickfix-bind/src/quickfix_bind.cpp @@ -1024,5 +1024,21 @@ int8_t FixSession_send(FixSession_t *session, FixMessage_t *msg) { CATCH_OR_RETURN_ERRNO({ return session->send(*msg); }); } +int8_t FixSession_reset(FixSession_t *session) { + RETURN_VAL_IF_NULL(session, ERRNO_INVAL); + CATCH_OR_RETURN_ERRNO({ + session->reset(); + return 0; + }); +} + +int8_t FixSession_logon(FixSession_t *session) { + RETURN_VAL_IF_NULL(session, ERRNO_INVAL); + CATCH_OR_RETURN_ERRNO({ + session->logon(); + return 0; + }); +} + } // namespace FIX } // extern C diff --git a/quickfix-ffi/src/lib.rs b/quickfix-ffi/src/lib.rs index 8eebb3b..480bac2 100644 --- a/quickfix-ffi/src/lib.rs +++ b/quickfix-ffi/src/lib.rs @@ -458,4 +458,8 @@ extern "C" { pub fn FixSession_isLoggedOn(session: FixSession_t) -> i8; #[must_use] pub fn FixSession_send(session: FixSession_t, msg: FixMessage_t) -> i8; + #[must_use] + pub fn FixSession_reset(session: FixSession_t) -> i8; + #[must_use] + pub fn FixSession_logon(session: FixSession_t) -> i8; } diff --git a/quickfix/src/session.rs b/quickfix/src/session.rs index 822b637..ef8d4c1 100644 --- a/quickfix/src/session.rs +++ b/quickfix/src/session.rs @@ -1,8 +1,8 @@ use std::{fmt, marker::PhantomData}; use quickfix_ffi::{ - FixSession_isLoggedOn, FixSession_logout, FixSession_lookup, FixSession_send, - FixSession_sendToTarget, FixSession_t, + FixSession_isLoggedOn, FixSession_logout, FixSession_lookup, FixSession_send, FixSession_reset, + FixSession_logon, FixSession_sendToTarget, FixSession_t, }; use crate::{ @@ -44,7 +44,7 @@ impl Session<'static> { } impl Session<'_> { - /// Force session logout. + /// Force session logout, and disable session. pub fn logout(&mut self) -> Result<(), QuickFixError> { ffi_code_to_result(unsafe { FixSession_logout(self.inner) }) } @@ -58,6 +58,17 @@ impl Session<'_> { pub fn send(&mut self, msg: Message) -> Result { ffi_code_to_bool(unsafe { FixSession_send(self.inner, msg.0) }) } + + /// Reset session by sending a logout & disconnecting, but still keeping the session enabled, + /// so that logon is retried. + pub fn reset(&mut self) -> Result<(), QuickFixError> { + ffi_code_to_result(unsafe { FixSession_reset(self.inner) }) + } + + /// Enable session so that logon is sent. + pub fn logon(&mut self) -> Result<(), QuickFixError> { + ffi_code_to_result(unsafe { FixSession_logon(self.inner) }) + } } impl fmt::Debug for Session<'_> {