[BACK]Return to ftp.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ftp

Diff for /src/usr.bin/ftp/ftp.c between version 1.66 and 1.67

version 1.66, 2007/03/06 05:16:01 version 1.67, 2007/06/16 08:58:33
Line 325 
Line 325 
         return (r);          return (r);
 }  }
   
   int keep_alive_timeout = 0;             /* 0 -> no timeout */
   
   static int full_noops_sent = 0;
   static time_t last_timestamp = 0;       /* 0 -> no measurement yet */
   static char noop[] = "NOOP\r\n";
   #define NOOP_LENGTH (sizeof noop - 1)
   static int current_nop_pos = 0;         /* 0 -> no noop started */
   
   /* to achieve keep alive, we send noop one byte at a time */
   void
   send_noop_char()
   {
           if (debug)
                   fprintf(ttyout, "---> %c\n", noop[current_nop_pos]);
           fputc(noop[current_nop_pos++], cout);
           (void)fflush(cout);
           if (current_nop_pos >= NOOP_LENGTH) {
                   full_noops_sent++;
                   current_nop_pos = 0;
           }
   }
   
   void
   may_reset_noop_timeout()
   {
           if (keep_alive_timeout != 0)
                   last_timestamp = time(NULL);
   }
   
   void
   may_receive_noop_ack()
   {
           int i;
   
           /* finish sending last incomplete noop */
           if (current_nop_pos != 0) {
                   fputs(&(noop[current_nop_pos]), cout);
                   if (debug)
                           fprintf(ttyout, "---> %s\n", &(noop[current_nop_pos]));
                   (void)fflush(cout);
                   current_nop_pos = 0;
                   full_noops_sent++;
           }
           /* and get the replies */
           for (i = 0; i < full_noops_sent; i++)
                   (void)getreply(0);
   
           full_noops_sent = 0;
   }
   
   void
   may_send_noop_char()
   {
           if (keep_alive_timeout != 0) {
                   if (last_timestamp != 0) {
                           time_t t = time(NULL);
   
                           if (t - last_timestamp >= keep_alive_timeout) {
                                   last_timestamp = t;
                                   send_noop_char();
                           }
                   } else {
                           last_timestamp = time(NULL);
                   }
           }
   }
   
 char reply_string[BUFSIZ];              /* first line of previous reply */  char reply_string[BUFSIZ];              /* first line of previous reply */
   
 int  int
Line 631 
Line 698 
         if (dout == NULL)          if (dout == NULL)
                 goto abort;                  goto abort;
         progressmeter(-1);          progressmeter(-1);
           may_reset_noop_timeout();
         oldintp = signal(SIGPIPE, SIG_IGN);          oldintp = signal(SIGPIPE, SIG_IGN);
         switch (curtype) {          switch (curtype) {
   
Line 638 
Line 706 
         case TYPE_L:          case TYPE_L:
                 errno = d = 0;                  errno = d = 0;
                 while ((c = read(fileno(fin), buf, sizeof(buf))) > 0) {                  while ((c = read(fileno(fin), buf, sizeof(buf))) > 0) {
                           may_send_noop_char();
                         bytes += c;                          bytes += c;
                         for (bufp = buf; c > 0; c -= d, bufp += d)                          for (bufp = buf; c > 0; c -= d, bufp += d)
                                 if ((d = write(fileno(dout), bufp, (size_t)c))                                  if ((d = write(fileno(dout), bufp, (size_t)c))
Line 668 
Line 737 
   
         case TYPE_A:          case TYPE_A:
                 while ((c = fgetc(fin)) != EOF) {                  while ((c = fgetc(fin)) != EOF) {
                           may_send_noop_char();
                         if (c == '\n') {                          if (c == '\n') {
                                 while (hash && (!progress || filesize < 0) &&                                  while (hash && (!progress || filesize < 0) &&
                                     (bytes >= hashbytes)) {                                      (bytes >= hashbytes)) {
Line 710 
Line 780 
                 (*closefunc)(fin);                  (*closefunc)(fin);
         (void)fclose(dout);          (void)fclose(dout);
         (void)getreply(0);          (void)getreply(0);
           may_receive_noop_ack();
         (void)signal(SIGINT, oldintr);          (void)signal(SIGINT, oldintr);
         (void)signal(SIGINFO, oldinti);          (void)signal(SIGINFO, oldinti);
         if (oldintp)          if (oldintp)
Line 938 
Line 1009 
                 preserve = 0;                  preserve = 0;
         }          }
         progressmeter(-1);          progressmeter(-1);
           may_reset_noop_timeout();
         switch (curtype) {          switch (curtype) {
   
         case TYPE_I:          case TYPE_I:
Line 956 
Line 1028 
                         ssize_t wr;                          ssize_t wr;
                         size_t  rd = c;                          size_t  rd = c;
   
                           may_send_noop_char();
                         d = 0;                          d = 0;
                         do {                          do {
                                 wr = write(fileno(fout), buf + d, rd);                                  wr = write(fileno(fout), buf + d, rd);
Line 1018 
Line 1091 
                         }                          }
                 }                  }
                 while ((c = fgetc(din)) != EOF) {                  while ((c = fgetc(din)) != EOF) {
                           may_send_noop_char();
                         if (c == '\n')                          if (c == '\n')
                                 bare_lfs++;                                  bare_lfs++;
                         while (c == '\r') {                          while (c == '\r') {
Line 1077 
Line 1151 
                 (void)signal(SIGPIPE, oldintp);                  (void)signal(SIGPIPE, oldintp);
         (void)fclose(din);          (void)fclose(din);
         (void)getreply(0);          (void)getreply(0);
           may_receive_noop_ack();
         if (bytes >= 0 && is_retr) {          if (bytes >= 0 && is_retr) {
                 if (bytes > 0)                  if (bytes > 0)
                         ptransfer(0);                          ptransfer(0);

Legend:
Removed from v.1.66  
changed lines
  Added in v.1.67