linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] unit/test-sdp: Avoid extra copies when sending a PDU
@ 2019-01-11 14:18 Luiz Augusto von Dentz
  2019-01-11 14:18 ` [PATCH BlueZ 2/2] unit: Fix fsanitize-address-use-after-scope with GCC 9 Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2019-01-11 14:18 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Make use of writev instead of creating a separate buffer to transmit
the data.
---
 unit/test-sdp.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/unit/test-sdp.c b/unit/test-sdp.c
index 5a50cbbf1..66da038cd 100644
--- a/unit/test-sdp.c
+++ b/unit/test-sdp.c
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <sys/socket.h>
+#include <sys/uio.h>
 
 #include <glib.h>
 
@@ -191,31 +192,23 @@ static gboolean send_pdu(gpointer user_data)
 {
 	struct context *context = user_data;
 	const struct sdp_pdu *req_pdu;
-	uint16_t pdu_len;
-	unsigned char *buf;
+	struct iovec iov[2];
 	ssize_t len;
 
 	req_pdu = &context->data->pdu_list[context->pdu_offset];
 
-	pdu_len = req_pdu->raw_size + context->cont_size;
+	iov[0].iov_base = (void *) req_pdu->raw_data;
+	iov[0].iov_len = req_pdu->raw_size;
 
-	buf = g_malloc0(pdu_len);
+	iov[1].iov_base = context->cont_data;
+	iov[1].iov_len = context->cont_size;
 
-	memcpy(buf, req_pdu->raw_data, req_pdu->raw_size);
+	if (context->cont_size && context->cont_size != req_pdu->cont_len)
+		put_be16(req_pdu->cont_len, iov[1].iov_base + 4);
 
-	if (context->cont_size > 0) {
-		memcpy(buf + req_pdu->raw_size, context->cont_data,
-						context->cont_size);
-		if (context->cont_size != req_pdu->cont_len)
-			put_be16(req_pdu->cont_len,
-					buf + req_pdu->raw_size + 4);
-	}
-
-	len = write(context->fd, buf, pdu_len);
-
-	g_free(buf);
+	len = writev(context->fd, iov, 2);
 
-	g_assert(len == pdu_len);
+	g_assert(len == (ssize_t) (iov[0].iov_len + iov[1].iov_len));
 
 	return FALSE;
 }
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-11 14:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-11 14:18 [PATCH BlueZ 1/2] unit/test-sdp: Avoid extra copies when sending a PDU Luiz Augusto von Dentz
2019-01-11 14:18 ` [PATCH BlueZ 2/2] unit: Fix fsanitize-address-use-after-scope with GCC 9 Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).