Skip to content

Commit

Permalink
Set linger time to 0 to properly close the sockets during termination…
Browse files Browse the repository at this point in the history
… of the FMU.

Signed-off-by: ClemensLinnhoff <clemens.linnhoff@partner.bmw.de>
  • Loading branch information
ClemensLinnhoff committed Jan 17, 2024
1 parent ec5e847 commit 2f2216e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/OSMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ fmi2Status OSMP::DoExitInitializationMode()
{

string address = "tcp://" + FmiIp() + ":" + FmiPort();
std::cout << address << std::endl;
const char* protocol = address.c_str();

if (FmiSender() != 0)
Expand All @@ -173,6 +172,8 @@ fmi2Status OSMP::DoExitInitializationMode()
const int wait_time_ms = FmiWaitTime() * 1000;
zmq_setsockopt(socket_, ZMQ_SNDTIMEO, &wait_time_ms, sizeof(wait_time_ms));
}
const int linger = 0;
zmq_setsockopt(socket_, ZMQ_LINGER, &linger, sizeof (linger));
socket_.bind(protocol);
}
else
Expand All @@ -190,6 +191,8 @@ fmi2Status OSMP::DoExitInitializationMode()
const int wait_time_ms = FmiWaitTime() * 1000;
zmq_setsockopt(socket_, ZMQ_RCVTIMEO, &wait_time_ms, sizeof(wait_time_ms));
}
const int linger = 0;
zmq_setsockopt(socket_, ZMQ_LINGER, &linger, sizeof (linger));
socket_.connect(protocol);
}

Expand Down Expand Up @@ -263,6 +266,12 @@ fmi2Status OSMP::DoCalc(fmi2Real current_communication_point, fmi2Real communica

fmi2Status OSMP::DoTerm()
{
string address = "tcp://" + FmiIp() + ":" + FmiPort();
const char* protocol = address.c_str();
socket_.unbind(protocol);
socket_.close();
context_.shutdown();
context_.close();
return fmi2OK;
}

Expand Down
2 changes: 1 addition & 1 deletion src/OSMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class OSMP
static fmi2Status DoEnterInitializationMode();
fmi2Status DoExitInitializationMode();
fmi2Status DoCalc(fmi2Real current_communication_point, fmi2Real communication_step_size, fmi2Boolean no_set_fmu_state_prior_to_current_pointfmi_2_component);
static fmi2Status DoTerm();
fmi2Status DoTerm();
void DoFree();
void ProcessMessage(zmq::message_t& message);

Expand Down

0 comments on commit 2f2216e

Please sign in to comment.