Split request_receive() into two functions.
authorAlan T. DeKok <aland@freeradius.org>
Fri, 3 Jun 2011 08:27:11 +0000 (10:27 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 3 Jun 2011 08:27:11 +0000 (10:27 +0200)
One is for sockets, and enforces limits, duplicates, etc.
The other allocates the request and inserts it into the queue,
independent of limits.  This is called directly by the detail
file reader

src/include/process.h
src/main/detail.c
src/main/process.c

index 61dfeb4..b100096 100644 (file)
@@ -52,7 +52,9 @@ int request_enqueue(REQUEST *request);
 
 int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet,
                    RADCLIENT *client, RAD_REQUEST_FUNP fun);
-
+int request_insert(rad_listen_t *listener, RADIUS_PACKET *packet,
+                  RADCLIENT *client, RAD_REQUEST_FUNP fun,
+                  struct timeval *pnow);
 #ifdef WITH_PROXY
 int request_proxy_reply(RADIUS_PACKET *packet);
 #endif
index 4a2df79..432dcf3 100644 (file)
@@ -733,7 +733,7 @@ int detail_recv(rad_listen_t *listener)
         *
         *      Try again later...
         */
-       if (!request_receive(listener, packet, &data->detail_client,
+       if (!request_insert(listener, packet, &data->detail_client,
                             rad_accounting)) {
                rad_free(&packet);
                data->state = STATE_NO_REPLY;   /* try again later */
index efeefc2..214064f 100644 (file)
@@ -426,6 +426,9 @@ static void request_done(REQUEST *request, int action)
 #ifdef DEBUG_STATE_MACHINE
                if (debug_flag) printf("(%u) ********\tSTATE %s C%u -> C%u\t********\n", request->number, __FUNCTION__, request->child_state, REQUEST_DONE);
 #endif
+#ifdef HAVE_PTHREAD_H
+               rad_assert(request->child_pid == NO_SUCH_CHILD_PID);
+#endif
                request->child_state = REQUEST_DONE;
                break;
 
@@ -1187,19 +1190,13 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet,
        RADIUS_PACKET **packet_p;
        REQUEST *request = NULL;
        struct timeval now;
+       listen_socket_t *sock = listener->data;
 
        /*
         *      Set the last packet received.
         */
        gettimeofday(&now, NULL);
-#ifdef WITH_DETAIL
-       if (listener->type != RAD_LISTEN_DETAIL)
-#endif
-       {
-               listen_socket_t *sock = listener->data;
-
-               sock->last_packet = now.tv_sec;
-       }
+       sock->last_packet = now.tv_sec;
 
        packet_p = fr_packet_list_find(pl, packet);
        if (packet_p) {
@@ -1254,13 +1251,8 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet,
 
        /*
         *      Quench maximum number of outstanding requests.
-        *
-        *      But we can always read from the detail file.
         */
        if (mainconfig.max_requests &&
-#ifdef WITH_DETAIL
-           (listener->type != RAD_LISTEN_DETAIL)  &&
-#endif
            ((count = fr_packet_list_num_elements(pl)) > mainconfig.max_requests)) {
                static time_t last_complained = 0;
 
@@ -1281,6 +1273,15 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet,
                return 0;
        }
 
+       return request_insert(listener, packet, client, fun);
+}
+
+int request_insert(rad_listen_t *listener, RADIUS_PACKET *packet,
+                  RADCLIENT *client, RAD_REQUEST_FUNP fun,
+                  struct timeval *pnow)
+{
+       REQUEST *request;
+
        /*
         *      Create and initialize the new request.
         */
@@ -1295,7 +1296,7 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet,
        request->listener = listener;
        request->client = client;
        request->packet = packet;
-       request->packet->timestamp = now;
+       request->packet->timestamp = *pnow;
        request->number = request_num_counter++;
        request->priority = listener->type;
        request->master_state = REQUEST_ACTIVE;
@@ -2452,6 +2453,9 @@ static void ping_home_server(void *ctx)
        if (debug_flag) printf("(%u) ********\tSTATE %s C%u -> C%u\t********\n", request->number, __FUNCTION__, request->child_state, REQUEST_DONE);
        if (debug_flag) printf("(%u) ********\tNEXT-STATE %s -> %s\n", request->number, __FUNCTION__, "request_ping");
 #endif
+#ifdef HAVE_PTHREAD_H
+       rad_assert(request->child_pid == NO_SUCH_CHILD_PID);
+#endif
        request->child_state = REQUEST_DONE;
        request->process = request_ping;
 
@@ -2710,6 +2714,9 @@ static void request_proxied(REQUEST *request, int action)
 #ifdef DEBUG_STATE_MACHINE
                        if (debug_flag) printf("(%u) ********\tSTATE %s C%u -> C%u\t********\n", request->number, __FUNCTION__, request->child_state, REQUEST_DONE);
 #endif
+#ifdef HAVE_PTHREAD_H
+                       rad_assert(request->child_pid == NO_SUCH_CHILD_PID);
+#endif
                        request->child_state = REQUEST_DONE;
                        request_process_timer(request);
                        return;
@@ -3159,7 +3166,6 @@ static void request_coa_process(REQUEST *request, int action)
                RDEBUG3("%s: Ignoring action %s", __FUNCTION__, action_codes[action]);
                break;
        }
-       
 }
 
 #endif /* WITH_COA */