1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
diff -Nru obexftp-0.21.orig/multicobex/multi_cobex.c obexftp-0.21/multicobex/multi_cobex.c
--- obexftp-0.21.orig/multicobex/multi_cobex.c 2005-11-24 16:55:11.000000000 +0200
+++ obexftp-0.21/multicobex/multi_cobex.c 2006-06-02 21:53:07.483151000 +0300
@@ -126,7 +126,7 @@
/* Called from OBEX-lib when data needs to be written */
int cobex_write(obex_t *self, void *data, uint8_t *buffer, int length)
{
- int actual;
+ int written;
cobex_t *c;
return_val_if_fail (self != NULL, -1);
return_val_if_fail (data != NULL, -1);
@@ -137,24 +137,37 @@
DEBUG(3, "%s() Data %d bytes\n", __func__, length);
if (c->type == CT_ERICSSON || c->type == CT_SIEMENS) {
- actual = write(c->fd, buffer, length);
- if (actual < length) {
- DEBUG(1, "Error writing to port (%d expected %d)\n", actual, length);
- return actual; /* or -1? */
+ int retries=0, chunk, fails=0;
+ written = 0;
+ for (retries = 0; written < length; retries++) {
+ chunk = write(c->fd, buffer+written, length-written);
+ if (chunk <= 0) {
+ if ( ++fails >= 10 ) { // to avoid infinite looping if something is really wrong
+ DEBUG(1, "%s() Error writing to port (written %d bytes out of %d, in %d retries)\n", __func__, written, length, retries);
+ return written;
+ }
+ usleep(1); // This mysteriously avoids a resource not available error on write()
+ } else {
+ written += chunk;
+ fails = 0; // Reset error counter on successful write op
+ }
}
- return actual;
+
+ if (retries > 0)
+ DEBUG(2, "%s() Wrote %d bytes in %d retries\n", __func__, written, retries);
+ return written;
}
if (c->seq == 0){
- actual = bfb_send_first(c->fd, buffer, length);
- DEBUG(2, "%s() Wrote %d first packets (%d bytes)\n", __func__, actual, length);
+ written = bfb_send_first(c->fd, buffer, length);
+ DEBUG(2, "%s() Wrote %d first packets (%d bytes)\n", __func__, written, length);
} else {
- actual = bfb_send_next(c->fd, buffer, length, c->seq);
- DEBUG(2, "%s() Wrote %d packets (%d bytes)\n", __func__, actual, length);
+ written = bfb_send_next(c->fd, buffer, length, c->seq);
+ DEBUG(2, "%s() Wrote %d packets (%d bytes)\n", __func__, written, length);
}
c->seq++;
- return actual;
+ return written;
}
/* Called when input data is needed */
|