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