libcutils/fastboot: improve multi-buffer write.

Fixes libcutils multi-buffer write interface to be more friendly and
hooks into it from the fastboot Socket class.

Bug: http://b/26558551
Change-Id: Ibb3a8428fc379755602de52722c1260f9e345bc0
diff --git a/include/cutils/sockets.h b/include/cutils/sockets.h
index cb9b3ff..783bd0b 100644
--- a/include/cutils/sockets.h
+++ b/include/cutils/sockets.h
@@ -30,15 +30,12 @@
 
 typedef int  socklen_t;
 typedef SOCKET cutils_socket_t;
-typedef WSABUF cutils_socket_buffer_t;
 
 #else
 
 #include <sys/socket.h>
-#include <sys/uio.h>
 
 typedef int cutils_socket_t;
-typedef struct iovec cutils_socket_buffer_t;
 #define INVALID_SOCKET (-1)
 
 #endif
@@ -144,21 +141,24 @@
  * on Windows. This can give significant speedup compared to calling send()
  * multiple times.
  *
- * Because Unix and Windows use different structs to hold buffers, we also
- * need a generic function to set up the buffers.
- *
  * Example usage:
- *   cutils_socket_buffer_t buffers[2] = {
- *       make_cutils_socket_buffer(data0, len0),
- *       make_cutils_socket_buffer(data1, len1)
- *   };
+ *   cutils_socket_buffer_t buffers[2] = { {data0, len0}, {data1, len1} };
  *   socket_send_buffers(sock, buffers, 2);
  *
+ * If you try to pass more than SOCKET_SEND_BUFFERS_MAX_BUFFERS buffers into
+ * this function it will return -1 without sending anything.
+ *
  * Returns the number of bytes written or -1 on error.
  */
-cutils_socket_buffer_t make_cutils_socket_buffer(void* data, size_t length);
+typedef struct {
+  const void* data;
+  size_t length;
+} cutils_socket_buffer_t;
+
+#define SOCKET_SEND_BUFFERS_MAX_BUFFERS 16
+
 ssize_t socket_send_buffers(cutils_socket_t sock,
-                            cutils_socket_buffer_t* buffers,
+                            const cutils_socket_buffer_t* buffers,
                             size_t num_buffers);
 
 /*