mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
socket: save MSG_PEEK recv(2) call by using a fixed allocation.
This should work for most data link layers.
This commit is contained in:
parent
246a4a98fb
commit
465999d608
1 changed files with 5 additions and 12 deletions
|
@ -40,6 +40,8 @@
|
|||
#include "queue.h"
|
||||
#include "plugin.h"
|
||||
|
||||
#define MAX_PACKETLEN 1500
|
||||
|
||||
/* Forward declartions */
|
||||
static struct plugin p;
|
||||
|
||||
|
@ -327,23 +329,14 @@ static int socket_read_none(struct node *n, struct sample *smps[], unsigned cnt)
|
|||
|
||||
static int socket_read_villas(struct node *n, struct sample *smps[], unsigned cnt)
|
||||
{
|
||||
int ret;
|
||||
struct socket *s = n->_vd;
|
||||
|
||||
int ret;
|
||||
char data[MAX_PACKETLEN];
|
||||
ssize_t bytes;
|
||||
|
||||
/* Peak into message header of the first sample and to get total packet size. */
|
||||
bytes = recv(s->sd, NULL, 0, MSG_PEEK | MSG_TRUNC);
|
||||
if (bytes < MSG_LEN(1) || bytes % 4 != 0) {
|
||||
warn("Received invalid packet for node %s", node_name(n));
|
||||
recv(s->sd, NULL, 0, 0); /* empty receive buffer */
|
||||
return -1;
|
||||
}
|
||||
|
||||
char data[bytes];
|
||||
|
||||
/* Receive message from socket */
|
||||
bytes = recv(s->sd, data, bytes, 0);
|
||||
bytes = recv(s->sd, data, sizeof(data), 0);
|
||||
if (bytes == 0)
|
||||
error("Remote node %s closed the connection", node_name(n));
|
||||
else if (bytes < 0)
|
||||
|
|
Loading…
Add table
Reference in a new issue