Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Commit 74a0cc59 authored by Alexandre Bailon's avatar Alexandre Bailon
Browse files

tcpip: use poll to wait for incomming data


This uses poll to wait for incomming data.
This also used to detect errors and avoid using an invalid
file descriptor.
This should improve the error handling when a connection is close
by the server or the client.

Signed-off-by: default avatarAlexandre Bailon <abailon@baylibre.com>
parent 0f2adcc9
1 merge request!3This fixes many issues
...@@ -382,12 +382,25 @@ static int _tcpip_read(int fd, void *data, size_t len) ...@@ -382,12 +382,25 @@ static int _tcpip_read(int fd, void *data, size_t len)
size_t remaining; size_t remaining;
size_t offset; size_t offset;
size_t recvd; size_t recvd;
struct pollfd pollfd;
if (0 == len) { if (0 == len) {
return 0; return 0;
} }
pollfd.fd = fd;
pollfd.events = POLLIN | POLLHUP | POLLERR | POLLHUP | POLLNVAL;
for(remaining = len, offset = 0, recvd = 0; remaining; remaining -= recvd, offset += recvd, recvd = 0) { for(remaining = len, offset = 0, recvd = 0; remaining; remaining -= recvd, offset += recvd, recvd = 0) {
ret = poll(&pollfd, 1, -1);
if (ret <= 0) {
pr_err("%s(): failed to execute poll\n", __func__);
return -errno;
}
/* The socket could not be used anymore */
if (pollfd.revents & (POLLHUP | POLLERR | POLLHUP | POLLNVAL))
return -ECONNRESET;
ret = read(fd, &((uint8_t *)data)[offset], remaining); ret = read(fd, &((uint8_t *)data)[offset], remaining);
if (-1 == ret) { if (-1 == ret) {
if (EAGAIN == errno) { if (EAGAIN == errno) {
......
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