/[weechat]/weechat/src/irc/irc-dcc.c
ViewVC logotype

Diff of /weechat/src/irc/irc-dcc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.17 by flashcode, Thu May 5 16:26:34 2005 UTC revision 1.18 by flashcode, Tue Jul 12 17:05:02 2005 UTC
# Line 229  dcc_close (t_irc_dcc *ptr_dcc, int statu Line 229  dcc_close (t_irc_dcc *ptr_dcc, int statu
229          }          }
230      }      }
231            
232        /* remove empty file if received file failed and nothing was transfered */
233        if (((status == DCC_FAILED) || (status == DCC_ABORTED))
234            && DCC_IS_FILE(ptr_dcc->type)
235            && DCC_IS_RECV(ptr_dcc->type)
236            && ptr_dcc->local_filename
237            && ptr_dcc->pos == 0)
238            unlink (ptr_dcc->local_filename);
239        
240      if (DCC_IS_CHAT(ptr_dcc->type))      if (DCC_IS_CHAT(ptr_dcc->type))
241          channel_remove_dcc (ptr_dcc);          channel_remove_dcc (ptr_dcc);
242            
# Line 418  dcc_add (t_irc_server *server, int type, Line 426  dcc_add (t_irc_server *server, int type,
426      new_dcc->last_check_time = 0;      new_dcc->last_check_time = 0;
427      new_dcc->last_check_pos = 0;      new_dcc->last_check_pos = 0;
428      new_dcc->bytes_per_sec = 0;      new_dcc->bytes_per_sec = 0;
429        new_dcc->last_activity = time (NULL);
430      new_dcc->prev_dcc = NULL;      new_dcc->prev_dcc = NULL;
431      new_dcc->next_dcc = dcc_list;      new_dcc->next_dcc = dcc_list;
432      if (dcc_list)      if (dcc_list)
# Line 844  dcc_handle () Line 853  dcc_handle ()
853            
854      for (ptr_dcc = dcc_list; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)      for (ptr_dcc = dcc_list; ptr_dcc; ptr_dcc = ptr_dcc->next_dcc)
855      {      {
856            /* check DCC timeout */
857            if (DCC_IS_FILE(ptr_dcc->type) && !DCC_ENDED(ptr_dcc->status))
858            {
859                if ((cfg_dcc_timeout != 0) && (time (NULL) > ptr_dcc->last_activity + cfg_dcc_timeout))
860                {
861                    dcc_close (ptr_dcc, DCC_FAILED);
862                    dcc_redraw (1);
863                    continue;
864                }
865            }
866            
867          if (ptr_dcc->status == DCC_CONNECTING)          if (ptr_dcc->status == DCC_CONNECTING)
868          {          {
869              if (ptr_dcc->type == DCC_FILE_SEND)              if (ptr_dcc->type == DCC_FILE_SEND)
# Line 858  dcc_handle () Line 878  dcc_handle ()
878                  {                  {
879                      if (FD_ISSET (ptr_dcc->sock, &read_fd))                      if (FD_ISSET (ptr_dcc->sock, &read_fd))
880                      {                      {
881                            ptr_dcc->last_activity = time (NULL);
882                          length = sizeof (addr);                          length = sizeof (addr);
883                          sock = accept (ptr_dcc->sock, (struct sockaddr *) &addr, &length);                          sock = accept (ptr_dcc->sock, (struct sockaddr *) &addr, &length);
884                          close (ptr_dcc->sock);                          close (ptr_dcc->sock);
# Line 866  dcc_handle () Line 887  dcc_handle ()
887                          {                          {
888                              dcc_close (ptr_dcc, DCC_FAILED);                              dcc_close (ptr_dcc, DCC_FAILED);
889                              dcc_redraw (1);                              dcc_redraw (1);
890                              return;                              continue;
891                          }                          }
892                          ptr_dcc->sock = sock;                          ptr_dcc->sock = sock;
893                          if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)                          if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)
894                          {                          {
895                              dcc_close (ptr_dcc, DCC_FAILED);                              dcc_close (ptr_dcc, DCC_FAILED);
896                              dcc_redraw (1);                              dcc_redraw (1);
897                              return;                              continue;
898                          }                          }
899                          ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);                          ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);
900                          ptr_dcc->status = DCC_ACTIVE;                          ptr_dcc->status = DCC_ACTIVE;
# Line 907  dcc_handle () Line 928  dcc_handle ()
928                          {                          {
929                              dcc_close (ptr_dcc, DCC_FAILED);                              dcc_close (ptr_dcc, DCC_FAILED);
930                              dcc_redraw (1);                              dcc_redraw (1);
931                              return;                              continue;
932                          }                          }
933                          ptr_dcc->sock = sock;                          ptr_dcc->sock = sock;
934                          if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)                          if (fcntl (ptr_dcc->sock, F_SETFL, O_NONBLOCK) == -1)
935                          {                          {
936                              dcc_close (ptr_dcc, DCC_FAILED);                              dcc_close (ptr_dcc, DCC_FAILED);
937                              dcc_redraw (1);                              dcc_redraw (1);
938                              return;                              continue;
939                          }                          }
940                          ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);                          ptr_dcc->addr = ntohl (addr.sin_addr.s_addr);
941                          ptr_dcc->status = DCC_ACTIVE;                          ptr_dcc->status = DCC_ACTIVE;
# Line 950  dcc_handle () Line 971  dcc_handle ()
971                      {                      {
972                          dcc_close (ptr_dcc, DCC_FAILED);                          dcc_close (ptr_dcc, DCC_FAILED);
973                          dcc_redraw (1);                          dcc_redraw (1);
974                          return;                          continue;
975                      }                      }
976                                            
977                      if (write (ptr_dcc->file, buffer, num_read) == -1)                      if (write (ptr_dcc->file, buffer, num_read) == -1)
978                      {                      {
979                          dcc_close (ptr_dcc, DCC_FAILED);                          dcc_close (ptr_dcc, DCC_FAILED);
980                          dcc_redraw (1);                          dcc_redraw (1);
981                          return;                          continue;
982                      }                      }
983                        ptr_dcc->last_activity = time (NULL);
984                      ptr_dcc->pos += (unsigned long) num_read;                      ptr_dcc->pos += (unsigned long) num_read;
985                      pos = htonl (ptr_dcc->pos);                      pos = htonl (ptr_dcc->pos);
986                      send (ptr_dcc->sock, (char *) &pos, 4, 0);                      send (ptr_dcc->sock, (char *) &pos, 4, 0);
# Line 983  dcc_handle () Line 1005  dcc_handle ()
1005                                  sizeof (buffer));                                  sizeof (buffer));
1006                      dcc_close (ptr_dcc, DCC_FAILED);                      dcc_close (ptr_dcc, DCC_FAILED);
1007                      dcc_redraw (1);                      dcc_redraw (1);
1008                      return;                      continue;
1009                  }                  }
1010                  if (ptr_dcc->pos > ptr_dcc->ack)                  if (ptr_dcc->pos > ptr_dcc->ack)
1011                  {                  {
# Line 995  dcc_handle () Line 1017  dcc_handle ()
1017                          {                          {
1018                              dcc_close (ptr_dcc, DCC_FAILED);                              dcc_close (ptr_dcc, DCC_FAILED);
1019                              dcc_redraw (1);                              dcc_redraw (1);
1020                              return;                              continue;
1021                          }                          }
1022                          if (num_read < 4)                          if (num_read < 4)
1023                              return;                              continue;
1024                          recv (ptr_dcc->sock, (char *) &pos, 4, 0);                          recv (ptr_dcc->sock, (char *) &pos, 4, 0);
1025                          ptr_dcc->ack = ntohl (pos);                          ptr_dcc->ack = ntohl (pos);
1026                                                    
# Line 1007  dcc_handle () Line 1029  dcc_handle ()
1029                          {                          {
1030                              dcc_close (ptr_dcc, DCC_DONE);                              dcc_close (ptr_dcc, DCC_DONE);
1031                              dcc_redraw (1);                              dcc_redraw (1);
1032                              return;                              continue;
1033                          }                          }
1034                      }                      }
1035                  }                  }
# Line 1019  dcc_handle () Line 1041  dcc_handle ()
1041                      {                      {
1042                          dcc_close (ptr_dcc, DCC_FAILED);                          dcc_close (ptr_dcc, DCC_FAILED);
1043                          dcc_redraw (1);                          dcc_redraw (1);
1044                          return;                          continue;
1045                      }                      }
1046                      num_sent = send (ptr_dcc->sock, buffer, num_read, 0);                      num_sent = send (ptr_dcc->sock, buffer, num_read, 0);
1047                      if (num_sent < 0)                      if (num_sent < 0)
1048                      {                      {
1049                          dcc_close (ptr_dcc, DCC_FAILED);                          dcc_close (ptr_dcc, DCC_FAILED);
1050                          dcc_redraw (1);                          dcc_redraw (1);
1051                          return;                          continue;
1052                      }                      }
1053                        ptr_dcc->last_activity = time (NULL);
1054                      ptr_dcc->pos += (unsigned long) num_sent;                      ptr_dcc->pos += (unsigned long) num_sent;
1055                      dcc_calculate_speed (ptr_dcc, 0);                      dcc_calculate_speed (ptr_dcc, 0);
1056                      dcc_redraw (0);                      dcc_redraw (0);

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26