| 250 | */ |
| 251 | template <typename AddressType> |
| 252 | class Socket |
| 253 | { |
| 254 | public: |
| 255 | static_assert( |
| 256 | std::is_convertible<AddressType, network::Address>::value, |
| 257 | "Requires type convertible to `network::Address`"); |
| 258 | |
| 259 | /** |
| 260 | * Returns an instance of a `Socket` using the specified kind of |
| 261 | * implementation. |
| 262 | * |
| 263 | * @param s Optional. The file descriptor to wrap with the `Socket`. |
| 264 | * @param kind Optional. The desired `Socket` implementation. |
| 265 | * |
| 266 | * @return An instance of a `Socket`. |
| 267 | */ |
| 268 | static Try<Socket> create( |
| 269 | int_fd s, |
| 270 | SocketImpl::Kind kind = SocketImpl::DEFAULT_KIND()) |
| 271 | { |
| 272 | Try<std::shared_ptr<SocketImpl>> impl = SocketImpl::create(s, kind); |
| 273 | if (impl.isError()) { |
| 274 | return Error(impl.error()); |
| 275 | } |
| 276 | return Socket(impl.get()); |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * Returns an instance of a `Socket` using `AddressType` to determine |
| 281 | * the address family to use. An optional implementation kind can be |
| 282 | * specified. The NONBLOCK and CLOEXEC options will be set on the |
| 283 | * underlying file descriptor for the socket. |
| 284 | * |
| 285 | * @param kind Optional. The desired `Socket` implementation. |
| 286 | * |
| 287 | * @return An instance of a `Socket`. |
| 288 | */ |
| 289 | // TODO(josephw): MESOS-5729: Consider making the CLOEXEC option |
| 290 | // configurable by the caller of the interface. |
| 291 | static Try<Socket> create(SocketImpl::Kind kind = SocketImpl::DEFAULT_KIND()); |
| 292 | |
| 293 | /** |
| 294 | * Returns an instance of a `Socket` using the specified |
| 295 | * `Address::Family` to determine the address family to use. An |
| 296 | * optional implementation kind can be specified. The NONBLOCK and |
| 297 | * CLOEXEC options will be set on the underlying file descriptor for |
| 298 | * the socket. |
| 299 | * |
| 300 | * NOTE: this is only defined for `AddressType` of |
| 301 | * `network::Address`, all others are explicitly deleted. |
| 302 | * |
| 303 | * @param kind Optional. The desired `Socket` implementation. |
| 304 | * |
| 305 | * @return An instance of a `Socket`. |
| 306 | */ |
| 307 | static Try<Socket> create( |
| 308 | Address::Family family, |
| 309 | SocketImpl::Kind kind = SocketImpl::DEFAULT_KIND()); |