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 NetAccept.h 00027 00028 00029 NetAccept is a generalized facility which allows 00030 Connections of different classes to be accepted either 00031 from a blockable thread or by adaptive polling. 00032 00033 It is used by the NetProcessor and the ClusterProcessor 00034 and should be considered PRIVATE to processor implementations. 00035 00036 00037 00038 ****************************************************************************/ 00039 #ifndef __P_NETACCEPT_H__ 00040 #define __P_NETACCEPT_H__ 00041 00042 #include "libts.h" 00043 #include "P_Connection.h" 00044 00045 00046 struct NetAccept; 00047 class Event; 00048 // 00049 // Default accept function 00050 // Accepts as many connections as possible, returning the number accepted 00051 // or -1 to stop accepting. 00052 // 00053 typedef int (AcceptFunction) (NetAccept * na, void *e, bool blockable); 00054 typedef AcceptFunction *AcceptFunctionPtr; 00055 AcceptFunction net_accept; 00056 00057 class UnixNetVConnection; 00058 00059 // TODO fix race between cancel accept and call back 00060 struct NetAcceptAction:public Action, public RefCountObj 00061 { 00062 Server *server; 00063 00064 void cancel(Continuation * cont = NULL) { 00065 Action::cancel(cont); 00066 server->close(); 00067 } 00068 00069 Continuation *operator =(Continuation * acont) 00070 { 00071 return Action::operator=(acont); 00072 } 00073 00074 ~NetAcceptAction() { 00075 Debug("net_accept", "NetAcceptAction dying\n"); 00076 } 00077 }; 00078 00079 00080 // 00081 // NetAccept 00082 // Handles accepting connections. 00083 // 00084 struct NetAccept:public Continuation 00085 { 00086 ink_hrtime period; 00087 Server server; 00088 void *alloc_cache; 00089 AcceptFunctionPtr accept_fn; 00090 int ifd; 00091 bool callback_on_open; 00092 bool backdoor; 00093 Ptr<NetAcceptAction> action_; 00094 int recv_bufsize; 00095 int send_bufsize; 00096 uint32_t sockopt_flags; 00097 uint32_t packet_mark; 00098 uint32_t packet_tos; 00099 EventType etype; 00100 UnixNetVConnection *epoll_vc; // only storage for epoll events 00101 EventIO ep; 00102 00103 virtual EventType getEtype() const; 00104 virtual NetProcessor * getNetProcessor() const; 00105 00106 void init_accept_loop(const char *); 00107 virtual void init_accept(EThread * t = NULL); 00108 virtual void init_accept_per_thread(); 00109 virtual NetAccept *clone() const; 00110 // 0 == success 00111 int do_listen(bool non_blocking, bool transparent = false); 00112 00113 int do_blocking_accept(EThread * t); 00114 virtual int acceptEvent(int event, void *e); 00115 virtual int acceptFastEvent(int event, void *e); 00116 int acceptLoopEvent(int event, Event * e); 00117 void cancel(); 00118 00119 NetAccept(); 00120 virtual ~ NetAccept() 00121 { 00122 action_ = NULL; 00123 }; 00124 }; 00125 00126 00127 #endif