Skip to content

Commit

Permalink
- calculate max fd value from the recent device file descriptor set
Browse files Browse the repository at this point in the history
  • Loading branch information
sp-martin committed Jun 4, 2024
1 parent eeff710 commit 235f47f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion port/linux/ipadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,13 @@ process_event(ip_context_t *dev, fd_set *rdfds, fd_set *wfds)
return 0;
}

static bool
fd_sets_are_equal(const fd_set *fd1, const fd_set *fd2)
{
return (memcmp(__FDS_BITS(fd1), __FDS_BITS(fd2), sizeof(__FDS_BITS(fd1))) ==
0);
}

static int
fds_max(const fd_set *sourcefds)
{
Expand Down Expand Up @@ -1041,7 +1048,10 @@ network_event_thread(void *data)
tcp_add_socks_to_rfd_set(dev);
tcp_add_controlflow_socks_to_rfd_set(&dev->rfds, dev);
#endif /* OC_TCP */
int max_read_fd = fds_max(&dev->rfds);

int max_read_fd = FD_SETSIZE;
fd_set last_rdfds;
FD_ZERO(&last_rdfds);

#ifdef OC_HAS_FEATURE_TCP_ASYNC_CONNECT
oc_clock_time_t expires_in = 0;
Expand All @@ -1063,6 +1073,12 @@ network_event_thread(void *data)
#endif /* OC_HAS_FEATURE_TCP_ASYNC_CONNECT */

#ifdef OC_DYNAMIC_ALLOCATION
if (!fd_sets_are_equal(&rdfds, &last_rdfds)) {
// fd set has changed -> recalculate max fd
max_read_fd = fds_max(&rdfds);
last_rdfds = rdfds;
}

if (oc_network_get_event_queue_length(dev->device) >=
OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS) {
// the queue is full -> add only control flow rfds
Expand Down

0 comments on commit 235f47f

Please sign in to comment.