Skip to content

Commit

Permalink
Merge pull request #19 from aaiyer/main
Browse files Browse the repository at this point in the history
Expose reset(), logon() for Session
  • Loading branch information
arthurlm authored Dec 22, 2024
2 parents 1e3a300 + c3cc33a commit a916b11
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
16 changes: 16 additions & 0 deletions quickfix-ffi/quickfix-bind/src/quickfix_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions quickfix-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
17 changes: 14 additions & 3 deletions quickfix/src/session.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -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) })
}
Expand All @@ -58,6 +58,17 @@ impl Session<'_> {
pub fn send(&mut self, msg: Message) -> Result<bool, QuickFixError> {
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<'_> {
Expand Down

0 comments on commit a916b11

Please sign in to comment.