Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/impl/LogForwarder: Do not use a static Bottle #2667

Draft
wants to merge 1 commit into
base: yarp-3.5
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/release/yarp_3_5/LogForwarder_static_Bottle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LogForwarder_static_Bottle {#yarp-3.5}
--------------------------

### Libraries

#### `os`

* The `LogForwarder` no longer skips messages when messages are sent too
quickly (#2643).
9 changes: 3 additions & 6 deletions src/libYARP_os/src/yarp/os/impl/LogForwarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ yarp::os::impl::LogForwarder::LogForwarder()
if (!outputPort.open(logPortName)) {
printf("LogForwarder error while opening port %s\n", logPortName.c_str());
}
outputPort.enableBackgroundWrite(true);
outputPort.addOutput("/yarplogger", "fast_tcp");

started = true;
Expand All @@ -46,12 +45,12 @@ yarp::os::impl::LogForwarder::LogForwarder()
void yarp::os::impl::LogForwarder::forward(const std::string& message)
{
mutex.lock();
static Bottle b;
Bottle& b = outputPort.prepare();
b.clear();
std::string port = "[" + outputPort.getName() + "]";
b.addString(port);
b.addString(message);
outputPort.write(b);
outputPort.writeStrict();
mutex.unlock();
}

Expand All @@ -68,9 +67,7 @@ void yarp::os::impl::LogForwarder::shutdown()

yarp::os::impl::LogForwarder& fw = getInstance();
fw.forward(ost.str());
while (fw.outputPort.isWriting()) {
yarp::os::SystemClock::delaySystem(0.2);
}
fw.outputPort.waitForWrite();
fw.outputPort.interrupt();
fw.outputPort.close();
}
Expand Down
5 changes: 3 additions & 2 deletions src/libYARP_os/src/yarp/os/impl/LogForwarder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include <yarp/os/api.h>

#include <yarp/os/Port.h>
#include <yarp/os/Bottle.h>
#include <yarp/os/BufferedPort.h>

#include <mutex>
#include <string>
Expand All @@ -32,7 +33,7 @@ class YARP_os_impl_API LogForwarder
LogForwarder& operator=(LogForwarder const&) = delete;

std::mutex mutex;
yarp::os::Port outputPort;
yarp::os::BufferedPort<yarp::os::Bottle> outputPort;
static bool started;
};

Expand Down