]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
handle the case of WOULD_BLOCK
authorAlan T. DeKok <aland@freeradius.org>
Tue, 9 Apr 2024 14:51:49 +0000 (10:51 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 9 Apr 2024 15:53:21 +0000 (11:53 -0400)
src/bin/radclient-ng.c
src/protocols/radius/client.c

index a8f013374d820a882b4aea81f2cbc15745e263d6..828f87c28b0f9c7e2ef878e372a606c76df29aee 100644 (file)
@@ -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)
index ecb0d9de252ccfb1b3df44dcf6670ffe51eb394e..467f8d85415094e133cc686fa33e84aca960e55a 100644 (file)
@@ -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;