libcutils: add multi-buffer socket send.
Unix and Windows both have functions to write multiple buffers to a
socket with a single call but they have very different signatures. This
CL creates some cross-platform functions to be able to perform these
operations in a uniform way, which will be required for upcoming
fastboot functionality.
This CL also fixes some inconsistent spacing in the touched files.
Bug: http://b/26558551
Change-Id: I8f14d52d3a1de1f3b464267666d6cd3b54263238
diff --git a/libcutils/sockets_windows.c b/libcutils/sockets_windows.c
index 1bf2933..8153688 100644
--- a/libcutils/sockets_windows.c
+++ b/libcutils/sockets_windows.c
@@ -58,3 +58,22 @@
return setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout_ms,
sizeof(timeout_ms));
}
+
+cutils_socket_buffer_t make_cutils_socket_buffer(void* data, size_t length) {
+ cutils_socket_buffer_t buffer;
+ buffer.buf = data;
+ buffer.len = length;
+ return buffer;
+}
+
+ssize_t socket_send_buffers(cutils_socket_t sock,
+ cutils_socket_buffer_t* buffers,
+ size_t num_buffers) {
+ DWORD bytes_sent = 0;
+
+ if (WSASend(sock, buffers, num_buffers, &bytes_sent, 0, NULL, NULL) !=
+ SOCKET_ERROR) {
+ return bytes_sent;
+ }
+ return -1;
+}