[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] invalid recvmbox in UDP recv() function
From: |
gussabina |
Subject: |
Re: [lwip-users] invalid recvmbox in UDP recv() function |
Date: |
Thu, 11 May 2017 11:03:23 -0700 (MST) |
Ok. But TCP sockets works fine...Below is the code I'm using for TCP receive.
Actually, in below code I'm using select() to wait for receive data...Now
I'm confused...Should I use same approach for UDP?
Thanks;
Gus
/int SocketRead(void *context, byte* buf, int buf_len, int timeout_ms)
{
SocketContext *sock = (SocketContext*)context;
int rc = -1, timeout = 0;
SOERROR_T so_error = 0;
fd_set recvfds;
fd_set errfds;
struct timeval tv;
if (context == NULL || buf == NULL || buf_len <= 0) {
return ERROR_BAD_ARG;
}
sock->bytes = 0;
// Setup timeout and FD's
setup_timeout(&tv, timeout_ms);
FD_ZERO(&recvfds);
FD_SET(sock->fd, &recvfds);
FD_ZERO(&errfds);
FD_SET(sock->fd, &errfds);
// Loop until buf_len has been read, error or timeout
while (sock->bytes < buf_len) {
// Wait for rx data to be available
rc = select((int)SELECT_FD(sock->fd), &recvfds, NULL, &errfds, &tv);
if (rc > 0)
{
// Check if rx or error
if (FD_ISSET(sock->fd, &recvfds)) {
// Try and read number of buf_len provided,
// minus what's already been read
rc = (int)SOCK_RECV(sock->fd, &buf[sock->bytes], buf_len -
sock->bytes, 0);
if (rc <= 0) {
rc = -1;
goto exit; // Error
}
else {
sock->bytes += rc; // Data
}
}
if (FD_ISSET(sock->fd, &errfds)) {
rc = -1;
break;
}
}
else {
timeout = 1;
break; // timeout or signal
}
} // while
exit:
if (rc == 0 && timeout) {
rc = ERROR_TIMEOUT;
}
else if (rc < 0) {
// Get error
socklen_t len = sizeof(so_error);
getsockopt(sock->fd, SOL_SOCKET, SO_ERROR, &so_error, &len);
if (so_error == 0) {
rc = 0; // Handle signal
}
else {
rc = ERROR_NETWORK;
PRINTF("NetRead: Error %d", so_error);
}
}
else {
rc = sock->bytes;
}
sock->bytes = 0;
return rc;
}
/
--
View this message in context:
http://lwip.100.n7.nabble.com/invalid-recvmbox-in-UDP-recv-function-tp29602p29623.html
Sent from the lwip-users mailing list archive at Nabble.com.
- [lwip-users] invalid recvmbox in UDP recv() function, gussabina, 2017/05/10
- Re: [lwip-users] invalid recvmbox in UDP recv() function, Simon Goldschmidt, 2017/05/11
- Re: [lwip-users] invalid recvmbox in UDP recv() function, gussabina, 2017/05/11
- Re: [lwip-users] invalid recvmbox in UDP recv() function, gussabina, 2017/05/11
- Re: [lwip-users] invalid recvmbox in UDP recv() function, address@hidden, 2017/05/11
- Re: [lwip-users] invalid recvmbox in UDP recv() function,
gussabina <=
- Re: [lwip-users] invalid recvmbox in UDP recv() function, address@hidden, 2017/05/11
- Re: [lwip-users] invalid recvmbox in UDP recv() function, gussabina, 2017/05/11
- Re: [lwip-users] invalid recvmbox in UDP recv() function, address@hidden, 2017/05/11
- [lwip-users] SOLVED! Re: invalid recvmbox in UDP recv() function, gussabina, 2017/05/11
- Re: [lwip-users] SOLVED! Re: invalid recvmbox in UDP recv() function, address@hidden, 2017/05/12