• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

P_Connection.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /**************************************************************************
00025 
00026   Connection.h
00027   Description:
00028   struct Connection
00029   struct Server
00030   struct ConnectionManager
00031 
00032   struct ConnectionManager
00033   ========================
00034 
00035   struct ConnectionManager provides the interface for network or disk
00036   connections.  There is a global ConnectionManager in the system
00037   (connectionManager).
00038 
00039   Connection * connect()
00040   Connection * accept()
00041 
00042   The accept call is a blocking call while connect is non-blocking. They
00043   returns a new Connection instance which is an handle to the newly created
00044   connection. The connection `q instance can be used later for read/writes
00045   using an intance of IOProcessor class.
00046 
00047 
00048   **************************************************************************/
00049 
00050 #ifndef __CONNECTION_H__
00051 #define __CONNECTION_H__
00052 
00053 #include "libts.h"
00054 
00055 struct NetVCOptions;
00056 
00057 //
00058 // Defines
00059 //
00060 
00061 #define NON_BLOCKING_CONNECT     true
00062 #define BLOCKING_CONNECT         false
00063 #define CONNECT_WITH_TCP         true
00064 #define CONNECT_WITH_UDP         false
00065 #define NON_BLOCKING             true
00066 #define BLOCKING                 false
00067 #define BIND_RANDOM_PORT         true
00068 #define BIND_ANY_PORT            false
00069 #define ENABLE_MC_LOOPBACK       true
00070 #define DISABLE_MC_LOOPBACK      false
00071 #define BC_NO_CONNECT            true
00072 #define BC_CONNECT               false
00073 #define BC_NO_BIND               true
00074 #define BC_BIND                  false
00075 
00076 ///////////////////////////////////////////////////////////////////////
00077 //
00078 // Connection
00079 //
00080 ///////////////////////////////////////////////////////////////////////
00081 struct Connection
00082 {
00083   SOCKET fd; ///< Socket for connection.
00084   IpEndpoint addr; ///< Associated address.
00085   bool is_bound; ///< Flag for already bound to a local address.
00086   bool is_connected; ///< Flag for already connected.
00087   int sock_type;
00088 
00089   /** Create and initialize the socket for this connection.
00090 
00091       A socket is created and the options specified by @a opt are
00092       set. The socket is @b not connected.
00093 
00094       @note It is important to pass the same @a opt to this method and
00095       @c connect.
00096 
00097       @return 0 on success, -ERRNO on failure.
00098       @see connect
00099   */
00100   int open(
00101            NetVCOptions const& opt = DEFAULT_OPTIONS ///< Socket options.
00102            );
00103 
00104   /** Connect the socket.
00105 
00106       The socket is connected to the remote @a addr and @a port. The
00107       @a opt structure is used to control blocking on the socket. All
00108       other options are set via @c open. It is important to pass the
00109       same @a opt to this method as was passed to @c open.
00110 
00111       @return 0 on success, -ERRNO on failure.
00112       @see open
00113   */
00114   int connect(
00115            sockaddr const* to, ///< Remote address and port.
00116            NetVCOptions const& opt = DEFAULT_OPTIONS ///< Socket options
00117            );
00118 
00119 
00120   /// Set the internal socket address struct.
00121   /// @internal Used only by ICP.
00122   void setRemote(
00123     sockaddr const* remote_addr ///< Address and port.
00124   ) {
00125     ats_ip_copy(&addr, remote_addr);
00126   }
00127 
00128   int setup_mc_send(sockaddr const* mc_addr,
00129                     sockaddr const* my_addr,
00130                     bool non_blocking = NON_BLOCKING,
00131                     unsigned char mc_ttl = 1, bool mc_loopback = DISABLE_MC_LOOPBACK, Continuation * c = NULL);
00132 
00133   int setup_mc_receive(sockaddr const* from,
00134                        sockaddr const* my_addr,
00135                        bool non_blocking = NON_BLOCKING, Connection * sendchan = NULL, Continuation * c = NULL);
00136 
00137   int close();                  // 0 on success, -errno on failure
00138 
00139   void apply_options(NetVCOptions const& opt);
00140 
00141   virtual ~ Connection();
00142   Connection();
00143 
00144   /// Default options.
00145   static NetVCOptions const DEFAULT_OPTIONS;
00146 
00147 protected:
00148   void _cleanup();
00149 };
00150 
00151 ///////////////////////////////////////////////////////////////////////
00152 //
00153 // Server
00154 //
00155 ///////////////////////////////////////////////////////////////////////
00156 struct Server: public Connection
00157 {
00158   /// Client side (inbound) local IP address.
00159   IpEndpoint accept_addr;
00160 
00161   /// If set, the related incoming connect was transparent.
00162   bool f_inbound_transparent;
00163 
00164   /// If set, a kernel HTTP accept filter
00165   bool http_accept_filter;
00166 
00167   //
00168   // Use this call for the main proxy accept
00169   //
00170   int proxy_listen(bool non_blocking = false);
00171 
00172   int accept(Connection * c);
00173 
00174   //
00175   // Listen on a socket. We assume the port is in host by order, but
00176   // that the IP address (specified by accept_addr) has already been
00177   // converted into network byte order
00178   //
00179 
00180   int listen(bool non_blocking = false, int recv_bufsize = 0, int send_bufsize = 0, bool transparent = false);
00181   int setup_fd_for_listen(
00182     bool non_blocking = false,
00183     int recv_bufsize = 0,
00184     int send_bufsize = 0,
00185     bool transparent = false ///< Inbound transparent.
00186   );
00187 
00188   Server()
00189     : Connection()
00190     , f_inbound_transparent(false)
00191   {
00192     ink_zero(accept_addr);
00193   }
00194 };
00195 
00196 #endif /*_Connection_h*/

Generated by  doxygen 1.7.1