Re: Patch: Camel stream filter waits properly for slow streams
Philip Van Hoof <[email protected]> Tue, 20 May 2008 17:03:48 +0200
| Newsgroups | gmane.comp.gnome.apps.tinymail.devel,gmane.comp.gnome.evolution.patches,gmane.comp.gnome.evolution.devel |
|---|---|
| Message-ID | <1211295828.9291.25.camel@schtrumpf> |
--=-mhEZUoLrq7HSOpLkFtZ/
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Adding some people and mailing lists in CC
Reattaching patch for Evolution-hackers mailing list.
Please bring this upstream too, Jos=C3=A9
Response from Jeffrey:
jeff_ yea, you should compare against -1
jeff_ as long as it returns >0, it wrote all the data
jeff_ -1 is error
jeff_ 0 is EOF maybe
jeff_ if write even returns 0 ever
On Tue, 2008-05-20 at 16:10 +0200, Jos=C3=A9 Dapena Paz wrote:
> Hi,
>=20
> This patch for tinymail modifies a bit the implementation of do_write
> method in camel_stream_filter, to make it not fail simply because the
> stream is slow. In my case I'm getting problems writting to a bluetooth
> stream, as it sometimes writes less than the full buffer, and then the
> stream filter returns -1.
>=20
> Anyway, it seems that my code adds an active wait. How could I fix
> this? Any safe idea?
>=20
> Changelog entry would be:
> * libtinymail-camel/camel-lite/camel/camel-stream-filter.c:
> * (do_write): if the camel_stream_write call does not write the
> full buffer but it's not due to an error, then loop to go on=20
> writing the stream.
--=20
Philip Van Hoof, freelance software developer
home: me at pvanhoof dot be=20
gnome: pvanhoof at gnome dot org=20
http://pvanhoof.be/blog
http://codeminded.be
--=-mhEZUoLrq7HSOpLkFtZ/
Content-Disposition: attachment;
filename*0=tinymail-trunk-r3671-stream-filter-waits-properly-for-slow-st;
filename*1=reams.patch
Content-Type: text/x-patch;
name*0=tinymail-trunk-r3671-stream-filter-waits-properly-for-slow-stream;
name*1=s.patch; charset=utf-8
Content-Transfer-Encoding: 7bit
Index: libtinymail-camel/camel-lite/camel/camel-stream-filter.c
===================================================================
--- libtinymail-camel/camel-lite/camel/camel-stream-filter.c (revision 3671)
+++ libtinymail-camel/camel-lite/camel/camel-stream-filter.c (working copy)
@@ -290,6 +290,7 @@
struct _filter *f;
size_t presize, len, left = n;
char *buffer, realbuffer[READ_SIZE+READ_PAD];
+ size_t written = 0;
p->last_was_read = FALSE;
@@ -321,8 +322,13 @@
f = f->next;
}
- if (camel_stream_write(filter->source, buffer, len) != len)
- return -1;
+ for (written = 0; written < len;) {
+ size_t just_written;
+ just_written = camel_stream_write (filter->source, buffer + written, len - written);
+ if (just_written == -1)
+ return -1;
+ written += just_written;
+ }
}
g_check(p->realbuffer);
--=-mhEZUoLrq7HSOpLkFtZ/
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
tinymail-devel-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/tinymail-devel-list
--=-mhEZUoLrq7HSOpLkFtZ/--