Skip to content

Commit f6b4c34

Browse files
[libc] Add functions to send/recv messages (#106467)
This patch adds the necessary functions to send and receive messages over a socket. Those functions are: recv, recvfrom, recvmsg, send, sendto, sendmsg, and socketpair for testing.
1 parent c3fe727 commit f6b4c34

37 files changed

+1422
-84
lines changed

libc/config/linux/api.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ def SysSocketAPI : PublicAPI<"sys/socket.h"> {
193193
"socklen_t",
194194
"struct sockaddr",
195195
"struct sockaddr_un",
196+
"struct msghdr",
197+
"struct iovec",
198+
"size_t",
199+
"ssize_t",
196200
];
197201
}
198202

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,14 @@ if(LLVM_LIBC_FULL_BUILD)
10411041
libc.src.sys.select.select
10421042

10431043
# sys/socket.h entrypoints
1044-
libc.src.sys.socket.bind
10451044
libc.src.sys.socket.socket
1045+
libc.src.sys.socket.socketpair
1046+
libc.src.sys.socket.send
1047+
libc.src.sys.socket.sendto
1048+
libc.src.sys.socket.sendmsg
1049+
libc.src.sys.socket.recv
1050+
libc.src.sys.socket.recvfrom
1051+
libc.src.sys.socket.recvmsg
10461052
)
10471053
endif()
10481054

libc/hdr/types/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,30 @@ add_proxy_header_library(
199199
libc.include.setjmp
200200
)
201201

202+
203+
add_proxy_header_library(
204+
struct_msghdr
205+
HDRS
206+
struct_msghdr.h
207+
FULL_BUILD_DEPENDS
208+
libc.include.llvm-libc-types.struct_msghdr
209+
libc.include.sys_socket
210+
)
211+
212+
add_proxy_header_library(
213+
struct_sockaddr
214+
HDRS
215+
struct_sockaddr.h
216+
FULL_BUILD_DEPENDS
217+
libc.include.llvm-libc-types.struct_sockaddr
218+
libc.include.sys_socket
219+
)
220+
221+
add_proxy_header_library(
222+
socklen_t
223+
HDRS
224+
socklen_t.h
225+
FULL_BUILD_DEPENDS
226+
libc.include.llvm-libc-types.socklen_t
227+
libc.include.sys_socket
228+
)

libc/hdr/types/socklen_t.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Proxy for socklen_t -----------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef LLVM_LIBC_HDR_TYPES_SOCKLEN_T_H
9+
#define LLVM_LIBC_HDR_TYPES_SOCKLEN_T_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/socklen_t.h"
14+
15+
#else
16+
17+
#include <signal.h>
18+
19+
#endif // LIBC_FULL_BUILD
20+
21+
#endif // LLVM_LIBC_HDR_TYPES_SOCKLEN_T_H

libc/hdr/types/ssize_t.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- Proxy for ssize_t -------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef LLVM_LIBC_HDR_TYPES_SSIZE_T_H
9+
#define LLVM_LIBC_HDR_TYPES_SSIZE_T_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/ssize_t.h"
14+
15+
#else
16+
17+
#define __need_ssize_t
18+
#include <stddef.h>
19+
#undef __need_ssize_t
20+
21+
#endif // LIBC_FULL_BUILD
22+
23+
#endif // LLVM_LIBC_HDR_TYPES_SSIZE_T_H

libc/hdr/types/struct_msghdr.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Proxy for struct msghdr ------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_MSGHDR_H
9+
#define LLVM_LIBC_HDR_TYPES_STRUCT_MSGHDR_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/struct_msghdr.h"
14+
15+
#else
16+
17+
#include <sys/socket.h>
18+
19+
#endif // LIBC_FULL_BUILD
20+
21+
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_MSGHDR_H

libc/hdr/types/struct_sockaddr.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Proxy for struct sockaddr ----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_SOCKADDR_H
9+
#define LLVM_LIBC_HDR_TYPES_STRUCT_SOCKADDR_H
10+
11+
#ifdef LIBC_FULL_BUILD
12+
13+
#include "include/llvm-libc-types/struct_sockaddr.h"
14+
15+
#else
16+
17+
#include <sys/socket.h>
18+
19+
#endif // LIBC_FULL_BUILD
20+
21+
#endif // LLVM_LIBC_HDR_TYPES_STRUCT_SOCKADDR_H

libc/include/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,8 @@ add_header_macro(
593593
.llvm-libc-macros.sys_socket_macros
594594
.llvm-libc-types.sa_family_t
595595
.llvm-libc-types.socklen_t
596+
.llvm-libc-types.struct_iovec
597+
.llvm-libc-types.struct_msghdr
596598
.llvm-libc-types.struct_sockaddr
597599
.llvm-libc-types.struct_sockaddr_un
598600
)

libc/include/llvm-libc-types/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ add_header(
117117
add_header(wint_t HDR wint_t.h)
118118
add_header(sa_family_t HDR sa_family_t.h)
119119
add_header(socklen_t HDR socklen_t.h)
120-
add_header(struct_sockaddr_un HDR struct_sockaddr_un.h)
121-
add_header(struct_sockaddr HDR struct_sockaddr.h)
120+
add_header(struct_sockaddr_un HDR struct_sockaddr_un.h DEPENDS .sa_family_t)
121+
add_header(struct_sockaddr HDR struct_sockaddr.h DEPENDS .sa_family_t)
122+
add_header(struct_iovec HDR struct_iovec.h DEPENDS .size_t)
123+
add_header(struct_msghdr HDR struct_msghdr.h DEPENDS .size_t .socklen_t .struct_iovec)
122124
add_header(rpc_opcodes_t HDR rpc_opcodes_t.h)
123125
add_header(ACTION HDR ACTION.h)
124126
add_header(ENTRY HDR ENTRY.h)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Definition of struct iovec ----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_TYPES_STRUCT_IOVEC_H
10+
#define LLVM_LIBC_TYPES_STRUCT_IOVEC_H
11+
12+
#include "size_t.h"
13+
14+
struct iovec {
15+
void *iov_base;
16+
size_t iov_len;
17+
};
18+
19+
#endif // LLVM_LIBC_TYPES_STRUCT_IOVEC_H

0 commit comments

Comments
 (0)