+ iov[1].iov_base = *data;
+ iov[1].iov_len = peek_header.size;
+
+ msg.msg_iovlen++;
+ }
+
+ result = recvmsg(sock, &msg, MSG_WAITALL);
+ if (result < 0) {
+ free(*data);
+ PERROR("recvmsg failed");
+ }
+
+ return result;
+}
+
+/* returns 1 to indicate a message was received
+ * returns 0 to indicate no message was received (end of stream)
+ * returns -1 to indicate an error
+ */
+int ustcomm_recv_fd(int sock,
+ struct ustcomm_header *header,
+ char *data, int *fd)
+{
+ int result;
+ struct ustcomm_header peek_header;
+ struct iovec iov[2];
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ char buf[CMSG_SPACE(sizeof(int))];
+
+ result = recv(sock, &peek_header, sizeof(peek_header),
+ MSG_PEEK | MSG_WAITALL);
+ if (result <= 0) {
+ if(errno == ECONNRESET) {
+ return 0;
+ } else if (errno == EINTR) {
+ return -1;
+ } else if (result < 0) {
+ PERROR("recv");