From: Alan T. DeKok Date: Tue, 11 Jul 2017 13:08:33 +0000 (-0400) Subject: try to call write() immediately. If it works, we're fine X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e95540c7a023f8e6d17ed4cef4ebe795b86efee;p=thirdparty%2Ffreeradius-server.git try to call write() immediately. If it works, we're fine This avoids a lot of overhead in updating the event list, and doing lots of callbacks. --- diff --git a/src/modules/rlm_radius/rlm_radius.c b/src/modules/rlm_radius/rlm_radius.c index 1a3e053e15b..6c69404d437 100644 --- a/src/modules/rlm_radius/rlm_radius.c +++ b/src/modules/rlm_radius/rlm_radius.c @@ -264,8 +264,9 @@ static void mod_radius_conn_writable(UNUSED fr_event_list_t *el, UNUSED int sock rad_assert(link->waiting = false); - // @todo - if this returns EWOULDBLOCK, stop - // @todo - if this returns "too many requests", stop. But the caller should have checked... + /* + * Write to the socket. + */ rcode = c->inst->client_io->write(link->request, link->request_io_ctx, c->client_io_ctx); /* @@ -661,8 +662,38 @@ static int CC_HINT(nonnull) mod_add(rlm_radius_t *inst, rlm_radius_connection_t * If there are no pending writes, enable the write * callback. It will wake up and write the packets to * the socket. + * + * We have no packets in the queue. Try calling write(). + * If it succeeds, we're good, and we can avoid updating + * the event list along with many callbacks and lots of + * overhead. */ if (!c->pending) { + int rcode; + + rcode = c->inst->client_io->write(link->request, link->request_io_ctx, c->client_io_ctx); + if (rcode < 0) { + talloc_free(link); + return -1; + } + + /* + * It was successfully written to the socket. + * Update the various timers, etc. + */ + if (rcode == 1) { + link->time_sent = fr_time(); + fr_dlist_remove(&link->entry); + fr_dlist_insert_head(&c->sent, &link->entry); + link->waiting = true; + c->num_outstanding++; + return 1; + } + + /* + * We couldn't write it, so leave the request on + * the pending queue. + */ c->pending = true; mod_radius_fd_active(c); }