1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

introduce new macro for format buffer length

This commit is contained in:
Steffen Vogel 2022-11-07 10:13:05 -05:00
parent 8e09bbb3ad
commit 576a63be9c
6 changed files with 20 additions and 14 deletions

View file

@ -14,9 +14,10 @@
#include <villas/config.hpp>
/** Default number of values in a sample */
#define DEFAULT_SAMPLE_LENGTH 64u
#define DEFAULT_QUEUE_LENGTH 1024u
#define MAX_SAMPLE_LENGTH 256u
#define DEFAULT_SAMPLE_LENGTH 64u
#define DEFAULT_QUEUE_LENGTH 1024u
#define MAX_SAMPLE_LENGTH 512u
#define DEFAULT_FORMAT_BUFFER_LENGTH 4096u
/** Number of hugepages which are requested from the the kernel.
* @see https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt */

View file

@ -11,6 +11,7 @@
#include <fcntl.h>
#include <cctype>
#include <villas/node/config.hpp>
#include <villas/format.hpp>
#include <villas/utils.hpp>
#include <villas/sample.hpp>
@ -62,7 +63,7 @@ Format::Format(int fl) :
signals(nullptr)
{
in.buflen =
out.buflen = 4096;
out.buflen = DEFAULT_FORMAT_BUFFER_LENGTH;
in.buffer = new char[in.buflen];
out.buffer = new char[out.buflen];

View file

@ -26,6 +26,7 @@ protected:
std::string output_path;
FILE *output;
std::vector<char> output_buffer;
public:
PrintHook(Path *p, Node *n, int fl, int prio, bool en = true) :
@ -44,6 +45,8 @@ public:
if (!output)
throw SystemError("Failed to open file");
}
else
output_buffer = std::vector<char>(DEFAULT_FORMAT_BUFFER_LENGTH);
formatter->start(signals);
@ -107,10 +110,11 @@ public:
assert(state == State::STARTED);
if (!output) {
char buf[1024];
char *buf = output_buffer.data();
size_t buflen = output_buffer.size();
size_t wbytes;
formatter->sprint(buf, sizeof(buf), &wbytes, smp);
formatter->sprint(buf, buflen, &wbytes, smp);
if (wbytes > 0 && buf[wbytes-1] == '\n')
buf[wbytes-1] = 0;

View file

@ -200,14 +200,14 @@ std::vector<int> GoNode::getNetemFDs()
int GoNode::_read(struct Sample * smps[], unsigned cnt)
{
int ret;
char buf[4096];
char data[DEFAULT_FORMAT_BUFFER_LENGTH];
size_t rbytes;
auto d = GoNodeRead(node, buf, 4096);
auto d = GoNodeRead(node, data, sizeof(data));
if (d.r1)
return d.r1;
ret = formatter->sscan(buf, d.r0, &rbytes, smps, cnt);
ret = formatter->sscan(data, d.r0, &rbytes, smps, cnt);
if (ret < 0 || (size_t) d.r0 != rbytes) {
logger->warn("Received invalid packet: ret={}, bytes={}, rbytes={}", ret, d.r0, rbytes);
return ret;
@ -219,17 +219,17 @@ int GoNode::_read(struct Sample * smps[], unsigned cnt)
int GoNode::_write(struct Sample * smps[], unsigned cnt)
{
int ret;
char buf[4096];
char buf[DEFAULT_FORMAT_BUFFER_LENGTH];
size_t wbytes;
ret = formatter->sprint(buf, 4096, &wbytes, smps, cnt);
ret = formatter->sprint(buf, DEFAULT_FORMAT_BUFFER_LENGTH, &wbytes, smps, cnt);
if (ret < 0)
return ret;
GoSlice slice = {
data: buf,
len: GoInt(wbytes),
cap: 4096
cap: DEFAULT_FORMAT_BUFFER_LENGTH
};
ret = GoNodeWrite(node, slice);

View file

@ -541,7 +541,7 @@ int villas::node::kafka_write(NodeCompat *n, struct Sample * const smps[], unsig
size_t wbytes;
char data[4096];
char data[DEFAULT_FORMAT_BUFFER_LENGTH];
ret = k->formatter->sprint(data, sizeof(data), &wbytes, smps, cnt);
if (ret < 0)

View file

@ -551,7 +551,7 @@ int villas::node::zeromq_write(NodeCompat *n, struct Sample * const smps[], unsi
size_t wbytes;
zmq_msg_t m;
char data[4096];
char data[DEFAULT_FORMAT_BUFFER_LENGTH];
ret = z->formatter->sprint(data, sizeof(data), &wbytes, smps, cnt);
if (ret <= 0)