"Fossies" - the Fresh Open Source Software Archive

Member "netbiff-0.9.18/connection.c" (21 Sep 2003, 1968 Bytes) of package /linux/privat/old/netbiff-0.9.18.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "connection.c" see the Fossies "Dox" file reference documentation.

    1 #include "connection.h"
    2 #include "xlib.h"
    3 #include "gui.h"
    4 
    5 #include <unistd.h>
    6 #include <string.h>
    7 #include <time.h>
    8 
    9 Connection connections[MAX_CONNECTIONS];
   10 unsigned nconnections = 0;
   11 
   12 void connection_init(Connection *c) {
   13   c->state = CSTATE_PENALTY_BOX;
   14   c->pending_commands = 0;
   15 
   16   c->retry_time = time(0);
   17   c->penalty = 1;
   18 
   19   c->fd_in = c->fd_out = -1;
   20   buffer_init(&c->bin);
   21   buffer_init(&c->bout);
   22 
   23   c->name = NULL;
   24   c->command = NULL;
   25 
   26   c->nupdates = 0;
   27   c->nresets = 0;
   28   c->nfolders = 0;
   29   c->folders_added = 0;
   30 }
   31 
   32 void connection_close(Connection *c) {
   33   int i;
   34 
   35   if(c->fd_in >= 0)
   36     close(c->fd_in);
   37   if(c->fd_out >= 0)
   38     close(c->fd_out);
   39 
   40   gui.delete_fd(c, GUI_FD_READ|GUI_FD_WRITE);
   41 
   42   buffer_finish(&c->bin);
   43   buffer_finish(&c->bout);
   44 
   45   c->folders_added = 0;
   46 
   47   c->retry_time = time(0) + 2 * c->penalty;
   48   c->penalty *= 2;
   49   c->state = CSTATE_PENALTY_BOX;
   50   c->pending_commands = 0;
   51 
   52   gui.schedule_retry(c->retry_time);
   53   
   54   for(i = 0; i < c->nfolders; i++)
   55     c->folders[i].biffed = 0;
   56   gui.flagdown(c);
   57 }
   58 
   59 void connection_do_update(Connection *c, const char *folder) {
   60   int i;
   61 
   62   if(folder) {
   63     xerror("%s: %s biffed", c->name, folder);
   64     for(i = 0; i < c->nfolders; i++) {
   65       if(!strcmp(folder, c->folders[i].name)) {
   66         c->folders[i].biffed = 1;
   67         break;
   68       }
   69     }
   70   }
   71 
   72   for(i = 0; i < c->nupdates; i++)
   73     action_perform(c->updates[i], c);
   74 }
   75 
   76 void connection_do_reset(Connection *c, const char *folder) {
   77   int i;
   78   int biff_coefficient = 0;
   79   int found = 0;
   80   int was_biffed = 0;
   81 
   82   if(folder) {
   83     for(i = 0; i < c->nfolders; i++) {
   84       if(!found && !strcmp(folder, c->folders[i].name)) {
   85         was_biffed = c->folders[i].biffed;
   86         c->folders[i].biffed = 0;
   87         found = 1;
   88       }
   89       else
   90         biff_coefficient += c->folders[i].biffed;
   91     }
   92   }
   93 
   94   if(!biff_coefficient && found && was_biffed) {
   95     for(i = 0; i < c->nresets; i++)
   96       action_perform(c->resets[i], c);
   97   }
   98 }