From 36242efceaa6dd0bbb90f5fc53820f2a05ae09c6 Mon Sep 17 00:00:00 2001
From: Adam Barth <abarth@chromium.org>
Date: Fri, 9 Nov 2018 15:21:15 -0800
Subject: [PATCH] [zxs] Remove inception.h

We still have protocol.h because the zxs-test needs the protocol
definition. Once NET-1865 is fixed, we'll be able to remove protocol.h
as well.

Also, removed a number of unused declarations from these headers.

Test: No behavior change
Change-Id: Ifeee4e3bfc3e0781e3cef28fb327836d9642904e
---
 system/ulib/zxs/include/lib/zxs/inception.h | 49 ---------------------
 system/ulib/zxs/include/lib/zxs/protocol.h  | 41 ++++++++++-------
 system/ulib/zxs/zxs.cpp                     | 11 ++++-
 system/utest/zxs/zxs-test.cpp               |  2 -
 4 files changed, 36 insertions(+), 67 deletions(-)
 delete mode 100644 system/ulib/zxs/include/lib/zxs/inception.h

diff --git a/system/ulib/zxs/include/lib/zxs/inception.h b/system/ulib/zxs/include/lib/zxs/inception.h
deleted file mode 100644
index 4873b11ce2b..00000000000
--- a/system/ulib/zxs/include/lib/zxs/inception.h
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2018 The Fuchsia Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef LIB_ZXS_INCEPTION_H_
-#define LIB_ZXS_INCEPTION_H_
-
-// This header will be removed once all the socket protocol code is refactored
-// from fdio to zxs.
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <zircon/compiler.h>
-#include <zircon/types.h>
-
-__BEGIN_CDECLS
-
-#define ZXSIO_PAYLOAD_SZ 900
-
-typedef struct zxsio_msg zxsio_msg_t;
-
-// TODO: most of these fields will end up unused. Figure out which are needed.
-// For now, we keep them to preserve the message header format of zxrio_msg
-// to make the conversion process easier.
-struct zxsio_msg {
-    zx_txid_t txid;                    // FIDL message header
-    uint32_t reserved0;
-    uint32_t flags;
-    uint32_t op;
-
-    uint32_t datalen;                  // size of data[]
-    int32_t arg;                       // tx: argument, rx: return value
-    union {
-        int64_t off;                   // tx/rx: offset where needed
-        uint32_t mode;                 // tx: Open
-        uint32_t protocol;             // rx: Open
-        uint32_t op;                   // tx: Ioctl
-    } arg2;
-    int32_t reserved1;
-    uint32_t hcount;                   // number of valid handles
-    zx_handle_t handle[4];             // up to 3 handles + reply channel handle
-    uint8_t data[ZXSIO_PAYLOAD_SZ];    // payload
-};
-
-#define ZXSIO_HDR_SZ       (__builtin_offsetof(zxsio_msg_t, data))
-
-__END_CDECLS
-
-#endif // LIB_ZXS_INCEPTION_H_
diff --git a/system/ulib/zxs/include/lib/zxs/protocol.h b/system/ulib/zxs/include/lib/zxs/protocol.h
index 82d7237379f..e34da65e1fe 100644
--- a/system/ulib/zxs/include/lib/zxs/protocol.h
+++ b/system/ulib/zxs/include/lib/zxs/protocol.h
@@ -14,11 +14,8 @@
 
 __BEGIN_CDECLS
 
-#define ZXSIO_ONE_HANDLE   0x00000100
-
 // SIO (Socket I/O)
 #define ZXSIO_CLOSE        0x00000001
-#define ZXSIO_OPEN        (0x00000003 | ZXSIO_ONE_HANDLE)
 #define ZXSIO_IOCTL        0x0000000a
 #define ZXSIO_CONNECT      0x00000010
 #define ZXSIO_BIND         0x00000011
@@ -28,10 +25,7 @@ __BEGIN_CDECLS
 #define ZXSIO_GETSOCKOPT   0x00000015
 #define ZXSIO_SETSOCKOPT   0x00000016
 
-#define ZXSIO_SOCKET_DIR_NONE   "none-v3"
-#define ZXSIO_SOCKET_DIR_SOCKET "socket-v3"
-
-// fdio signals
+// SIO signals
 #define ZXSIO_SIGNAL_INCOMING ZX_USER_SIGNAL_0
 #define ZXSIO_SIGNAL_OUTGOING ZX_USER_SIGNAL_1
 #define ZXSIO_SIGNAL_ERROR ZX_USER_SIGNAL_2
@@ -54,15 +48,32 @@ typedef struct zxrio_sockopt_req_reply {
     socklen_t optlen;
 } zxrio_sockopt_req_reply_t;
 
-// wire format for datagram messages
-typedef struct fdio_socket_msg {
-    struct sockaddr_storage addr;
-    socklen_t addrlen;
-    int32_t flags;
-    char data[1]; // variable size
-} fdio_socket_msg_t;
+#define ZXSIO_PAYLOAD_SZ 900
+
+// TODO: most of these fields will end up unused. Figure out which are needed.
+// For now, we keep them to preserve the message header format of zxrio_msg
+// to make the conversion process easier.
+typedef struct zxsio_msg {
+    zx_txid_t txid;                    // FIDL message header
+    uint32_t reserved0;
+    uint32_t flags;
+    uint32_t op;
+
+    uint32_t datalen;                  // size of data[]
+    int32_t arg;                       // tx: argument, rx: return value
+    union {
+        int64_t off;                   // tx/rx: offset where needed
+        uint32_t mode;                 // tx: Open
+        uint32_t protocol;             // rx: Open
+        uint32_t op;                   // tx: Ioctl
+    } arg2;
+    int32_t reserved1;
+    uint32_t hcount;                   // number of valid handles
+    zx_handle_t handle[4];             // up to 3 handles + reply channel handle
+    uint8_t data[ZXSIO_PAYLOAD_SZ];    // payload
+} zxsio_msg_t;
 
-#define FDIO_SOCKET_MSG_HEADER_SIZE offsetof(fdio_socket_msg_t, data)
+#define ZXSIO_HDR_SZ       (__builtin_offsetof(zxsio_msg_t, data))
 
 __END_CDECLS
 
diff --git a/system/ulib/zxs/zxs.cpp b/system/ulib/zxs/zxs.cpp
index c9d8dd91719..0e0135bc24a 100644
--- a/system/ulib/zxs/zxs.cpp
+++ b/system/ulib/zxs/zxs.cpp
@@ -4,7 +4,6 @@
 
 #include <fuchsia/net/c/fidl.h>
 #include <lib/zx/socket.h>
-#include <lib/zxs/inception.h>
 #include <lib/zxs/protocol.h>
 #include <lib/zxs/zxs.h>
 #include <stdlib.h>
@@ -13,6 +12,16 @@
 #include <zircon/device/ioctl.h>
 #include <zircon/syscalls.h>
 
+// wire format for datagram messages
+typedef struct fdio_socket_msg {
+    struct sockaddr_storage addr;
+    socklen_t addrlen;
+    int32_t flags;
+    char data[1]; // variable size
+} fdio_socket_msg_t;
+
+#define FDIO_SOCKET_MSG_HEADER_SIZE offsetof(fdio_socket_msg_t, data)
+
 static bool is_rio_message_valid(zxsio_msg_t* msg) {
     if ((msg->datalen > ZXSIO_PAYLOAD_SZ) ||
         (msg->hcount > 0)) {
diff --git a/system/utest/zxs/zxs-test.cpp b/system/utest/zxs/zxs-test.cpp
index 1b647bffa1d..d6f16ec30d5 100644
--- a/system/utest/zxs/zxs-test.cpp
+++ b/system/utest/zxs/zxs-test.cpp
@@ -6,7 +6,6 @@
 #include <lib/async-loop/loop.h>
 #include <lib/async/cpp/wait.h>
 #include <lib/zx/socket.h>
-#include <lib/zxs/inception.h>
 #include <lib/zxs/protocol.h>
 #include <lib/zxs/zxs.h>
 #include <string.h>
@@ -157,7 +156,6 @@ static zx_status_t handle_message(async_dispatcher_t* dispatcher,
         memcpy(reply.data, "abcd", reply.datalen);
         break;
     }
-    case ZXSIO_OPEN:
     default:
         return ZX_ERR_STOP;
     }
-- 
GitLab