23#include <catch2/catch_amalgamated.hpp>
37 if (!in.
read(connection)) {
44 if (writer !=
nullptr) {
52bool waitConnection(
const std::string& src,
const std::string& dest,
bool connected)
54 for (
int i = 0; i < 50; ++i) {
55 if (Network::isConnected(src, dest,
"shmem",
true) == connected) {
68 + std::to_string(
rpc.getPort()) +
" " + std::to_string(stream.
getPort());
71 cmd =
"\"" + cmd +
"\"";
73 return std::async(std::launch::async, [cmd]() {
74 int ret = std::system(cmd.c_str());
90 Network::setLocalMode(
true);
103 for (
int i = 0; i < 100; ++i) {
125 SECTION(
"test increasing message size (shared memory resize)")
138 for (
size_t len : {10, 1000, 4000, 5000, 20000, 100000, 1000000}) {
140 for (
size_t j = 0; j < len; ++j) {
141 payload[j] =
static_cast<char>(
'a' + (j % 26));
172 SECTION(
"test disconnect and reconnect")
181 for (
int k = 0;
k < 3; ++
k) {
204 Network::setLocalMode(
false);
211 Network::setLocalMode(
true);
223 for (
int i = 0; i < 20; ++i) {
227 cmd.
addString(std::string(
static_cast<size_t>(i) * 1000,
'x'));
238 Network::setLocalMode(
false);
251 Network::setLocalMode(
true);
253 SECTION(
"rpc and streaming with another process")
272 while (received < 200 &&
Time::now() - start < 60.0) {
275 if (peer.wait_for(std::chrono::seconds(0)) == std::future_status::ready && in.
getPendingReads() == 0) {
288 CHECK(peer.get() == 0);
289 CHECK(received == 200);
291 CHECK(bytes == 196 * 100 + 4 * 500000);
297 SECTION(
"the other process crashes")
308 CHECK(peer.get() == 0);
313 for (
int i = 0; i < 100 && !
removed; ++i) {
322 Network::setLocalMode(
false);
A simple collection of objects that can be described and transmitted in a portable way.
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
A mini-server for performing network communication in the background.
Contact where() const override
Returns information about how this port can be reached.
std::string getName() const override
Get name of port.
void writeStrict()
Write the current object being returned by BufferedPort::prepare, waiting until any previous sends ar...
void close() override
Stop port activity.
void setReader(PortReader &reader) override
Set an external reader for port data.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
int getPendingReads() override
Get the number of objects ready to be read.
void interrupt() override
Interrupt any current reads or writes attached to the port.
int getInputCount() override
Determine how many connections are arriving into this port.
T * read(bool shouldWait=true) override
Read an available object from the port.
void setStrict(bool strict=true) override
Call this to strictly keep all messages, or allow old ones to be quietly dropped.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
An interface for reading from a network connection.
virtual ConnectionWriter * getWriter()=0
Gets a way to reply to the message, if possible.
An interface for writing to a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
virtual bool read(ConnectionReader &reader)=0
Read this object from a network connection.
A mini-server for network communication.
bool write(const PortWriter &writer, const PortWriter *callback=nullptr) const override
Write an object to the port.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual std::string asString() const
Get string value.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
void delay(double seconds)
Wait for a certain number of seconds.
An interface to the operating system, including Port based communication.
TEST_CASE("carriers::shmem", "[carriers]")