From: Alan T. DeKok Date: Tue, 9 Apr 2024 14:51:49 +0000 (-0400) Subject: handle the case of WOULD_BLOCK X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3cfff0ba2a76a5af55d88f8a11209c94d0ade23;p=thirdparty%2Ffreeradius-server.git handle the case of WOULD_BLOCK --- diff --git a/src/bin/radclient-ng.c b/src/bin/radclient-ng.c index a8f013374d8..828f87c28b0 100644 --- a/src/bin/radclient-ng.c +++ b/src/bin/radclient-ng.c @@ -727,6 +727,8 @@ static int radclient_sane(rc_request_t *request) */ static int send_one_packet(fr_bio_packet_t *client, rc_request_t *request) { + int rcode; + fr_assert(!request->done); fr_assert(request->reply == NULL); @@ -779,12 +781,17 @@ static int send_one_packet(fr_bio_packet_t *client, rc_request_t *request) request->timestamp = fr_time(); request->tries = 1; - request->resend++; /* * Send the current packet. */ - if (fr_bio_packet_write(client, request, request->packet, &request->request_pairs) < 0) { + rcode = fr_bio_packet_write(client, request, request->packet, &request->request_pairs); + if (rcode < 0) { + /* + * Failed writing it. Try again later. + */ + if (rcode == fr_bio_error(IO_WOULD_BLOCK)) return 0; + REDEBUG("Failed writing packet - %s", fr_strerror()); return -1; } @@ -961,8 +968,6 @@ static void client_write(fr_event_list_t *el, int fd, UNUSED int flags, void *uc return; } - current = request; - if (request->packet->id >= 0) { paused = true; goto pause; @@ -979,6 +984,8 @@ static void client_write(fr_event_list_t *el, int fd, UNUSED int flags, void *uc } request->resend++; + current = request; + } static void client_connect(fr_event_list_t *el, int fd, UNUSED int flags, void *uctx) diff --git a/src/protocols/radius/client.c b/src/protocols/radius/client.c index ecb0d9de252..467f8d85415 100644 --- a/src/protocols/radius/client.c +++ b/src/protocols/radius/client.c @@ -161,11 +161,19 @@ int fr_radius_client_fd_bio_write(fr_radius_client_fd_bio_t *my, void *request_c if (fr_packet_sign(packet, NULL, (char const *) my->cfg.verify.secret) < 0) goto fail; slen = fr_bio_write(my->common.bio, &packet->socket, packet->data, packet->data_len); - if (slen <= 0) { + if (slen < 0) { fr_radius_code_id_push(my->codes, packet); return slen; } + /* + * Didn't write anything, that's a blocking error. + */ + if (slen == 0) { + fr_radius_code_id_push(my->codes, packet); + return fr_bio_error(IO_WOULD_BLOCK); + } + my->info.outstanding++; return 0;