manoj       99/08/12 23:58:14

  Modified:    mpm/src/include http_connection.h httpd.h
               mpm/src/main http_connection.c
               mpm/src/modules/mpm/dexter dexter.c
               mpm/src/modules/mpm/mpmt_pthread mpmt_pthread.c
               mpm/src/modules/mpm/prefork prefork.c
               mpm/src/modules/mpm/spmt_os2 spmt_os2.c
               mpm/src/modules/mpm/winnt winnt.c
  Log:
  Add a connection ID to conn_rec. It uniquely identifies a connection at
  any instant in time. It's not very well tested yet.
  
  Revision  Changes    Path
  1.7       +1 -1      apache-2.0/mpm/src/include/http_connection.h
  
  Index: http_connection.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/include/http_connection.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -d -u -r1.6 -r1.7
  --- http_connection.h 1999/08/05 19:56:04     1.6
  +++ http_connection.h 1999/08/13 06:57:30     1.7
  @@ -66,7 +66,7 @@
   
   conn_rec *ap_new_connection(pool *p, server_rec *server, BUFF *inout,
                            const struct sockaddr_in *remaddr,
  -                         const struct sockaddr_in *saddr);
  +                         const struct sockaddr_in *saddr, long id);
   CORE_EXPORT(void) ap_process_connection(conn_rec *);
   int ap_process_http_connection(conn_rec *);
   
  
  
  
  1.12      +2 -0      apache-2.0/mpm/src/include/httpd.h
  
  Index: httpd.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/include/httpd.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -d -u -r1.11 -r1.12
  --- httpd.h   1999/08/06 00:54:19     1.11
  +++ httpd.h   1999/08/13 06:57:33     1.12
  @@ -816,6 +816,8 @@
       char *local_host;                /* used for ap_get_server_name when
                                 * UseCanonicalName is set to DNS
                                 * (ignores setting of HostnameLookups) */
  +    long id;                    /* ID of this connection; unique at any
  +                                 * point in time */
       void *conn_config;               /* Notes on *this* connection */
   };
   
  
  
  
  1.17      +3 -1      apache-2.0/mpm/src/main/http_connection.c
  
  Index: http_connection.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/main/http_connection.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -d -u -r1.16 -r1.17
  --- http_connection.c 1999/08/06 00:54:29     1.16
  +++ http_connection.c 1999/08/13 06:57:40     1.17
  @@ -258,7 +258,7 @@
   
   conn_rec *ap_new_connection(pool *p, server_rec *server, BUFF *inout,
                            const struct sockaddr_in *remaddr,
  -                         const struct sockaddr_in *saddr)
  +                         const struct sockaddr_in *saddr, long id)
   {
       conn_rec *conn = (conn_rec *) ap_pcalloc(p, sizeof(conn_rec));
   
  @@ -278,6 +278,8 @@
       conn->remote_addr = *remaddr;
       conn->remote_ip = ap_pstrdup(conn->pool,
                              inet_ntoa(conn->remote_addr.sin_addr));
  +    
  +    conn->id = id;
   
       return conn;
   }
  
  
  
  1.22      +43 -33    apache-2.0/mpm/src/modules/mpm/dexter/dexter.c
  
  Index: dexter.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/dexter/dexter.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -d -u -r1.21 -r1.22
  --- dexter.c  1999/08/12 02:02:27     1.21
  +++ dexter.c  1999/08/13 06:57:46     1.22
  @@ -145,18 +145,17 @@
   
   static pool *pconf;          /* Pool for config stuff */
   static pool *pchild;         /* Pool for httpd child stuff */
  -
  -typedef struct {
  -    pool *pool;
  -    pthread_mutex_t mutex;
  -    pthread_attr_t attr;
  -} worker_thread_info;
  +static pool *thread_pool_parent; /* Parent of per-thread pools */
  +static pthread_mutex_t thread_pool_create_mutex;
   
  +static int child_num;
   static int my_pid; /* Linux getpid() doesn't work except in main thread. Use
                         this instead */
   /* Keep track of the number of worker threads currently active */
   static int worker_thread_count;
   static pthread_mutex_t worker_thread_count_mutex;
  +static int worker_thread_free_ids[HARD_THREAD_LIMIT];
  +static pthread_attr_t worker_thread_attr;
   
   /* Keep track of the number of idle worker threads */
   static int idle_thread_count;
  @@ -849,7 +848,8 @@
    * Child process main loop.
    */
   
  -static void process_socket(pool *p, struct sockaddr *sa_client, int csd)
  +static void process_socket(pool *p, struct sockaddr *sa_client, int csd,
  +                           int conn_id)
   {
       struct sockaddr sa_server; /* ZZZZ */
       size_t len = sizeof(struct sockaddr);
  @@ -886,7 +886,8 @@
   
       current_conn = ap_new_connection(p, server_conf, conn_io,
                                     (const struct sockaddr_in *) sa_client, 
  -                                  (const struct sockaddr_in *) &sa_server);
  +                                  (const struct sockaddr_in *) &sa_server,
  +                                  conn_id);
   
       ap_process_connection(current_conn);
   }
  @@ -895,7 +896,7 @@
   static void *worker_thread_one_child(void *);
   
   /* Starts a thread as long as we're below max_threads */
  -static int start_thread(worker_thread_info *thread_info)
  +static int start_thread(void)
   {
       pthread_t thread;
       void *(*thread_function)(void *);
  @@ -908,19 +909,21 @@
           else {
               thread_function = worker_thread;
           }
  -        worker_thread_count++;
  -        if (pthread_create(&thread, &(thread_info->attr), thread_function, 
thread_info)) {
  +        if (pthread_create(&thread, &worker_thread_attr, thread_function,
  +       &worker_thread_free_ids[worker_thread_count])) {
               ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf,
                            "pthread_create: unable to create worker thread");
               /* In case system resources are maxxed out, we don't want
                  Apache running away with the CPU trying to fork over and
                  over and over again if we exit. */
               sleep(10);
  -            worker_thread_count--;
               workers_may_exit = 1;
               pthread_mutex_unlock(&worker_thread_count_mutex);
               return 0;
           }
  +     else {
  +         worker_thread_count++;
  +     }
       }
       else {
           static int reported = 0;
  @@ -973,12 +976,13 @@
       int poll_count = 0;
       static int curr_pollfd = 0;
       size_t len = sizeof(struct sockaddr);
  -    worker_thread_info *thread_info = arg;
       int thread_just_started = 1;
  +    int thread_num = *((int *) arg);
  +    long conn_id = child_num * HARD_THREAD_LIMIT + thread_num;
   
  -    pthread_mutex_lock(&thread_info->mutex);
  -    tpool = ap_make_sub_pool(thread_info->pool);
  -    pthread_mutex_unlock(&thread_info->mutex);
  +    pthread_mutex_lock(&thread_pool_create_mutex);
  +    tpool = ap_make_sub_pool(thread_pool_parent);
  +    pthread_mutex_unlock(&thread_pool_create_mutex);
       ptrans = ap_make_sub_pool(tpool);
   
       while (!workers_may_exit) {
  @@ -1054,7 +1058,7 @@
                   idle_thread_count--;
               }
               else {
  -                if (!start_thread(thread_info)) {
  +                if (!start_thread()) {
                       idle_thread_count--;
                   }
               }
  @@ -1066,7 +1070,7 @@
               pthread_mutex_unlock(&idle_thread_count_mutex);
               break;
           }
  -        process_socket(ptrans, &sa_client, csd);
  +        process_socket(ptrans, &sa_client, csd, conn_id);
           ap_clear_pool(ptrans);
           requests_this_child--;
       }
  @@ -1074,6 +1078,7 @@
       ap_destroy_pool(tpool);
       pthread_mutex_lock(&worker_thread_count_mutex);
       worker_thread_count--;
  +    worker_thread_free_ids[worker_thread_count] = thread_num;
       if (worker_thread_count == 0) {
           /* All the threads have exited, now finish the shutdown process
            * by signalling the sigwait thread */
  @@ -1094,12 +1099,13 @@
       int srv;
       int curr_pollfd, last_pollfd = 0;
       size_t len = sizeof(struct sockaddr);
  -    worker_thread_info *thread_info = arg;
       int thread_just_started = 1;
  +    int thread_num = *((int *) arg);
  +    long conn_id = child_num * HARD_THREAD_LIMIT + thread_num;
   
  -    pthread_mutex_lock(&thread_info->mutex);
  -    tpool = ap_make_sub_pool(thread_info->pool);
  -    pthread_mutex_unlock(&thread_info->mutex);
  +    pthread_mutex_lock(&thread_pool_create_mutex);
  +    tpool = ap_make_sub_pool(thread_pool_parent);
  +    pthread_mutex_unlock(&thread_pool_create_mutex);
       ptrans = ap_make_sub_pool(tpool);
   
       while (!workers_may_exit) {
  @@ -1179,7 +1185,7 @@
                   idle_thread_count--;
               }
               else {
  -                if (!start_thread(thread_info)) {
  +                if (!start_thread()) {
                       idle_thread_count--;
                   }
               }
  @@ -1192,7 +1198,7 @@
               pthread_mutex_unlock(&idle_thread_count_mutex);
            break;
        }
  -        process_socket(ptrans, &sa_client, csd);
  +        process_socket(ptrans, &sa_client, csd, conn_id);
           ap_clear_pool(ptrans);
           requests_this_child--;
       }
  @@ -1200,6 +1206,7 @@
       ap_destroy_pool(tpool);
       pthread_mutex_lock(&worker_thread_count_mutex);
       worker_thread_count--;
  +    worker_thread_free_ids[worker_thread_count] = thread_num;
       if (worker_thread_count == 0) {
           /* All the threads have exited, now finish the shutdown process
            * by signalling the sigwait thread */
  @@ -1210,15 +1217,15 @@
       return NULL;
   }
   
  -static void child_main(void)
  +static void child_main(int child_num_arg)
   {
       sigset_t sig_mask;
       int signal_received;
       int i;
  -    worker_thread_info thread_info;
       ap_listen_rec *lr;
   
       my_pid = getpid();
  +    child_num = child_num_arg;
       pchild = ap_make_sub_pool(pconf);
   
       /*stuff to do before we switch id's, so we have permissions.*/
  @@ -1261,18 +1268,21 @@
       }
       idle_thread_count = threads_to_start;
       worker_thread_count = 0;
  -    thread_info.pool = ap_make_sub_pool(pconf);
  -    pthread_mutex_init(&thread_info.mutex, NULL);
  +    for (i = 0; i < max_threads; i++) {
  +        worker_thread_free_ids[i] = i;
  +    }
  +    thread_pool_parent = ap_make_sub_pool(pchild);
  +    pthread_mutex_init(&thread_pool_create_mutex, NULL);
       pthread_mutex_init(&idle_thread_count_mutex, NULL);
       pthread_mutex_init(&worker_thread_count_mutex, NULL);
       pthread_mutex_init(&pipe_of_death_mutex, NULL);
  -    pthread_attr_init(&thread_info.attr);
  -    pthread_attr_setdetachstate(&thread_info.attr, PTHREAD_CREATE_DETACHED);
  +    pthread_attr_init(&worker_thread_attr);
  +    pthread_attr_setdetachstate(&worker_thread_attr, 
PTHREAD_CREATE_DETACHED);
   
       /* We are creating worker threads right now */
       for (i=0; i < threads_to_start; i++) {
           /* start_thread shouldn't fail here */
  -        if (!start_thread(&thread_info)) {
  +        if (!start_thread()) {
               break;
           }
       }
  @@ -1307,7 +1317,7 @@
       if (one_process) {
        set_signals();
           ap_scoreboard_image[slot].pid = getpid();
  -     child_main();
  +     child_main(slot);
       }
   
       if ((pid = fork()) == -1) {
  @@ -1338,7 +1348,7 @@
        /* XXX - For an unthreaded server, a signal handler will be necessary
           signal(SIGTERM, just_die);
        */
  -        child_main();
  +        child_main(slot);
   
        return 0;
       }
  
  
  
  1.26      +3 -1      
apache-2.0/mpm/src/modules/mpm/mpmt_pthread/mpmt_pthread.c
  
  Index: mpmt_pthread.c
  ===================================================================
  RCS file: 
/home/cvs/apache-2.0/mpm/src/modules/mpm/mpmt_pthread/mpmt_pthread.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -d -u -r1.25 -r1.26
  --- mpmt_pthread.c    1999/08/11 23:55:42     1.25
  +++ mpmt_pthread.c    1999/08/13 06:57:52     1.26
  @@ -864,6 +864,7 @@
       BUFF *conn_io;
       conn_rec *current_conn;
       ap_iol *iol;
  +    long conn_id = my_child_num * HARD_THREAD_LIMIT + my_thread_num;
   
       if (getsockname(csd, &sa_server, &len) < 0) { 
        ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, "getsockname");
  @@ -896,7 +897,8 @@
   
       current_conn = ap_new_connection(p, server_conf, conn_io,
                                     (const struct sockaddr_in *) sa_client, 
  -                                  (const struct sockaddr_in *) &sa_server);
  +                                  (const struct sockaddr_in *) &sa_server,
  +                                  conn_id);
   
       ap_process_connection(current_conn);
   }
  
  
  
  1.26      +2 -1      apache-2.0/mpm/src/modules/mpm/prefork/prefork.c
  
  Index: prefork.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/prefork/prefork.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -d -u -r1.25 -r1.26
  --- prefork.c 1999/08/06 00:54:42     1.25
  +++ prefork.c 1999/08/13 06:57:56     1.26
  @@ -2359,7 +2359,8 @@
   
        current_conn = ap_new_connection(ptrans, server_conf, conn_io,
                                         (struct sockaddr_in *) &sa_client,
  -                                      (struct sockaddr_in *) &sa_server);
  +                                      (struct sockaddr_in *) &sa_server,
  +                                      my_child_num);
   
        ap_process_connection(current_conn);
       }
  
  
  
  1.9       +2 -1      apache-2.0/mpm/src/modules/mpm/spmt_os2/spmt_os2.c
  
  Index: spmt_os2.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/spmt_os2/spmt_os2.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -d -u -r1.8 -r1.9
  --- spmt_os2.c        1999/08/05 19:56:24     1.8
  +++ spmt_os2.c        1999/08/13 06:58:02     1.9
  @@ -1135,7 +1135,8 @@
   
        current_conn = ap_new_connection(ptrans, server_conf, conn_io,
                                         (struct sockaddr_in *) &sa_client,
  -                                      (struct sockaddr_in *) &sa_server);
  +                                      (struct sockaddr_in *) &sa_server,
  +                                      THREAD_GLOBAL(child_num));
   
        ap_process_connection(current_conn);
       }
  
  
  
  1.4       +2 -2      apache-2.0/mpm/src/modules/mpm/winnt/winnt.c
  
  Index: winnt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/mpm/src/modules/mpm/winnt/winnt.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -d -u -r1.3 -r1.4
  --- winnt.c   1999/08/11 16:03:55     1.3
  +++ winnt.c   1999/08/13 06:58:08     1.4
  @@ -726,8 +726,8 @@
           
        current_conn = ap_new_connection(ptrans, server_conf, conn_io,
                                            (struct sockaddr_in *) &sa_client,
  -                                         (struct sockaddr_in *) 
&sa_server);//,
  -            //child_num, 0); /* Set my_thread_num to 0 for now */
  +                                         (struct sockaddr_in *) &sa_server,
  +                                         child_num);
           
           ap_process_connection(current_conn);
       }        
  
  
  

Reply via email to