]> granicus.if.org Git - libevent/commitdiff
test/dns: install correct RLIMIT_NOFILE in bufferevent_connect_hostname_emfile
authorAzat Khuzhin <a3at.mail@gmail.com>
Tue, 24 Apr 2018 11:46:06 +0000 (14:46 +0300)
committerAzat Khuzhin <azat@libevent.org>
Sat, 2 Feb 2019 12:17:56 +0000 (15:17 +0300)
Otherwise poll() will fail with EINVAL:
       EINVAL The nfds value exceeds the RLIMIT_NOFILE value.

P.S. and cleanup this test a little, with early-return.

CI: https://travis-ci.org/libevent/libevent/jobs/370350426
(cherry picked from commit d1c8993c3c34030b68ecb6079bd9dce8cb3d3604)

test/regress_dns.c

index b2ea8651659dcca820a2bfa6bd730504dce5b404..17cd7099ca71a09ae56978edfa646d85684ad489 100644 (file)
@@ -1161,34 +1161,36 @@ static void
 be_connect_hostname_event_cb(struct bufferevent *bev, short what, void *ctx)
 {
        struct be_conn_hostname_result *got = ctx;
-       if (!got->what) {
-               TT_BLATHER(("Got a bufferevent event %d", what));
-               got->what = what;
-
-               if ((what & BEV_EVENT_CONNECTED) || (what & BEV_EVENT_ERROR)) {
-                       int expected = 3;
-                       int r = bufferevent_socket_get_dns_error(bev);
-
-                       if (r) {
-                               got->dnserr = r;
-                               TT_BLATHER(("DNS error %d: %s", r,
-                                          evutil_gai_strerror(r)));
-                       }                       ++total_connected_or_failed;
-                       TT_BLATHER(("Got %d connections or errors.", total_connected_or_failed));
-
-                       /** emfile test */
-                       if (errno == EMFILE) {
-                               expected = 0;
-                       }
 
-                       if (total_n_accepted >= expected && total_connected_or_failed >= 5)
-                               event_base_loopexit(be_connect_hostname_base,
-                                   NULL);
-               }
-       } else {
+       if (got->what) {
                TT_FAIL(("Two events on one bufferevent. %d,%d",
                        got->what, (int)what));
        }
+
+       TT_BLATHER(("Got a bufferevent event %d", what));
+       got->what = what;
+
+       if ((what & BEV_EVENT_CONNECTED) || (what & BEV_EVENT_ERROR)) {
+               int expected = 3;
+               int r = bufferevent_socket_get_dns_error(bev);
+
+               if (r) {
+                       got->dnserr = r;
+                       TT_BLATHER(("DNS error %d: %s", r,
+                                  evutil_gai_strerror(r)));
+               }
+               ++total_connected_or_failed;
+               TT_BLATHER(("Got %d connections or errors.", total_connected_or_failed));
+
+               /** emfile test */
+               if (errno == EMFILE) {
+                       expected = 0;
+               }
+
+               if (total_n_accepted >= expected && total_connected_or_failed >= 5)
+                       event_base_loopexit(be_connect_hostname_base,
+                           NULL);
+       }
 }
 
 static void
@@ -1242,8 +1244,13 @@ test_bufferevent_connect_hostname(void *arg)
 
 #ifdef EVENT__HAVE_SETRLIMIT
        if (emfile) {
-               struct rlimit file = { 1, 1 };
-               setrlimit(RLIMIT_NOFILE, &file);
+               int fd = socket(AF_INET, SOCK_STREAM, 0);
+               struct rlimit file = { fd, fd };
+
+               tt_int_op(fd, >=, 0);
+               tt_assert(!close(fd));
+
+               tt_assert(!setrlimit(RLIMIT_NOFILE, &file));
        }
 #endif