Revert "Implement recvmmsg"

This reverts commit de5fe64be5.
This commit is contained in:
def 2018-07-29 23:07:59 +02:00
parent 5d8d900643
commit 18529fa082
4 changed files with 9 additions and 90 deletions

View file

@ -1494,80 +1494,29 @@ int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size
#endif /* FUZZING */
}
void net_init_mmsgs(MMSGS* m)
{
#if defined(CONF_PLATFORM_LINUX)
m->pos = 0;
m->size = 0;
mem_zero(m->msgs, sizeof(m->msgs));
mem_zero(m->iovecs, sizeof(m->iovecs));
mem_zero(m->sockaddrs, sizeof(m->sockaddrs));
for(int i = 0; i < VLEN; ++i)
{
m->iovecs[i].iov_base = m->bufs[i];
m->iovecs[i].iov_len = PACKETSIZE;
m->msgs[i].msg_hdr.msg_iov = &m->iovecs[i];
m->msgs[i].msg_hdr.msg_iovlen = 1;
m->msgs[i].msg_hdr.msg_name = &m->sockaddrs[i];
m->msgs[i].msg_hdr.msg_namelen = sizeof(&m->sockaddrs[i]);
}
#endif
}
int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize, MMSGS* m)
int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize)
{
#ifndef FUZZING
char sockaddrbuf[128];
socklen_t fromlen;// = sizeof(sockaddrbuf);
int bytes = 0;
#if defined(CONF_PLATFORM_LINUX)
if(sock.ipv4sock >= 0)
{
if(m->pos >= m->size)
{
m->size = recvmmsg(sock.ipv4sock, m->msgs, VLEN, 0, NULL);
m->pos = 0;
}
}
if(sock.ipv6sock >= 0)
{
if(m->pos >= m->size)
{
m->size = recvmmsg(sock.ipv6sock, m->msgs, VLEN, 0, NULL);
m->pos = 0;
}
}
if(m->pos < m->size)
{
sockaddr_to_netaddr((struct sockaddr *)&(m->sockaddrs[m->pos]), addr);
// TODO: network_stats
//network_stats.recv_bytes += bytes;
//network_stats.recv_packets++;
bytes = m->msgs[m->pos].msg_len;
mem_copy(data, m->bufs[m->pos], bytes);
m->pos++;
return bytes;
}
#else
if(bytes == 0 && sock.ipv4sock >= 0)
{
socklen_t fromlen = sizeof(struct sockaddr_in);
fromlen = sizeof(struct sockaddr_in);
bytes = recvfrom(sock.ipv4sock, (char*)data, maxsize, 0, (struct sockaddr *)&sockaddrbuf, &fromlen);
}
if(bytes <= 0 && sock.ipv6sock >= 0)
{
socklen_t fromlen = sizeof(struct sockaddr_in6);
fromlen = sizeof(struct sockaddr_in6);
bytes = recvfrom(sock.ipv6sock, (char*)data, maxsize, 0, (struct sockaddr *)&sockaddrbuf, &fromlen);
}
#endif
#if defined(CONF_WEBSOCKETS)
if(bytes <= 0 && sock.web_ipv4sock >= 0)
{
socklen_t fromlen = sizeof(struct sockaddr);
fromlen = sizeof(struct sockaddr);
bytes = websocket_recv(sock.web_ipv4sock, data, maxsize, (struct sockaddr_in *)&sockaddrbuf, fromlen);
((struct sockaddr_in *)&sockaddrbuf)->sin_family = AF_WEBSOCKET_INET;
}
@ -1583,7 +1532,7 @@ int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize, MMSGS*
else if(bytes == 0)
return 0;
return -1; /* error */
#else /* ifdef FUZZING */
#else
addr->type = NETTYPE_IPV4;
addr->port = 11111;
addr->ip[0] = 127;

View file

@ -9,11 +9,6 @@
#define BASE_SYSTEM_H
#include "detect.h"
#ifndef __USE_GNU
#define __USE_GNU
#endif
#include <stddef.h>
#include <stdlib.h>
#include <time.h>
@ -22,10 +17,6 @@
#include <sys/un.h>
#endif
#ifdef CONF_PLATFORM_LINUX
#include <sys/socket.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -741,22 +732,6 @@ NETSOCKET net_udp_create(NETADDR bindaddr);
*/
int net_udp_send(NETSOCKET sock, const NETADDR *addr, const void *data, int size);
#define VLEN 128
#define PACKETSIZE 1400
typedef struct
{
#ifdef CONF_PLATFORM_LINUX
int pos;
int size;
struct mmsghdr msgs[VLEN];
struct iovec iovecs[VLEN];
char bufs[VLEN][PACKETSIZE];
char sockaddrs[VLEN][128];
#endif
} MMSGS;
void net_init_mmsgs(MMSGS* m);
/*
Function: net_udp_recv
Receives a packet over an UDP socket.
@ -771,7 +746,7 @@ void net_init_mmsgs(MMSGS* m);
On success it returns the number of bytes received. Returns -1
on error.
*/
int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize, MMSGS* m);
int net_udp_recv(NETSOCKET sock, NETADDR *addr, void *data, int maxsize);
/*
Function: net_udp_close

View file

@ -56,9 +56,6 @@ int CNetClient::ResetErrorString()
int CNetClient::Recv(CNetChunk *pChunk)
{
MMSGS m;
net_init_mmsgs(&m);
while(1)
{
// check for a chunk
@ -67,7 +64,7 @@ int CNetClient::Recv(CNetChunk *pChunk)
// TODO: empty the recvinfo
NETADDR Addr;
int Bytes = net_udp_recv(m_Socket, &Addr, m_RecvUnpacker.m_aBuffer, NET_MAX_PACKETSIZE, &m);
int Bytes = net_udp_recv(m_Socket, &Addr, m_RecvUnpacker.m_aBuffer, NET_MAX_PACKETSIZE);
// no more packets for now
if(Bytes <= 0)

View file

@ -581,8 +581,6 @@ int CNetServer::GetClientSlot(const NETADDR &Addr)
*/
int CNetServer::Recv(CNetChunk *pChunk)
{
MMSGS m;
net_init_mmsgs(&m);
while(1)
{
NETADDR Addr;
@ -592,7 +590,7 @@ int CNetServer::Recv(CNetChunk *pChunk)
return 1;
// TODO: empty the recvinfo
int Bytes = net_udp_recv(m_Socket, &Addr, m_RecvUnpacker.m_aBuffer, NET_MAX_PACKETSIZE, &m);
int Bytes = net_udp_recv(m_Socket, &Addr, m_RecvUnpacker.m_aBuffer, NET_MAX_PACKETSIZE);
// no more packets for now
if(Bytes <= 0)