Mercurial > pidgin
comparison src/protocols/sametime/sametime.c @ 13207:8facf33a528a
[gaim-migrate @ 15571]
quiet some debugging. fixes in outgoing file transfers so that they'll show as complete (this is actualy a bug in Meanwhile, but I'm in the middle of a large rewrite right now). hopefully this will speed up sametime ft for some people, too. Or it could just consume more server resources and make everyone hate me, I dunno.
committer: Tailor Script <tailor@pidgin.im>
| author | Christopher O'Brien <siege@pidgin.im> |
|---|---|
| date | Thu, 09 Feb 2006 19:04:36 +0000 |
| parents | 76c66b7e1327 |
| children | 77e1d19c115a |
comparison
equal
deleted
inserted
replaced
| 13206:0c4db52c6a3d | 13207:8facf33a528a |
|---|---|
| 391 return 0; | 391 return 0; |
| 392 } | 392 } |
| 393 | 393 |
| 394 while(len) { | 394 while(len) { |
| 395 ret = write(pd->socket, buf, (len > BUF_LEN)? BUF_LEN: len); | 395 ret = write(pd->socket, buf, (len > BUF_LEN)? BUF_LEN: len); |
| 396 DEBUG_INFO("wrote %i bytes in one turn\n", ret); | |
| 397 | 396 |
| 398 if(ret <= 0) | 397 if(ret <= 0) |
| 399 break; | 398 break; |
| 400 | 399 |
| 401 len -= ret; | 400 len -= ret; |
| 2023 srvc = mwServiceConference_new(s, &mw_conference_handler); | 2022 srvc = mwServiceConference_new(s, &mw_conference_handler); |
| 2024 return srvc; | 2023 return srvc; |
| 2025 } | 2024 } |
| 2026 | 2025 |
| 2027 | 2026 |
| 2027 /** size of an outgoing file transfer chunk */ | |
| 2028 #define MW_FT_LEN (BUF_LONG * 2) | |
| 2029 | |
| 2030 | |
| 2028 static void ft_incoming_cancel(GaimXfer *xfer) { | 2031 static void ft_incoming_cancel(GaimXfer *xfer) { |
| 2029 /* incoming transfer rejected or canceled in-progress */ | 2032 /* incoming transfer rejected or canceled in-progress */ |
| 2030 struct mwFileTransfer *ft = xfer->data; | 2033 struct mwFileTransfer *ft = xfer->data; |
| 2031 if(ft) mwFileTransfer_reject(ft); | 2034 if(ft) mwFileTransfer_reject(ft); |
| 2032 } | 2035 } |
| 2102 gaim_xfer_request(xfer); | 2105 gaim_xfer_request(xfer); |
| 2103 } | 2106 } |
| 2104 | 2107 |
| 2105 | 2108 |
| 2106 static void ft_send(struct mwFileTransfer *ft, FILE *fp) { | 2109 static void ft_send(struct mwFileTransfer *ft, FILE *fp) { |
| 2107 guchar buf[BUF_LONG]; | 2110 guchar buf[MW_FT_LEN]; |
| 2108 struct mwOpaque o = { .data = buf, .len = BUF_LONG }; | 2111 struct mwOpaque o = { .data = buf, .len = MW_FT_LEN }; |
| 2109 guint32 rem; | 2112 guint32 rem; |
| 2110 GaimXfer *xfer; | 2113 GaimXfer *xfer; |
| 2111 | 2114 |
| 2112 xfer = mwFileTransfer_getClientData(ft); | 2115 xfer = mwFileTransfer_getClientData(ft); |
| 2113 | 2116 |
| 2114 rem = mwFileTransfer_getRemaining(ft); | 2117 rem = mwFileTransfer_getRemaining(ft); |
| 2115 if(rem < BUF_LONG) o.len = rem; | 2118 if(rem < MW_FT_LEN) o.len = rem; |
| 2116 | 2119 |
| 2117 if(fread(buf, (size_t) o.len, 1, fp)) { | 2120 if(fread(buf, (size_t) o.len, 1, fp)) { |
| 2118 | 2121 |
| 2119 /* calculate progress first. update is displayed upon ack */ | 2122 /* calculate progress and display it */ |
| 2120 xfer->bytes_sent += o.len; | 2123 xfer->bytes_sent += o.len; |
| 2121 xfer->bytes_remaining -= o.len; | 2124 xfer->bytes_remaining -= o.len; |
| 2122 | 2125 gaim_xfer_update_progress(xfer); |
| 2123 /* ... send data second */ | 2126 |
| 2124 mwFileTransfer_send(ft, &o); | 2127 mwFileTransfer_send(ft, &o); |
| 2125 | 2128 |
| 2126 } else { | 2129 } else { |
| 2127 int err = errno; | 2130 int err = errno; |
| 2128 DEBUG_WARN("problem reading from file %s: %s", | 2131 DEBUG_WARN("problem reading from file %s: %s\n", |
| 2129 NSTR(mwFileTransfer_getFileName(ft)), strerror(err)); | 2132 NSTR(mwFileTransfer_getFileName(ft)), strerror(err)); |
| 2130 | 2133 |
| 2131 mwFileTransfer_cancel(ft); | 2134 mwFileTransfer_cancel(ft); |
| 2132 } | 2135 } |
| 2133 } | |
| 2134 | |
| 2135 | |
| 2136 static gboolean ft_idle_cb(struct mwFileTransfer *ft) { | |
| 2137 GaimXfer *xfer = mwFileTransfer_getClientData(ft); | |
| 2138 g_return_val_if_fail(xfer != NULL, FALSE); | |
| 2139 | |
| 2140 xfer->watcher = 0; | |
| 2141 ft_send(ft, xfer->dest_fp); | |
| 2142 | |
| 2143 return FALSE; | |
| 2144 } | 2136 } |
| 2145 | 2137 |
| 2146 | 2138 |
| 2147 static void mw_ft_opened(struct mwFileTransfer *ft) { | 2139 static void mw_ft_opened(struct mwFileTransfer *ft) { |
| 2148 /* | 2140 /* |
| 2158 mwFileTransfer_cancel(ft); | 2150 mwFileTransfer_cancel(ft); |
| 2159 mwFileTransfer_free(ft); | 2151 mwFileTransfer_free(ft); |
| 2160 g_return_if_reached(); | 2152 g_return_if_reached(); |
| 2161 } | 2153 } |
| 2162 | 2154 |
| 2163 gaim_xfer_update_progress(xfer); | |
| 2164 | |
| 2165 if(gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) { | 2155 if(gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) { |
| 2166 xfer->watcher = g_idle_add((GSourceFunc)ft_idle_cb, ft); | |
| 2167 xfer->dest_fp = g_fopen(xfer->local_filename, "rb"); | 2156 xfer->dest_fp = g_fopen(xfer->local_filename, "rb"); |
| 2157 ft_send(ft, xfer->dest_fp); | |
| 2168 } | 2158 } |
| 2169 } | 2159 } |
| 2170 | 2160 |
| 2171 | 2161 |
| 2172 static void mw_ft_closed(struct mwFileTransfer *ft, guint32 code) { | 2162 static void mw_ft_closed(struct mwFileTransfer *ft, guint32 code) { |
| 2180 | 2170 |
| 2181 xfer = mwFileTransfer_getClientData(ft); | 2171 xfer = mwFileTransfer_getClientData(ft); |
| 2182 if(xfer) { | 2172 if(xfer) { |
| 2183 xfer->data = NULL; | 2173 xfer->data = NULL; |
| 2184 | 2174 |
| 2185 if(mwFileTransfer_isDone(ft)) { | 2175 if(! mwFileTransfer_getRemaining(ft)) { |
| 2186 gaim_xfer_set_completed(xfer, TRUE); | 2176 gaim_xfer_set_completed(xfer, TRUE); |
| 2187 gaim_xfer_end(xfer); | 2177 gaim_xfer_end(xfer); |
| 2188 | 2178 |
| 2189 } else if(mwFileTransfer_isCancelLocal(ft)) { | 2179 } else if(mwFileTransfer_isCancelLocal(ft)) { |
| 2190 /* calling gaim_xfer_cancel_local is redundant, since that's | 2180 /* calling gaim_xfer_cancel_local is redundant, since that's |
| 2241 | 2231 |
| 2242 xfer = mwFileTransfer_getClientData(ft); | 2232 xfer = mwFileTransfer_getClientData(ft); |
| 2243 g_return_if_fail(xfer != NULL); | 2233 g_return_if_fail(xfer != NULL); |
| 2244 g_return_if_fail(xfer->watcher == 0); | 2234 g_return_if_fail(xfer->watcher == 0); |
| 2245 | 2235 |
| 2246 gaim_xfer_update_progress(xfer); | 2236 if(! mwFileTransfer_getRemaining(ft)) { |
| 2247 | 2237 gaim_xfer_set_completed(xfer, TRUE); |
| 2248 if(mwFileTransfer_isOpen(ft)) | 2238 gaim_xfer_end(xfer); |
| 2249 xfer->watcher = g_idle_add((GSourceFunc)ft_idle_cb, ft); | 2239 |
| 2240 } else if(mwFileTransfer_isOpen(ft)) { | |
| 2241 ft_send(ft, xfer->dest_fp); | |
| 2242 } | |
| 2250 } | 2243 } |
| 2251 | 2244 |
| 2252 | 2245 |
| 2253 static void mw_ft_clear(struct mwServiceFileTransfer *srvc) { | 2246 static void mw_ft_clear(struct mwServiceFileTransfer *srvc) { |
| 2254 ; | 2247 ; |
| 4941 | 4934 |
| 4942 filename = gaim_xfer_get_local_filename(xfer); | 4935 filename = gaim_xfer_get_local_filename(xfer); |
| 4943 filesize = gaim_xfer_get_size(xfer); | 4936 filesize = gaim_xfer_get_size(xfer); |
| 4944 idb.user = xfer->who; | 4937 idb.user = xfer->who; |
| 4945 | 4938 |
| 4939 gaim_xfer_update_progress(xfer); | |
| 4940 | |
| 4946 /* test that we can actually send the file */ | 4941 /* test that we can actually send the file */ |
| 4947 fp = g_fopen(filename, "rb"); | 4942 fp = g_fopen(filename, "rb"); |
| 4948 if(! fp) { | 4943 if(! fp) { |
| 4949 char *msg = g_strdup_printf(_("Error reading file %s: \n%s\n"), | 4944 char *msg = g_strdup_printf(_("Error reading file %s: \n%s\n"), |
| 4950 filename, strerror(errno)); | 4945 filename, strerror(errno)); |
| 4969 } | 4964 } |
| 4970 | 4965 |
| 4971 | 4966 |
| 4972 static void ft_outgoing_cancel(GaimXfer *xfer) { | 4967 static void ft_outgoing_cancel(GaimXfer *xfer) { |
| 4973 struct mwFileTransfer *ft = xfer->data; | 4968 struct mwFileTransfer *ft = xfer->data; |
| 4969 | |
| 4970 DEBUG_INFO("ft_outgoing_cancel called\n"); | |
| 4971 | |
| 4974 if(ft) mwFileTransfer_cancel(ft); | 4972 if(ft) mwFileTransfer_cancel(ft); |
| 4975 } | 4973 } |
| 4976 | 4974 |
| 4977 | 4975 |
| 4978 static GaimXfer *mw_prpl_new_xfer(GaimConnection *gc, const char *who) { | 4976 static GaimXfer *mw_prpl_new_xfer(GaimConnection *gc, const char *who) { |
| 4982 acct = gaim_connection_get_account(gc); | 4980 acct = gaim_connection_get_account(gc); |
| 4983 | 4981 |
| 4984 xfer = gaim_xfer_new(acct, GAIM_XFER_SEND, who); | 4982 xfer = gaim_xfer_new(acct, GAIM_XFER_SEND, who); |
| 4985 gaim_xfer_set_init_fnc(xfer, ft_outgoing_init); | 4983 gaim_xfer_set_init_fnc(xfer, ft_outgoing_init); |
| 4986 gaim_xfer_set_cancel_send_fnc(xfer, ft_outgoing_cancel); | 4984 gaim_xfer_set_cancel_send_fnc(xfer, ft_outgoing_cancel); |
| 4987 | 4985 |
| 4988 return xfer; | 4986 return xfer; |
| 4989 } | 4987 } |
| 4990 | 4988 |
| 4991 static void mw_prpl_send_file(GaimConnection *gc, | 4989 static void mw_prpl_send_file(GaimConnection *gc, |
| 4992 const char *who, const char *file) { | 4990 const char *who, const char *file) { |
