Changeset 1611

Show
Ignore:
Timestamp:
03/27/08 22:29:13 (6 months ago)
Author:
till
Message:

nebula
- fix: dynamically grow and shrink poll fd set

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nebula/trunk/ChangeLog

    r1593 r1611  
    88- off-by-one error in signature generator input offset fixed 
    99- signature generation triggers when cluster threshold is met instead of exceeded 
     10- real time signals for adjusting certain parameters 
     11- write instead of printf in signal handlers 
    1012- flush stdout after each session 
    1113- clean up on SIGINT and SIGTERM 
  • nebula/trunk/src/nebula.c

    r1593 r1611  
    8787        memset(pfdflag, 0, sizeof(u_char) * (POLLFD_SET_SIZE)); 
    8888        memset(s, 0, sizeof(submission) * POLLFD_SET_SIZE); 
     89        pollfd_set_size         = 0; 
    8990 
    9091        global_sid              = 2000000; 
     
    272273 
    273274        for(;;) { 
    274                 switch (rv = poll(pfdset, POLLFD_SET_SIZE+1, -1)) { 
     275                switch (rv = poll(pfdset, pollfd_set_size+1, -1)) { 
    275276                case -1: 
    276277                        if (errno == EINTR) break; 
     
    294295                                } 
    295296 
    296                                 if (LISTEN_SOCK.revents & POLLIN) { 
    297                                         // incoming connection, find next free place in poll fd set 
    298                                  
    299                                         for (i=0; i<POLLFD_SET_SIZE; i++) { 
    300                                                 if (pfdset[i].fd <= 0) { 
    301                                                         pthread_mutex_lock(&sessions_mutex); 
    302  
    303                                                         pfdset[i].fd            = net_accept(LISTEN_SOCK.fd); 
    304                                                         pfdset[i].events        = POLLOUT; 
    305                                                         pfdflag[i]              = 1; 
    306  
    307                                                         memset(&s[i], 0, sizeof(submission)); 
    308  
    309                                                         pthread_mutex_unlock(&sessions_mutex); 
    310  
    311                                                         if (verbose > 1) printf("[>] Connection accepted.\n"); 
    312                                                         break; 
    313                                                 } 
    314                                         }        
     297                                if ((LISTEN_SOCK.revents & POLLIN) && pollfd_set_size < POLLFD_SET_SIZE) { 
     298                                        // incoming connection, accept it and place fd in pollfd set 
     299                                        pthread_mutex_lock(&sessions_mutex); 
     300 
     301                                        pollfd_set_size++; 
     302 
     303                                        pfdset[pollfd_set_size].fd      = net_accept(LISTEN_SOCK.fd); 
     304                                        pfdset[pollfd_set_size].events  = POLLOUT; 
     305                                        pfdflag[pollfd_set_size]        = 1; 
     306 
     307                                        memset(&s[pollfd_set_size], 0, sizeof(submission)); 
     308 
     309                                        pthread_mutex_unlock(&sessions_mutex); 
     310 
     311                                        if (verbose > 1) printf("[>] Connection accepted.\n"); 
    315312                                } 
    316313                        } 
    317                         for (i=0; i<POLLFD_SET_SIZE; i++) { 
     314                        for (i=1; i<=pollfd_set_size; i++) { 
    318315                                if (pfdflag[i] && pfdset[i].revents & POLLOUT) { 
    319316                                        switch (session_handle_data(&pfdset[i], &s[i])) { 
  • nebula/trunk/src/nebula.h

    r1593 r1611  
    3737 
    3838#define POLLFD_SET_SIZE 255 
    39 #define LISTEN_SOCK     pfdset[POLLFD_SET_SIZE
     39#define LISTEN_SOCK     pfdset[0
    4040 
    4141struct pollfd   pfdset[POLLFD_SET_SIZE+1]; 
    4242u_char          pfdflag[POLLFD_SET_SIZE]; 
     43int             pollfd_set_size;                // size of dynamically adjusted set 
    4344 
    4445int             lock_mutex; 
  • nebula/trunk/src/session.c

    r1593 r1611  
    5050                if (verbose > 1) printf("[<] Connection terminated.\n"); 
    5151 
    52                 memset(&pfdset[session_number], 0, sizeof(struct pollfd)); 
     52                // shrink pollfd set 
     53                memmove(&pfdset[session_number], &pfdset[session_number+1], sizeof(struct pollfd) * (POLLFD_SET_SIZE-session_number)); 
     54                memset(&pfdset[pollfd_set_size], 0, sizeof(struct pollfd)); 
     55                pollfd_set_size--; 
     56 
    5357                pfdset[session_number].events   = 0; 
    5458                pfdflag[session_number]         = 0;    // mark fd as unused 
  • nebula/trunk/src/sig.c

    r1589 r1611  
    110110 
    111111                // find minimal and maximal offset for leaves in this substring's subtree 
    112                 for (leaf = l; leaf < num_leaves && leaf <= r; leaf ++) { 
     112                for (leaf = l; leaf < num_leaves && leaf <= r; leaf++) { 
    113113                        id      = leaves[leaf]->string_id-1; 
    114114                        start   = leaves[leaf]->path_position; 
     
    126126 
    127127 
    128         // store signature info into for hashing a contiguous memory area 
     128        // store signature info into a contiguous memory area and calculate hash 
    129129        for (i=num_frags; i; i--) { 
    130130                // append next signature segment 
     
    290290                        if (!printable) putchar('|'); 
    291291                        INC_CHARCOUNT(1); 
    292                         printf("\"; depth: %lu; offset: %lu;", 
    293                                 (long unsigned int) seglist[num_frags-1].max_off+seglist[num_frags-1].len, 
     292                        printf("\"; offset: %lu; depth: %lu;", 
    294293                                (long unsigned int) (seglist[num_frags-1].min_off > seglist[num_frags-1].len ? 
    295                                         seglist[num_frags-1].min_off - seglist[num_frags-1].len : 0)); 
     294                                        seglist[num_frags-1].min_off - seglist[num_frags-1].len : 0), 
     295                                (long unsigned int) seglist[num_frags-1].max_off+seglist[num_frags-1].len); 
    296296 
    297297                        // process other segments 
  • nebula/trunk/src/sig.h

    r1589 r1611  
    8484 
    8585typedef struct { 
    86         ssize_t org_off; 
    87         ssize_t min_off; 
    88         ssize_t max_off; 
    89         ssize_t len; 
     86        ssize_t org_off;       // actual offset in the GST input string 
     87        ssize_t min_off;       // minimum offset in byte streams 
     88        ssize_t max_off;       // maximum offset in byte streams 
     89        ssize_t len;           // segment length 
    9090} sseg; 
    9191