2018-03-28 09:36:15 +02:00
|
|
|
#include "cw.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
|
2018-03-28 09:39:51 +02:00
|
|
|
int cw_read_from(struct conn *conn, struct sockaddr_storage *from)
|
2018-03-28 09:36:15 +02:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
uint8_t buf[2024];
|
|
|
|
int len = 2024;
|
2018-03-28 09:39:51 +02:00
|
|
|
|
2018-03-28 09:36:15 +02:00
|
|
|
if (!conn->readfrom) {
|
|
|
|
cw_log(LOG_ERR, "Fatal error, no readfrom method available.");
|
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-28 09:39:51 +02:00
|
|
|
|
2018-03-28 09:36:15 +02:00
|
|
|
n = conn->readfrom(conn, buf, len, from);
|
|
|
|
if (n < 0)
|
|
|
|
return n;
|
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
return conn->process_packet(conn, buf, n, (struct sockaddr *) from);
|
|
|
|
}
|
|
|
|
errno = EAGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|