obexapp print stream statistics after transfer

Maksim Yevmenkin maksim.yevmenkin at gmail.com
Tue Oct 19 18:19:43 UTC 2010


Hi Iain,

thanks for all the patches! could you please try the combined patch
(attached) and make sure it still works for you?

thanks,
mas
-------------- next part --------------
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	19 Oct 2010 17:33:58 -0000
@@ -137,7 +137,7 @@
 		static uint32_t	spinner_idx = 0;
 
 		printf("%c\b", spinner[spinner_idx ++]);
-		if (spinner_idx >= sizeof(spinner)/sizeof(spinner[0]))
+		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);


More information about the freebsd-bluetooth mailing list