Changeset 4806
- Timestamp:
- 05/28/07 21:50:10 (2 years ago)
- Files:
-
- wired/trunk/wired/commands.c (modified) (2 diffs)
- wired/trunk/wired/transfers.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wired/trunk/wired/commands.c
r4780 r4806 236 236 } while(state == WI_SOCKET_TIMEOUT && wd_user_state(user) <= WD_USER_LOGGED_IN); 237 237 238 if(wd_user_state(user) > WD_USER_LOGGED_IN) { 239 /* invalid state */ 238 if(wd_user_state(user) > WD_USER_LOGGED_IN) 240 239 break; 241 }242 240 243 241 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; 253 246 } 254 247 … … 258 251 259 252 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 } 262 257 263 258 break; wired/trunk/wired/transfers.c
r4750 r4806 34 34 #include <errno.h> 35 35 #include <openssl/ssl.h> 36 #include <openssl/err.h> 36 37 #include <wired/wired.h> 37 38 … … 614 615 SSL *ssl; 615 616 char buffer[WD_TRANSFER_BUFFER_SIZE]; 617 const char *file; 616 618 wi_time_interval_t interval, speedinterval, statusinterval, accountinterval; 617 619 wi_socket_state_t state; 618 620 ssize_t bytes, speedbytes, statsbytes; 619 621 wi_uinteger_t i = 0; 620 int fd, sd ;622 int fd, sd, result, error, line; 621 623 622 624 pool = wi_pool_init(wi_pool_alloc()); … … 656 658 bytes = read(fd, buffer, sizeof(buffer)); 657 659 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 659 666 break; 660 661 /* wait for timeout */ 667 } 668 669 /* wait to write */ 662 670 do { 663 671 state = wi_socket_wait_descriptor(sd, 0.1, false, true); 664 672 } 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) 668 675 break; 669 }670 676 671 677 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; 682 682 } 683 683 684 684 /* 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 686 710 break; 711 } 687 712 688 713 /* update counters */ … … 760 785 SSL *ssl; 761 786 char buffer[WD_TRANSFER_BUFFER_SIZE]; 787 const char *file; 762 788 wi_time_interval_t interval, speedinterval, statusinterval, accountinterval; 763 789 wi_socket_state_t state; 764 ssize_t bytes, speedbytes, statsbytes;790 ssize_t result, speedbytes, statsbytes; 765 791 wi_uinteger_t i = 0; 766 int sd, fd ;792 int sd, fd, bytes, error, line; 767 793 768 794 pool = wi_pool_init(wi_pool_alloc()); … … 797 823 798 824 while(transfer->state == WD_TRANSFER_RUNNING) { 799 /* wait for timeout*/825 /* wait to read */ 800 826 do { 801 827 state = wi_socket_wait_descriptor(sd, 0.1, true, false); 802 828 } 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) 806 831 break; 807 }808 832 809 833 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; 820 838 } 821 839 … … 823 841 bytes = SSL_read(ssl, buffer, sizeof(buffer)); 824 842 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 826 861 break; 862 } 827 863 828 864 /* 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 830 873 break; 874 } 831 875 832 876 /* update counters */
