comparison libpurple/ft.c @ 22073:f90462eb434b

Part of a large patch from o_sukhodolsky to fix some build warnings. Refs #1344
author Richard Laager <rlaager@wiktel.com>
date Sun, 13 Jan 2008 21:20:19 +0000
parents 03c950701fac
children b99d6d21cd79
comparison
equal deleted inserted replaced
22072:ac48f2e34359 22073:f90462eb434b
30 #include "notify.h" 30 #include "notify.h"
31 #include "prefs.h" 31 #include "prefs.h"
32 #include "proxy.h" 32 #include "proxy.h"
33 #include "request.h" 33 #include "request.h"
34 #include "util.h" 34 #include "util.h"
35 #include "debug.h"
35 36
36 #define FT_INITIAL_BUFFER_SIZE 4096 37 #define FT_INITIAL_BUFFER_SIZE 4096
37 #define FT_MAX_BUFFER_SIZE 65535 38 #define FT_MAX_BUFFER_SIZE 65535
38 39
39 static PurpleXferUiOps *xfer_ui_ops = NULL; 40 static PurpleXferUiOps *xfer_ui_ops = NULL;
901 gssize r = 0; 902 gssize r = 0;
902 903
903 if (condition & PURPLE_INPUT_READ) { 904 if (condition & PURPLE_INPUT_READ) {
904 r = purple_xfer_read(xfer, &buffer); 905 r = purple_xfer_read(xfer, &buffer);
905 if (r > 0) { 906 if (r > 0) {
906 fwrite(buffer, 1, r, xfer->dest_fp); 907 const size_t wc = fwrite(buffer, 1, r, xfer->dest_fp);
908 if (wc != r) {
909 purple_debug_error("filetransfer", "Unable to write whole buffer.\n");
910 purple_xfer_cancel_remote(xfer);
911 return;
912 }
907 } else if(r < 0) { 913 } else if(r < 0) {
908 purple_xfer_cancel_remote(xfer); 914 purple_xfer_cancel_remote(xfer);
909 return; 915 return;
910 } 916 }
911 } 917 }
912 918
913 if (condition & PURPLE_INPUT_WRITE) { 919 if (condition & PURPLE_INPUT_WRITE) {
920 size_t result;
914 size_t s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size); 921 size_t s = MIN(purple_xfer_get_bytes_remaining(xfer), xfer->current_buffer_size);
915 922
916 /* this is so the prpl can keep the connection open 923 /* this is so the prpl can keep the connection open
917 if it needs to for some odd reason. */ 924 if it needs to for some odd reason. */
918 if (s == 0) { 925 if (s == 0) {
923 return; 930 return;
924 } 931 }
925 932
926 buffer = g_malloc0(s); 933 buffer = g_malloc0(s);
927 934
928 fread(buffer, 1, s, xfer->dest_fp); 935 result = fread(buffer, 1, s, xfer->dest_fp);
936 if (result != s) {
937 purple_debug_error("filetransfer", "Unable to read whole buffer.\n");
938 purple_xfer_cancel_remote(xfer);
939 g_free(buffer);
940 return;
941 }
929 942
930 /* Write as much as we're allowed to. */ 943 /* Write as much as we're allowed to. */
931 r = purple_xfer_write(xfer, buffer, s); 944 r = purple_xfer_write(xfer, buffer, s);
932 945
933 if (r == -1) { 946 if (r == -1) {