Complain about too many sockets earlier
authorAlan T. DeKok <aland@freeradius.org>
Tue, 8 Dec 2009 15:31:55 +0000 (16:31 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 8 Dec 2009 15:31:55 +0000 (16:31 +0100)
Give feedback from event_new_fd() back to proxy_new_listener(),
and to insert_into_proxy_hash().  When all sockets are allocated,
stop allocating new ones

src/include/radiusd.h
src/main/event.c
src/main/listen.c

index 4bffd70..cd0c9b3 100644 (file)
@@ -692,7 +692,7 @@ int received_request(rad_listen_t *listener,
                     RADIUS_PACKET *packet, REQUEST **prequest,
                     RADCLIENT *client);
 REQUEST *received_proxy_response(RADIUS_PACKET *packet);
-void event_new_fd(rad_listen_t *listener);
+int event_new_fd(rad_listen_t *listener);
 
 /* evaluate.c */
 int radius_evaluate_condition(REQUEST *request, int modreturn, int depth,
index a230b52..d54b7f8 100644 (file)
@@ -3322,11 +3322,11 @@ static void tcp_socket_idle_timeout(void *ctx)
 }
 #endif
 
-void event_new_fd(rad_listen_t *this)
+int event_new_fd(rad_listen_t *this)
 {
        char buffer[1024];
 
-       if (this->status == RAD_LISTEN_STATUS_KNOWN) return;
+       if (this->status == RAD_LISTEN_STATUS_KNOWN) return 1;
 
        this->print(this, buffer, sizeof(buffer));
 
@@ -3353,7 +3353,6 @@ void event_new_fd(rad_listen_t *this)
                                                       this)) {
 
                                proxy_no_new_sockets = TRUE;
-                               listen_free(&this);
                                PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
 
                                /*
@@ -3364,7 +3363,7 @@ void event_new_fd(rad_listen_t *this)
                                 */
                                radlog(L_ERR, "Failed adding proxy socket: %s",
                                       fr_strerror());
-                               return;
+                               return 0;
                        }
 
                        if (sock->home) {
@@ -3408,7 +3407,7 @@ void event_new_fd(rad_listen_t *this)
                         *      Set up the first poll interval.
                         */
                        event_poll_detail(this);
-                       return;
+                       return 1;
                }
 #endif
 
@@ -3421,7 +3420,7 @@ void event_new_fd(rad_listen_t *this)
                FD_MUTEX_UNLOCK(&fd_mutex);
                
                this->status = RAD_LISTEN_STATUS_KNOWN;
-               return;
+               return 1;
        }
 
        /*
@@ -3574,7 +3573,7 @@ void event_new_fd(rad_listen_t *this)
                                rad_panic("Failed to insert event");
                        }
                       
-                       return;
+                       return 1;
                }
 
                /*
@@ -3631,6 +3630,8 @@ finish:
                 */
                listen_free(&this);
        }
+
+       return 1;
 }
 
 static void handle_signal_self(int flag)
index 52551ae..e86da73 100644 (file)
@@ -2283,7 +2283,10 @@ int proxy_new_listener(home_server *home, int src_port)
        /*
         *      Tell the event loop that we have a new FD
         */
-       event_new_fd(this);
+       if (!event_new_fd(this)) {
+               listen_free(&this);
+               return 0;
+       }
        
        return 1;
 }