commit 41744ce653238bcc8e4db96133efa728b00a9605
parent 0b68a9ec9421a9319e3adc57b1f35858d172156a
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 19 Jun 2021 10:48:08 -0400
net::unix: make to_native private
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 20 insertions(+), 29 deletions(-)
diff --git a/net/unix/+linux.ha b/net/unix/+linux.ha
@@ -7,35 +7,6 @@ use rt;
use strings;
use types;
-// Converts a UNIX socket address to a native sockaddr.
-export fn to_native(addr: addr) (rt::sockaddr | invalid) = {
- // sun_path should be null-terminated and fit into rt::UNIX_PATH_MAX
- if (len(addr) > rt::UNIX_PATH_MAX - 1) {
- return invalid;
- };
- let ret = rt::sockaddr {
- un = rt::sockaddr_un {
- sun_family = rt::AF_UNIX,
- ...
- }
- };
- match ((&addr: *types::string).data) {
- null => void,
- data: *[*]u8 => rt::memcpy(&ret.un.sun_path, data, len(addr)),
- };
- ret.un.sun_path[len(addr)] = 0;
- return ret;
-};
-
-// Converts a native sockaddr to a UNIX socket address. The return value is
-// borrowed from the input.
-export fn from_native(a: rt::sockaddr) addr = {
- return switch (a.in.sin_family) {
- rt::AF_UNIX => strings::fromc(&a.un.sun_path[0]),
- * => abort("Wrong address family!"),
- };
-};
-
// Opens a UNIX socket connection to the path. Blocks until the
// connection is established.
export fn connect(
@@ -71,3 +42,23 @@ export fn listen(
fd = sockfd,
}): *net::listener;
};
+
+// Converts a UNIX socket address to a native sockaddr.
+fn to_native(addr: addr) (rt::sockaddr | invalid) = {
+ // sun_path should be null-terminated and fit into rt::UNIX_PATH_MAX
+ if (len(addr) > rt::UNIX_PATH_MAX - 1) {
+ return invalid;
+ };
+ let ret = rt::sockaddr {
+ un = rt::sockaddr_un {
+ sun_family = rt::AF_UNIX,
+ ...
+ }
+ };
+ match ((&addr: *types::string).data) {
+ null => void,
+ data: *[*]u8 => rt::memcpy(&ret.un.sun_path, data, len(addr)),
+ };
+ ret.un.sun_path[len(addr)] = 0;
+ return ret;
+};