allow command to accept "--" separator
[folly.git] / folly / SocketAddress.h
index 06c698839be0cea3654c41eeb39cdd1c7a3ffba5..bfa5042cdbc8a025d274deecf88ecd1f9e6588a4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2014-present Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -47,8 +47,7 @@ class SocketAddress {
    *        This is potentially a very slow operation, so is disabled by
    *        default.
    */
-  SocketAddress(const char* host, uint16_t port,
-                 bool allowNameLookup = false) {
+  SocketAddress(const char* host, uint16_t port, bool allowNameLookup = false) {
     // Initialize the address family first,
     // since setFromHostPort() and setFromIpPort() will check it.
 
@@ -59,8 +58,10 @@ class SocketAddress {
     }
   }
 
-  SocketAddress(const std::string& host, uint16_t port,
-                 bool allowNameLookup = false) {
+  SocketAddress(
+      const std::string& host,
+      uint16_t port,
+      bool allowNameLookup = false) {
     // Initialize the address family first,
     // since setFromHostPort() and setFromIpPort() will check it.
 
@@ -305,6 +306,19 @@ class SocketAddress {
     setFromPath(StringPiece{path, length});
   }
 
+  /**
+   * Construct a SocketAddress from a local unix socket path.
+   *
+   * Raises std::invalid_argument on error.
+   *
+   * @param path The Unix domain socket path.
+   */
+  static SocketAddress makeFromPath(StringPiece path) {
+    SocketAddress addr;
+    addr.setFromPath(path);
+    return addr;
+  }
+
   /**
    * Initialize this SocketAddress from a socket's peer address.
    *
@@ -342,8 +356,7 @@ class SocketAddress {
    *                 enough for the full address type required by
    *                 address->sa_family.
    */
-  void setFromSockaddr(const struct sockaddr* address,
-                       socklen_t addrlen);
+  void setFromSockaddr(const struct sockaddr* address, socklen_t addrlen);
 
   /**
    * Initialize this SocketAddress from a struct sockaddr_in.
@@ -367,9 +380,7 @@ class SocketAddress {
    *                 the valid bytes of sun_path, not including any NUL
    *                 terminator.
    */
-  void setFromSockaddr(const struct sockaddr_un* address,
-                       socklen_t addrlen);
-
+  void setFromSockaddr(const struct sockaddr_un* address, socklen_t addrlen);
 
   /**
    * Fill in a given sockaddr_storage with the ip or unix address.
@@ -445,8 +456,7 @@ class SocketAddress {
    * Return true if this is an IPv4-mapped IPv6 address.
    */
   bool isIPv4Mapped() const {
-    return (getFamily() == AF_INET6 &&
-            storage_.addr.isIPv4Mapped());
+    return (getFamily() == AF_INET6 && storage_.addr.isIPv4Mapped());
   }
 
   /**
@@ -540,7 +550,7 @@ class SocketAddress {
    * the heap.
    */
   struct ExternalUnixAddr {
-    struct sockaddr_un *addr;
+    struct sockaddr_unaddr;
     socklen_t len;
 
     socklen_t pathLength() const {
@@ -552,12 +562,12 @@ class SocketAddress {
       addr->sun_family = AF_UNIX;
       len = 0;
     }
-    void init(const ExternalUnixAddr &other) {
+    void init(const ExternalUnixAddrother) {
       addr = new struct sockaddr_un;
       len = other.len;
       memcpy(addr, other.addr, size_t(len));
     }
-    void copy(const ExternalUnixAddr &other) {
+    void copy(const ExternalUnixAddrother) {
       len = other.len;
       memcpy(addr, other.addr, size_t(len));
     }
@@ -572,7 +582,7 @@ class SocketAddress {
   void setFromLocalAddr(const struct addrinfo* results);
   void setFromSocket(int socket, int (*fn)(int, struct sockaddr*, socklen_t*));
   std::string getIpString(int flags) const;
-  void getIpString(char *buf, size_t buflen, int flags) const;
+  void getIpString(charbuf, size_t buflen, int flags) const;
 
   void updateUnixAddressLength(socklen_t addrlen);
 
@@ -603,18 +613,15 @@ class SocketAddress {
 size_t hash_value(const SocketAddress& address);
 
 std::ostream& operator<<(std::ostream& os, const SocketAddress& addr);
-
-}
+} // namespace folly
 
 namespace std {
 
 // Provide an implementation for std::hash<SocketAddress>
 template <>
 struct hash<folly::SocketAddress> {
-  size_t operator()(
-      const folly::SocketAddress& addr) const {
+  size_t operator()(const folly::SocketAddress& addr) const {
     return addr.hash();
   }
 };
-
-}
+} // namespace std