fd/create: Add socket flags

This is completely interoperable with old code and allows us to create
non-blocking sockets in a single syscall.

Change-Id: I0d4184ae82ae5decd2f548528dd647190b2ac709
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/include-fd/stdplus/fd/create.hpp b/include-fd/stdplus/fd/create.hpp
index 8488b20..f96479b 100644
--- a/include-fd/stdplus/fd/create.hpp
+++ b/include-fd/stdplus/fd/create.hpp
@@ -69,6 +69,24 @@
     Stream = SOCK_STREAM,
 };
 
+enum class SocketFlag : int
+{
+    CloseOnExec = O_CLOEXEC,
+    NonBlock = O_NONBLOCK,
+};
+
+class SocketFlags : public BitFlags<SocketFlag>
+{
+  public:
+    constexpr SocketFlags(SocketType type) :
+        BitFlags<SocketFlag>(static_cast<int>(type))
+    {}
+
+    constexpr SocketFlags(BitFlags<SocketFlag> flags) :
+        BitFlags<SocketFlag>(flags)
+    {}
+};
+
 enum class SocketProto : int
 {
     ICMP = IPPROTO_ICMP,
@@ -78,7 +96,7 @@
     UDP = IPPROTO_UDP,
 };
 
-DupableFd socket(SocketDomain domain, SocketType type, SocketProto protocol);
+DupableFd socket(SocketDomain domain, SocketFlags flags, SocketProto protocol);
 
 } // namespace fd
 } // namespace stdplus
diff --git a/src/fd/create.cpp b/src/fd/create.cpp
index e39965f..59ec859 100644
--- a/src/fd/create.cpp
+++ b/src/fd/create.cpp
@@ -18,10 +18,10 @@
                     std::format("open `{}`", pathname.c_str())));
 }
 
-DupableFd socket(SocketDomain domain, SocketType type, SocketProto protocol)
+DupableFd socket(SocketDomain domain, SocketFlags flags, SocketProto protocol)
 {
     return DupableFd(
-        CHECK_ERRNO(::socket(static_cast<int>(domain), static_cast<int>(type),
+        CHECK_ERRNO(::socket(static_cast<int>(domain), static_cast<int>(flags),
                              static_cast<int>(protocol)),
                     "socket"));
 }