Iain,

On Wed, Oct 20, 2010 at 1:04 AM, Iain Hibbert <[email protected]> wrote:
> On Tue, 19 Oct 2010, Maksim Yevmenkin wrote:
>
>> thanks for all the patches! could you please try the combined patch
>> (attached) and make sure it still works for you?
>
> yes, its still working fine thanks
>
> - in retrospect I wasn't sure about the last one, if using printf() is ok?

it should be fine

> one more patch attached, with two parts
>
> - not really important as they won't be called but later versions of
>  openobex (using 1.5) provide some more event hooks might be interesting
>  for somebody :)

sounds good

> - I never have seen the spinner, fflush(stdout) to force visibility

sure :)

> I was trying to get back to another thing I was working on earlier this
> year, to split up the OPUSH and FTRN services so that I could have
> different settings. I've not got far with it though, maybe next week :)

cool

thanks for your patches, Iain. please find attached combined patch.
please let me know if this works, and i will commit and release next
version

thanks
max
Index: client.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/client.c,v
retrieving revision 1.19
diff -u -r1.19 client.c
--- client.c    8 Jan 2010 18:31:22 -0000       1.19
+++ client.c    19 Oct 2010 17:51:05 -0000
@@ -50,6 +50,7 @@
 #include "client.h"
 #include "event.h"
 #include "log.h"
+#include "stream.h"
 #include "util.h"
 
 /*
@@ -769,6 +770,8 @@
                        log_err("%s(): Could not add HDR_BODY", __func__);
                        goto done;
                }
+
+               obexapp_stream_stats_reset(context);
                break;
 
        case OBEXAPP_PUT_CREATE_EMPTY:
@@ -803,8 +806,12 @@
 
        if (context->rsp != OBEX_RSP_SUCCESS)
                error = -1;
-       else
+       else {
                error = 0;
+               if (opcode == OBEXAPP_PUT)
+                       obexapp_stream_stats_print(context);
+       }
+
 done:
        if (object != NULL) {
                OBEX_ObjectDelete(handle, object);
@@ -909,6 +916,7 @@
                        goto done;
                }
 
+               obexapp_stream_stats_reset(context);
                OBEX_ObjectReadStream(handle, object, NULL);
                break;
 
@@ -990,6 +998,8 @@
                                        "%s (%d)", __func__,
                                        context->temp, local, strerror(errno),
                                        errno);
+                       else
+                               obexapp_stream_stats_print(context);
                        break;
                }
        } else
Index: event.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/event.c,v
retrieving revision 1.7
diff -u -r1.7 event.c
--- event.c     20 Aug 2009 21:57:18 -0000      1.7
+++ event.c     21 Oct 2010 22:33:27 -0000
@@ -60,7 +60,9 @@
        obexapp_event_stub,             /* 6 - OBEX_EV_ACCEPTHINT */ 
        obexapp_event_abort,            /* 7 - OBEX_EV_ABORT */
        obexapp_stream_write,           /* 8 - OBEX_EV_STREAMEMPTY */
-       obexapp_stream_read             /* 9 - OBEX_EV_STREAMAVAIL */
+       obexapp_stream_read,            /* 9 - OBEX_EV_STREAMAVAIL */
+       obexapp_event_stub,             /* 10 - OBEX_EV_UNEXPECTED */
+       obexapp_event_stub,             /* 11 - OBEX_EV_REQCHECK */
 };
 #define        server_eh_size  ((int)(sizeof(server_eh)/sizeof(server_eh[0])))
 
@@ -75,7 +77,9 @@
        obexapp_event_stub,             /* 6 - OBEX_EV_ACCEPTHINT */ 
        obexapp_event_abort,            /* 7 - OBEX_EV_ABORT */
        obexapp_stream_write,           /* 8 - OBEX_EV_STREAMEMPTY */
-       obexapp_stream_read             /* 9 - OBEX_EV_STREAMAVAIL */
+       obexapp_stream_read,            /* 9 - OBEX_EV_STREAMAVAIL */
+       obexapp_event_stub,             /* 10 - OBEX_EV_UNEXPECTED */
+       obexapp_event_stub,             /* 11 - OBEX_EV_REQCHECK */
 };
 #define        client_eh_size  ((int)(sizeof(client_eh)/sizeof(client_eh[0])))
 
@@ -137,7 +141,8 @@
                static uint32_t spinner_idx = 0;
 
                printf("%c\b", spinner[spinner_idx ++]);
-               if (spinner_idx >= sizeof(spinner)/sizeof(spinner[0]))
+               fflush(stdout);
+               if (spinner_idx == sizeof(spinner)/sizeof(spinner[0]) - 1)
                        spinner_idx = 0;
        }
 } /* obexapp_event_progress */
Index: main.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/main.c,v
retrieving revision 1.14
diff -u -r1.14 main.c
--- main.c      20 Aug 2009 21:57:18 -0000      1.14
+++ main.c      19 Oct 2010 17:42:08 -0000
@@ -249,8 +249,7 @@
        argv += optind;
 
        if (!context.server) {
-               if (memcmp(&context.raddr, NG_HCI_BDADDR_ANY,
-                               sizeof(context.raddr)) == 0)
+               if (bdaddr_any(&context.raddr))
                        errx(1, "Must specify server BD_ADDR"); 
 
                /* Check channel, if was not set then obtain it via SDP */
Index: obexapp.h
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/obexapp.h,v
retrieving revision 1.10
diff -u -r1.10 obexapp.h
--- obexapp.h   20 Aug 2009 21:57:18 -0000      1.10
+++ obexapp.h   19 Oct 2010 17:51:05 -0000
@@ -110,6 +110,8 @@
        /* stream file descriptor and buffer */
        int                      sfd;
        uint8_t                 *sbuffer;
+       size_t                   stotal;
+       time_t                   stime;
 
        int                      mtu;            /* OBEX MTU */
 
Index: stream.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/stream.c,v
retrieving revision 1.9
diff -u -r1.9 stream.c
--- stream.c    9 Apr 2009 23:16:31 -0000       1.9
+++ stream.c    19 Oct 2010 17:52:03 -0000
@@ -34,7 +34,9 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <obex.h>
+#include <stdio.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 
 #include "compat.h"
@@ -79,6 +81,8 @@
 
                close(context->sfd);
                context->sfd = -1;
+       } else {
+               context->stotal += length;
        }
 } /* obexapp_stream_write */
 
@@ -224,6 +228,26 @@
                return;
        }
 
+       context->stotal += length;
        log_debug("%s(): Wrote %d bytes of stream data", __func__, length);
 } /* obexapp_stream_read */
 
+void
+obexapp_stream_stats_reset(context_t *context)
+{
+       context->stotal = 0;
+       context->stime = time(NULL);
+}
+
+void
+obexapp_stream_stats_print(context_t *context)
+{
+       int tm;
+
+       tm = (int)(time(NULL) - context->stime);
+       printf("%zu bytes streamed in %d second%s",
+           context->stotal, tm, (tm == 1 ? "" : "s"));
+       if (tm > 1)
+               printf(" (%zu bytes/sec)", context->stotal / tm);
+       printf("\n");
+}
Index: stream.h
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/stream.h,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 stream.h
--- stream.h    10 Feb 2003 03:28:03 -0000      1.1.1.1
+++ stream.h    19 Oct 2010 17:51:05 -0000
@@ -35,5 +35,8 @@
 obexapp_event_handler_t        obexapp_stream_write;
 obexapp_event_handler_t        obexapp_stream_read;
 
+void obexapp_stream_stats_reset(context_t *);
+void obexapp_stream_stats_print(context_t *);
+
 #endif /* _STREAM_H_ */
 
Index: transport.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/transport.c,v
retrieving revision 1.14
diff -u -r1.14 transport.c
--- transport.c 20 Aug 2009 21:57:18 -0000      1.14
+++ transport.c 19 Oct 2010 17:37:22 -0000
@@ -358,6 +358,10 @@
 
                return (n);
        }
+       if (n == 0) {
+               log_info("%s(): Connection closed", __func__);
+               return (-1);
+       }
 
        log_debug("%s(): Got %d bytes", __func__, n);
 
Index: util.c
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/util.c,v
retrieving revision 1.16
diff -u -r1.16 util.c
--- util.c      8 Jan 2010 18:31:22 -0000       1.16
+++ util.c      19 Oct 2010 17:38:37 -0000
@@ -288,14 +288,14 @@
  * Read upto buffer_length bytes into the buffer from the file descriptor fd
  */
 
-int
-obexapp_util_read(int fd, uint8_t *buffer, int buffer_length)
+ssize_t
+obexapp_util_read(int fd, uint8_t *buffer, size_t buffer_length)
 {
-       int     length;
+       ssize_t length;
 
 again:
        length = read(fd, buffer, buffer_length);
-       if (length < 0 && errno == EINTR)
+       if (length == -1 && errno == EINTR)
                goto again;
 
        return (length);
@@ -305,15 +305,16 @@
  * Write buffer_length bytes from the buffer to the descriptor fd
  */
 
-int
-obexapp_util_write(int fd, uint8_t const *buffer, int buffer_length)
+ssize_t
+obexapp_util_write(int fd, uint8_t const *buffer, size_t buffer_length)
 {
-       int     wrote, size;
+       ssize_t size;
+       size_t wrote;
 
        wrote = 0;
        while (wrote < buffer_length) {
                size = write(fd, buffer + wrote, buffer_length - wrote);
-               if (size < 0) {
+               if (size == -1) {
                        if (errno == EINTR)
                                continue;
 
Index: util.h
===================================================================
RCS file: /usr/local/cvs/ports/obexapp/util.h,v
retrieving revision 1.9
diff -u -r1.9 util.h
--- util.h      8 Jan 2010 18:31:22 -0000       1.9
+++ util.h      19 Oct 2010 17:38:37 -0000
@@ -39,8 +39,8 @@
 int obexapp_util_locale_from_utf16be(uint8_t const *src, size_t srclen, char 
*dst, size_t dstlen);
 int obexapp_util_locale_to_utf16be(char const *src, size_t srclen, uint8_t 
*dst, size_t dstlen);
 
-int obexapp_util_read(int fd, uint8_t *buffer, int buffer_length);
-int obexapp_util_write(int fd, uint8_t const *buffer, int buffer_length);
+ssize_t obexapp_util_read(int fd, uint8_t *buffer, size_t buffer_length);
+ssize_t obexapp_util_write(int fd, uint8_t const *buffer, size_t 
buffer_length);
 int obexapp_util_display_folder_listing(char const *ls);
 char * obexapp_util_gets(char const *prompt, char *buffer, int buffer_size);
 char * obexapp_util_strsep(char **sp, char const *delim);
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bluetooth
To unsubscribe, send any mail to "[email protected]"

Reply via email to