Some testing with data packets.

FossilOrigin-Name: a660beb536c9585a97b2c3973036d5dbef775425f1657b80bd1992e09635a912
This commit is contained in:
7u83@mail.ru 2016-03-21 07:26:09 +00:00
parent 9063302951
commit 7836c8491c
1 changed files with 38 additions and 1 deletions

View File

@ -61,11 +61,48 @@ int conn_recvfrom_packet(struct conn *conn, uint8_t * buf, int len,
}
#include "log.h"
int conn_recv_packet_x(struct conn *conn, uint8_t * buf, int len, int flags)
{
socklen_t al;
struct sockaddr_storage from;
al = sizeof(struct sockaddr_storage);
memset(&from, 0, sizeof(struct sockaddr_storage));
int n;
while ((n = recvfrom(conn->sock, (char *) buf, len, flags, (struct sockaddr*)&from, &al)) < 0) {
if (errno != EINTR) {
if (errno == EAGAIN)
return n;
}
}
// cw_log(LOG_ERR,"Received a packet from %s, len = %d\n",sock_addr2str_p(&from),n);
int port = sock_getport((struct sockaddr*)&from);
if (port == 5247){
conn->process_packet(conn,buf,n,(struct sockaddr*)&from);
}
return n;
}
/* yes, these functions could be better defined as macros in a .h file */
int conn_recv_packet(struct conn *conn, uint8_t * buf, int len)
{
return conn_recv_packet_(conn, buf, len, 0);
return conn_recv_packet_x(conn, buf, len, 0);
}
int conn_recv_packet_peek(struct conn *conn, uint8_t * buf, int len)