Home | History | Annotate | Download | only in flip_server
      1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_TOOLS_FLIP_SERVER_CREATE_LISTENER_H__
      6 #define NET_TOOLS_FLIP_SERVER_CREATE_LISTENER_H__
      7 #pragma once
      8 
      9 #include <iosfwd>
     10 #include <string>
     11 
     12 namespace net {
     13 
     14 void SetNonBlocking(int fd);
     15 
     16 // Summary:
     17 //   creates a socket for listening, and bind()s and listen()s it.
     18 // Args:
     19 //   host - hostname or numeric address, or empty-string if you want
     20 //          to bind to listen on all addresses
     21 //   port - a port number or service name. By service name I mean a
     22 //          -real- service name, not a Google service name. I'd suggest
     23 //          you just stick to a numeric representation like "80"
     24 //   is_numeric_host_address -
     25 //           if you know that the host address has already been looked-up,
     26 //           and will be provided in numeric form like "130.207.244.244",
     27 //           then you can set this to true, and it will save you the time
     28 //           of a DNS lookup.
     29 //   backlog - passed into listen. This is the number of pending incoming
     30 //             connections a socket which is listening may have acquired before
     31 //             the OS starts rejecting new incoming connections.
     32 //   reuseaddr - if true sets SO_REUSEADDR on the listening socket
     33 //   reuseport - if true sets SO_REUSEPORT on the listening socket
     34 //   wait_for_iface - A boolean indicating that CreateListeningSocket should
     35 //                    block until the interface that it will bind to has been
     36 //                    raised. This is intended for HA environments.
     37 //   disable_nagle - if true sets TCP_NODELAY on the listening socket.
     38 //   listen_fd - this will be assigned a positive value if the socket is
     39 //               successfully created, else it will be assigned -1.
     40 int CreateListeningSocket(const std::string& host,
     41                           const std::string& port,
     42                           bool is_numeric_host_address,
     43                           int backlog,
     44                           bool reuseaddr,
     45                           bool reuseport,
     46                           bool wait_for_iface,
     47                           bool disable_nagle,
     48                           int * listen_fd);
     49 
     50 int CreateConnectedSocket(int *connect_fd,
     51                           const std::string& host,
     52                           const std::string& port,
     53                           bool is_numeric_host_address,
     54                           bool disable_nagle);
     55 }  // namespace net
     56 
     57 #endif  // NET_TOOLS_FLIP_SERVER_CREATE_LISTENER_H__
     58 
     59