Commit 6953fc8e authored by Joanne Hugé's avatar Joanne Hugé

No segfault when doing nothing (fixed)

parent f1e6b168
......@@ -35,6 +35,7 @@
#define DEBUG
//#define DISABLE_SEND
//#define DISABLE_RECV
//#define DISABLE_DECODE
#include "utils.c"
#include "ring_buffer.c"
......@@ -322,11 +323,10 @@ static void *recv_thread(void *p) {
memset(msgh, 0, sizeof(msgh));
for(int j = 0; j < RX_BURST_SIZE; j++) {
msgv[j].iov_base = rbuf_write(&rx_rbuf);
msgv[j].iov_base = rbuf_write(&rx_rbuf) + j * rx_rbuf.block_len;
msgv[j].iov_len = rx_rbuf.block_len;
msgh[j].msg_hdr.msg_iov = &msgv[j];
msgh[j].msg_hdr.msg_iovlen = 1;
rbuf_increment_write(&rx_rbuf, rx_rbuf.block_len);
}
ret = recvmmsg(recv_sockfd, msgh, RX_BURST_SIZE, 0, NULL);
......@@ -335,6 +335,7 @@ static void *recv_thread(void *p) {
if(ret != RX_BURST_SIZE)
log_error("RECV_THREAD",
"recvmmsg received %d messages instead of %d\n", ret, RX_BURST_SIZE);
rbuf_increment_write(&rx_rbuf, RX_BURST_SIZE * rx_rbuf.block_len);
update_counter(&recv_counter, RX_BURST_SIZE);
}
pthread_exit(EXIT_SUCCESS);
......@@ -374,7 +375,6 @@ static void *send_thread(void *p) {
for(int64_t i = 1;; i++) {
int burst_size;
int to_send = rbuf_read_amount(&tx_rbuf);
if(to_send > TX_BURST_SIZE)
to_send = TX_BURST_SIZE;
......@@ -388,7 +388,7 @@ static void *send_thread(void *p) {
}
for(int j = 0; j < to_send;) {
int ret = sendmmsg(send_sockfd, msgh + j, (burst_size - j), 0);
int ret = sendmmsg(send_sockfd, msgh + j, (to_send - j), 0);
if(ret <= 0)
error(EXIT_FAILURE, errno, "sendmmsg error (returned %d)", ret);
j += ret;
......@@ -480,7 +480,7 @@ static void *encode_thread(void *p) {
}
static void *decode_thread(void *p) {
#ifdef DISABLE_RECV
#ifdef DISABLE_DECODE
pthread_exit(EXIT_SUCCESS);
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment