aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-08-15 10:57:48 +0200
committerToni Uhlig <matzeton@googlemail.com>2020-08-15 10:57:48 +0200
commita619a850c7c316df535d11dba7a5c6228071ebe0 (patch)
tree1f22b32b4ba8ca4fb0f0531ba830fb33c0385d4f
parente8a115b39f4450dbae9961052cd61a4c38c917f3 (diff)
nDPIsrvd: fixed another two bugs; one related to EPOLLIN event for fd with shutdown reading end, one if write() did not write all bytes
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--nDPIsrvd.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/nDPIsrvd.c b/nDPIsrvd.c
index 46ae98a3d..cb38d7b87 100644
--- a/nDPIsrvd.c
+++ b/nDPIsrvd.c
@@ -388,21 +388,20 @@ int main(int argc, char ** argv)
if (current->type == JSON_SOCK)
{
shutdown(current->fd, SHUT_WR); // collector
+ /* setup epoll event */
+ struct epoll_event accept_event = {};
+ accept_event.data.ptr = current;
+ accept_event.events = EPOLLIN;
+ if (epoll_ctl(epollfd, EPOLL_CTL_ADD, current->fd, &accept_event) < 0)
+ {
+ disconnect_client(epollfd, current);
+ continue;
+ }
}
else
{
shutdown(current->fd, SHUT_RD); // distributor
}
-
- /* setup epoll event */
- struct epoll_event accept_event = {};
- accept_event.data.ptr = current;
- accept_event.events = EPOLLIN;
- if (epoll_ctl(epollfd, EPOLL_CTL_ADD, current->fd, &accept_event) < 0)
- {
- disconnect_client(epollfd, current);
- continue;
- }
}
else
{
@@ -551,13 +550,16 @@ int main(int argc, char ** argv)
disconnect_client(epollfd, &remotes.desc[i]);
continue;
}
- if ((size_t)bytes_written != remotes.desc[i].buf.used)
+ if ((size_t)bytes_written < remotes.desc[i].buf.used)
{
syslog(LOG_DAEMON,
- "Distributor connection wrote less bytes than expected: %zd < %zu",
+ "Distributor write less than expected: %zd < %zu",
bytes_written,
remotes.desc[i].buf.used);
- disconnect_client(epollfd, &remotes.desc[i]);
+ memmove(remotes.desc[i].buf.ptr,
+ remotes.desc[i].buf.ptr + bytes_written,
+ remotes.desc[i].buf.used - bytes_written);
+ remotes.desc[i].buf.used -= bytes_written;
continue;
}