diff --git a/src/iomtee.c b/src/iomtee.c index 68c3eb4..06dd116 100644 --- a/src/iomtee.c +++ b/src/iomtee.c @@ -163,7 +163,7 @@ static void *tee_run(void *arg) { iomtee_t *iomtee_open(int *vfd, int num_fds, ...) { iomtee_t *tee = calloc(1, sizeof(iomtee_t)); - tee->iomux = iomux_create(0, 0, 1); + tee->iomux = iomux_create(0, 1); int rc = pipe(tee->pipe); if (rc != 0) { fprintf(stderr, "Can't create pipe : %s\n", strerror(errno)); diff --git a/src/iomux.c b/src/iomux.c index 2b73022..4522b5f 100644 --- a/src/iomux.c +++ b/src/iomux.c @@ -24,6 +24,8 @@ #include +#include + #if defined(HAVE_EPOLL) #include #elif defined(HAVE_KQUEUE) @@ -124,7 +126,7 @@ static void set_error(iomux_t *iomux, char *fmt, ...) { static void iomux_handle_timeout(iomux_t *iomux, void *priv); iomux_t * -iomux_create(int max_connections, int bufsize, int threadsafe) +iomux_create(int bufsize, int threadsafe) { iomux_t *iomux = (iomux_t *)calloc(1, sizeof(iomux_t)); @@ -134,7 +136,15 @@ iomux_create(int max_connections, int bufsize, int threadsafe) } iomux->bufsize = (bufsize > 0) ? bufsize : IOMUX_CONNECTION_BUFSIZE_DEFAULT; - iomux->maxconnections = (max_connections > 0) ? max_connections : IOMUX_CONNECTIONS_MAX_DEFAULT; + + struct rlimit rlim; + if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) { + iomux->maxconnections = rlim.rlim_max; + } else { + fprintf(stderr, "Can't get the max number of filedescriptors: %s\n", + strerror(errno)); + iomux->maxconnections = IOMUX_CONNECTIONS_MAX_DEFAULT; + } #if defined(HAVE_EPOLL) iomux->efd = epoll_create1(0); diff --git a/src/iomux.h b/src/iomux.h index 9a31eb5..5cd8bbb 100644 --- a/src/iomux.h +++ b/src/iomux.h @@ -106,7 +106,7 @@ typedef struct __iomux_callbacks { * @brief Create a new iomux handler * @returns A valid iomux handler */ -iomux_t *iomux_create(int max_connections, int bufsize, int threadsafe); +iomux_t *iomux_create(int bufsize, int threadsafe); /** * @brief Add a filedescriptor to the mux diff --git a/test/iomux_test.c b/test/iomux_test.c index 09f655d..d0b05ad 100644 --- a/test/iomux_test.c +++ b/test/iomux_test.c @@ -280,8 +280,8 @@ main(int argc, char **argv) ut_init(basename(argv[0])); - ut_testing("iomux_create(0, 0, 0)"); - mux = iomux_create(0, 0, 0); + ut_testing("iomux_create(0, 0)"); + mux = iomux_create(0, 0); if (mux) ut_success(); else @@ -361,7 +361,7 @@ main(int argc, char **argv) }; server = open_socket("localhost", TEST_SERVER_PORT); - mux = iomux_create(0, 0, 0); + mux = iomux_create(0, 0); iomux_add(mux, server, &cbs); iomux_listen(mux, server);