diff --git a/obexd/src/obex-priv.h b/obexd/src/obex-priv.h
index 932f275..11d524f 100644
--- a/obexd/src/obex-priv.h
+++ b/obexd/src/obex-priv.h
const gchar *path;
time_t time;
guint8 *buf;
+ gint32 pending;
gint32 offset;
gint32 size;
gpointer object;
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 14e24ba..71fef28 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
if (os->size == OBJECT_SIZE_DELETE)
os->size = OBJECT_SIZE_UNKNOWN;
+ if (os->pending > 0)
+ goto write;
+
size = OBEX_ObjectReadStream(obex, obj, &buffer);
if (size < 0) {
error("Error on OBEX stream");
return -EIO;
}
- if (os->object == NULL && size > 0) {
- os->buf = g_realloc(os->buf, os->offset + size);
- memcpy(os->buf + os->offset, buffer, size);
- os->offset += size;
-
- debug("Stored %u bytes into temporary buffer", size);
-
+ os->buf = g_realloc(os->buf, os->pending + size);
+ memcpy(os->buf + os->pending, buffer, size);
+ os->pending += size;
+ if (os->object == NULL) {
+ debug("Stored %u bytes into temporary buffer", os->pending);
return 0;
}
- while (len < size) {
+write:
+ while (os->pending > 0) {
gint w;
- w = os->driver->write(os->object, buffer + len, size - len);
+ w = os->driver->write(os->object, os->buf + len,
+ os->pending);
if (w < 0) {
if (w == -EINTR)
continue;
- else
+ else {
+ memmove(os->buf, os->buf + len, os->pending);
return w;
+ }
}
len += w;
+ os->offset += w;
+ os->pending -= w;
}
- os->offset += len;
-
return 0;
}
gint obex_put_stream_start(struct obex_session *os, const gchar *filename)
{
- gint len;
int err;
os->object = os->driver->open(filename, O_WRONLY | O_CREAT | O_TRUNC,
return 0;
}
- len = 0;
- while (len < os->offset) {
- gint w;
-
- w = os->driver->write(os->object, os->buf + len,
- os->offset - len);
- if (w < 0) {
- error("write(%s): %s (%d)", filename, strerror(-w), -w);
- if (w == -EINTR)
- continue;
- else
- return w;
- }
-
- len += w;
- }
+ if (os->pending == 0)
+ return 0;
- return 0;
+ return obex_read_stream(os, os->obex, NULL);
}
static gboolean check_put(obex_t *obex, obex_object_t *obj)