1 /* Copyright (C) 2010-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <sys/socket.h>
20 #include <socketcall.h>
23 recvmmsg_syscall (int fd
, struct mmsghdr
*vmessages
, unsigned int vlen
,
24 int flags
, struct __timespec64
*timeout
)
26 #ifndef __NR_recvmmsg_time64
27 # define __NR_recvmmsg_time64 __NR_recvmmsg
29 int r
= SYSCALL_CANCEL (recvmmsg_time64
, fd
, vmessages
, vlen
, flags
,
31 #ifndef __ASSUME_TIME64_SYSCALLS
32 if (r
>= 0 || errno
!= ENOSYS
)
35 struct timespec ts32
, *pts32
= NULL
;
38 if (! in_int32_t_range (timeout
->tv_sec
))
43 ts32
= valid_timespec64_to_timespec (*timeout
);
47 # ifdef __ASSUME_RECVMMSG_SYSCALL
48 r
= SYSCALL_CANCEL (recvmmsg
, fd
, vmessages
, vlen
, flags
, pts32
);
50 r
= SOCKETCALL_CANCEL (recvmmsg
, fd
, vmessages
, vlen
, flags
, pts32
);
55 *timeout
= valid_timespec_to_timespec64 (ts32
);
62 __recvmmsg64 (int fd
, struct mmsghdr
*vmessages
, unsigned int vlen
, int flags
,
63 struct __timespec64
*timeout
)
66 socklen_t csize
[IOV_MAX
];
69 for (int i
= 0; i
< vlen
; i
++)
70 csize
[i
] = vmessages
[i
].msg_hdr
.msg_controllen
;
73 int r
= recvmmsg_syscall (fd
, vmessages
, vlen
, flags
, timeout
);
77 for (int i
=0; i
< r
; i
++)
78 __convert_scm_timestamps (&vmessages
[i
].msg_hdr
, csize
[i
]);
84 libc_hidden_def (__recvmmsg64
)
87 __recvmmsg (int fd
, struct mmsghdr
*vmessages
, unsigned int vlen
, int flags
,
88 struct timespec
*timeout
)
90 struct __timespec64 ts64
, *pts64
= NULL
;
93 ts64
= valid_timespec_to_timespec64 (*timeout
);
96 int r
= recvmmsg_syscall (fd
, vmessages
, vlen
, flags
, pts64
);
97 if (r
>= 0 && timeout
!= NULL
)
98 /* The remanining timeout will be always less the input TIMEOUT. */
99 *timeout
= valid_timespec64_to_timespec (ts64
);
103 weak_alias (__recvmmsg
, recvmmsg
)