1 *29d079c9SBrooks Davis /*
2 *29d079c9SBrooks Davis * Copyright (c) 2016 Boris Astardzhiev, Smartcom-Bulgaria AD
3 *29d079c9SBrooks Davis * All rights reserved.
4 *29d079c9SBrooks Davis *
5 *29d079c9SBrooks Davis * Redistribution and use in source and binary forms, with or without
6 *29d079c9SBrooks Davis * modification, are permitted provided that the following conditions
7 *29d079c9SBrooks Davis * are met:
8 *29d079c9SBrooks Davis * 1. Redistributions of source code must retain the above copyright
9 *29d079c9SBrooks Davis * notice(s), this list of conditions and the following disclaimer as
10 *29d079c9SBrooks Davis * the first lines of this file unmodified other than the possible
11 *29d079c9SBrooks Davis * addition of one or more copyright notices.
12 *29d079c9SBrooks Davis * 2. Redistributions in binary form must reproduce the above copyright
13 *29d079c9SBrooks Davis * notice(s), this list of conditions and the following disclaimer in
14 *29d079c9SBrooks Davis * the documentation and/or other materials provided with the
15 *29d079c9SBrooks Davis * distribution.
16 *29d079c9SBrooks Davis *
17 *29d079c9SBrooks Davis * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
18 *29d079c9SBrooks Davis * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 *29d079c9SBrooks Davis * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 *29d079c9SBrooks Davis * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE
21 *29d079c9SBrooks Davis * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 *29d079c9SBrooks Davis * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 *29d079c9SBrooks Davis * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 *29d079c9SBrooks Davis * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 *29d079c9SBrooks Davis * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 *29d079c9SBrooks Davis * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 *29d079c9SBrooks Davis * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *29d079c9SBrooks Davis */
29 *29d079c9SBrooks Davis
30 *29d079c9SBrooks Davis #include <sys/types.h>
31 *29d079c9SBrooks Davis #include <sys/socket.h>
32 *29d079c9SBrooks Davis #include "libc_private.h"
33 *29d079c9SBrooks Davis
34 *29d079c9SBrooks Davis ssize_t
sendmmsg(int s,struct mmsghdr * __restrict msgvec,size_t vlen,int flags)35 *29d079c9SBrooks Davis sendmmsg(int s, struct mmsghdr *__restrict msgvec, size_t vlen, int flags)
36 *29d079c9SBrooks Davis {
37 *29d079c9SBrooks Davis size_t i, sent;
38 *29d079c9SBrooks Davis ssize_t ret;
39 *29d079c9SBrooks Davis
40 *29d079c9SBrooks Davis sent = 0;
41 *29d079c9SBrooks Davis for (i = 0; i < vlen; i++, sent++) {
42 *29d079c9SBrooks Davis ret = __sys_sendmsg(s, &msgvec[i].msg_hdr, flags);
43 *29d079c9SBrooks Davis if (ret == -1) {
44 *29d079c9SBrooks Davis if (sent != 0) {
45 *29d079c9SBrooks Davis /*
46 *29d079c9SBrooks Davis * We have sent messages. Let caller
47 *29d079c9SBrooks Davis * know about the data sent, socket
48 *29d079c9SBrooks Davis * error is returned on next
49 *29d079c9SBrooks Davis * invocation.
50 *29d079c9SBrooks Davis */
51 *29d079c9SBrooks Davis return (sent);
52 *29d079c9SBrooks Davis }
53 *29d079c9SBrooks Davis return (ret);
54 *29d079c9SBrooks Davis }
55 *29d079c9SBrooks Davis
56 *29d079c9SBrooks Davis /* Save sent bytes. */
57 *29d079c9SBrooks Davis msgvec[i].msg_len = ret;
58 *29d079c9SBrooks Davis }
59 *29d079c9SBrooks Davis
60 *29d079c9SBrooks Davis return (sent);
61 *29d079c9SBrooks Davis }
62