From 12f6ffd15214634f97f2bb9c5e35bb1f74cf546b Mon Sep 17 00:00:00 2001
From: Tiago Lam <tiagolam@gmail.com>
Date: Wed, 5 Feb 2020 22:35:50 +0000
Subject: [PATCH] platform/redox: Support AF_UNIX in socket.

To add support for UNIX sockets (AF_UNIX), of SOCK_STREAM type, the
"chan:" scheme is used, which will be supportedby the ipcd running in
userspace.

Later commits add similar AF_UNIX support for the rest of the methods in
impl PalSocket.
---
 src/platform/redox/socket.rs | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/platform/redox/socket.rs b/src/platform/redox/socket.rs
index 56aa5532c..bf9785455 100644
--- a/src/platform/redox/socket.rs
+++ b/src/platform/redox/socket.rs
@@ -292,7 +292,7 @@ impl PalSocket for Sys {
     }
 
     unsafe fn socket(domain: c_int, mut kind: c_int, protocol: c_int) -> c_int {
-        if domain != AF_INET {
+        if domain != AF_INET && domain != AF_UNIX {
             errno = syscall::EAFNOSUPPORT;
             return -1;
         }
@@ -313,9 +313,10 @@ impl PalSocket for Sys {
 
         // The tcp: and udp: schemes allow using no path,
         // and later specifying one using `dup`.
-        match kind {
-            SOCK_STREAM => e(syscall::open("tcp:", flags)) as c_int,
-            SOCK_DGRAM => e(syscall::open("udp:", flags)) as c_int,
+        match (domain, kind) {
+            (AF_INET, SOCK_STREAM) => e(syscall::open("tcp:", flags)) as c_int,
+            (AF_INET, SOCK_DGRAM) => e(syscall::open("udp:", flags)) as c_int,
+            (AF_UNIX, SOCK_STREAM) => e(syscall::open("chan:", flags | O_CREAT)) as c_int,
             _ => {
                 errno = syscall::EPROTONOSUPPORT;
                 -1
-- 
GitLab