Changeset 4806

Show
Ignore:
Timestamp:
05/28/07 21:50:10 (2 years ago)
Author:
morris
Message:

Better error logging for transfer read/write failures

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • wired/trunk/wired/commands.c

    r4780 r4806  
    236236                } while(state == WI_SOCKET_TIMEOUT && wd_user_state(user) <= WD_USER_LOGGED_IN); 
    237237                 
    238                 if(wd_user_state(user) > WD_USER_LOGGED_IN) { 
    239                         /* invalid state */ 
     238                if(wd_user_state(user) > WD_USER_LOGGED_IN) 
    240239                        break; 
    241                 } 
    242240 
    243241                if(state == WI_SOCKET_ERROR) { 
    244                         if(wi_error_code() == EINTR) { 
    245                                 /* got a signal */ 
    246                                 continue; 
    247                         } else { 
    248                                 /* error in TCP communication */ 
    249                                 wi_log_err(WI_STR("Could not read from %@: %m"), wd_user_ip(user)); 
    250  
    251                                 break; 
    252                         } 
     242                        wi_log_err(WI_STR("Could not wait for command from %@: %m"), 
     243                                wd_user_ip(user)); 
     244 
     245                        break; 
    253246                } 
    254247 
     
    258251                 
    259252                if(!string || wi_string_length(string) == 0) { 
    260                         if(!string) 
    261                                 wi_log_info(WI_STR("Could not read from %@: %m"), wd_user_ip(user)); 
     253                        if(!string) { 
     254                                wi_log_info(WI_STR("Could not read command from %@: %m"), 
     255                                        wd_user_ip(user)); 
     256                        } 
    262257                         
    263258                        break; 
  • wired/trunk/wired/transfers.c

    r4750 r4806  
    3434#include <errno.h> 
    3535#include <openssl/ssl.h> 
     36#include <openssl/err.h> 
    3637#include <wired/wired.h> 
    3738 
     
    614615        SSL                                             *ssl; 
    615616        char                                    buffer[WD_TRANSFER_BUFFER_SIZE]; 
     617        const char                              *file; 
    616618        wi_time_interval_t              interval, speedinterval, statusinterval, accountinterval; 
    617619        wi_socket_state_t               state; 
    618620        ssize_t                                 bytes, speedbytes, statsbytes; 
    619621        wi_uinteger_t                   i = 0; 
    620         int                                             fd, sd
     622        int                                             fd, sd, result, error, line
    621623 
    622624        pool = wi_pool_init(wi_pool_alloc()); 
     
    656658                bytes = read(fd, buffer, sizeof(buffer)); 
    657659 
    658                 if(bytes <= 0) 
     660                if(bytes <= 0) { 
     661                        if(bytes < 0) { 
     662                                wi_log_err(WI_STR("Could not read download from %@: %m"), 
     663                                        transfer->realpath, strerror(errno)); 
     664                        } 
     665                         
    659666                        break; 
    660  
    661                 /* wait for timeout */ 
     667                } 
     668 
     669                /* wait to write */ 
    662670                do { 
    663671                        state = wi_socket_wait_descriptor(sd, 0.1, false, true); 
    664672                } while(state == WI_SOCKET_TIMEOUT && transfer->state == WD_TRANSFER_RUNNING); 
    665  
    666                 if(transfer->state != WD_TRANSFER_RUNNING)  { 
    667                         /* invalid state */ 
     673                 
     674                if(transfer->state != WD_TRANSFER_RUNNING) 
    668675                        break; 
    669                 } 
    670676 
    671677                if(state == WI_SOCKET_ERROR) { 
    672                         if(wi_error_code() == EINTR) { 
    673                                 /* got a signal */ 
    674                                 continue; 
    675                         } else { 
    676                                 /* error in TCP communication */ 
    677                                 wi_log_err(WI_STR("Could not read from %@: %m"), 
    678                                         wd_user_ip(transfer->user)); 
    679  
    680                                 break; 
    681                         } 
     678                        wi_log_err(WI_STR("Could not wait for download to %@: %m"), 
     679                                wd_user_ip(transfer->user)); 
     680 
     681                        break; 
    682682                } 
    683683 
    684684                /* write data */ 
    685                 if(SSL_write(ssl, buffer, bytes) <= 0) 
     685                result = SSL_write(ssl, buffer, bytes); 
     686                 
     687                if(result <= 0) { 
     688                        if(result < 0) { 
     689                                if(ERR_peek_error() == 0) { 
     690                                        error = SSL_get_error(ssl, result); 
     691                                         
     692                                        if((error != SSL_ERROR_SYSCALL && error != SSL_ERROR_ZERO_RETURN) || 
     693                                           (error == SSL_ERROR_SYSCALL && errno != EPIPE)) { 
     694                                                wi_log_err(WI_STR("Could not write download to %@: %s"), 
     695                                                        wd_user_ip(transfer->user), strerror(errno)); 
     696                                        } 
     697                                } else { 
     698                                        error = ERR_get_error_line(&file, &line); 
     699 
     700                                        wi_log_err(WI_STR("Could not write download to %@: %s:%u: %s: %s (%u)"), 
     701                                                wd_user_ip(transfer->user), 
     702                                                file, 
     703                                                line, 
     704                                                ERR_func_error_string(error), 
     705                                                ERR_reason_error_string(error), 
     706                                                ERR_GET_REASON(error)); 
     707                                } 
     708                        } 
     709                         
    686710                        break; 
     711                } 
    687712 
    688713                /* update counters */ 
     
    760785        SSL                                             *ssl; 
    761786        char                                    buffer[WD_TRANSFER_BUFFER_SIZE]; 
     787        const char                              *file; 
    762788        wi_time_interval_t              interval, speedinterval, statusinterval, accountinterval; 
    763789        wi_socket_state_t               state; 
    764         ssize_t                                 bytes, speedbytes, statsbytes; 
     790        ssize_t                                 result, speedbytes, statsbytes; 
    765791        wi_uinteger_t                   i = 0; 
    766         int                                             sd, fd
     792        int                                             sd, fd, bytes, error, line
    767793 
    768794        pool = wi_pool_init(wi_pool_alloc()); 
     
    797823 
    798824        while(transfer->state == WD_TRANSFER_RUNNING) { 
    799                 /* wait for timeout */ 
     825                /* wait to read */ 
    800826                do { 
    801827                        state = wi_socket_wait_descriptor(sd, 0.1, true, false); 
    802828                } while(state == WI_SOCKET_TIMEOUT && transfer->state == WD_TRANSFER_RUNNING); 
    803  
    804                 if(transfer->state != WD_TRANSFER_RUNNING)  { 
    805                         /* invalid state */ 
     829                 
     830                if(transfer->state != WD_TRANSFER_RUNNING) 
    806831                        break; 
    807                 } 
    808832 
    809833                if(state == WI_SOCKET_ERROR) { 
    810                         if(wi_error_code() == EINTR) { 
    811                                 /* got a signal */ 
    812                                 continue; 
    813                         } else { 
    814                                 /* error in TCP communication */ 
    815                                 wi_log_err(WI_STR("Could not read from %@: %m"), 
    816                                         wd_user_ip(transfer->user)); 
    817  
    818                                 break; 
    819                         } 
     834                        wi_log_err(WI_STR("Could not wait for upload from %@: %m"), 
     835                                wd_user_ip(transfer->user)); 
     836 
     837                        break; 
    820838                } 
    821839 
     
    823841                bytes = SSL_read(ssl, buffer, sizeof(buffer)); 
    824842 
    825                 if(bytes <= 0) 
     843                if(bytes <= 0) { 
     844                        if(bytes < 0) { 
     845                                if(ERR_peek_error() == 0) { 
     846                                        wi_log_err(WI_STR("Could not read upload from %@: %s"), 
     847                                                wd_user_ip(transfer->user), strerror(errno)); 
     848                                } else { 
     849                                        error = ERR_get_error_line(&file, &line); 
     850 
     851                                        wi_log_err(WI_STR("Could not read upload from %@: %s:%u: %s: %s (%u)"), 
     852                                                wd_user_ip(transfer->user), 
     853                                                file, 
     854                                                line, 
     855                                                ERR_func_error_string(error), 
     856                                                ERR_reason_error_string(error), 
     857                                                ERR_GET_REASON(error)); 
     858                                } 
     859                        } 
     860                         
    826861                        break; 
     862                } 
    827863 
    828864                /* write data */ 
    829                 if(write(fd, buffer, bytes) <= 0) 
     865                result = write(fd, buffer, bytes); 
     866                 
     867                if(result <= 0) { 
     868                        if(result < 0) { 
     869                                wi_log_err(WI_STR("Could not write upload to %@: %s"), 
     870                                        transfer->realpath, strerror(errno)); 
     871                        } 
     872                         
    830873                        break; 
     874                } 
    831875 
    832876                /* update counters */