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 // include files 00026 //------------------------------------------------------------------------- 00027 00028 #include "libts.h" 00029 #include "P_EventSystem.h" 00030 00031 #include "Log.h" 00032 #include "LogCollationAccept.h" 00033 #include "LogCollationHostSM.h" 00034 00035 //------------------------------------------------------------------------- 00036 // LogCollationAccept::LogCollationAccept 00037 //------------------------------------------------------------------------- 00038 00039 LogCollationAccept::LogCollationAccept(int port) 00040 : Continuation(new_ProxyMutex()), 00041 m_port(port), 00042 m_pending_event(NULL) 00043 { 00044 NetProcessor::AcceptOptions opt; 00045 SET_HANDLER((LogCollationAcceptHandler) & LogCollationAccept::accept_event); 00046 // work around for iocore problem where _pre_fetch_buffer can get 00047 // appended to itself if multiple do_io_reads are called requesting 00048 // small amounts of data. Most arguments are default except for the 00049 // last one which we will set to true. 00050 // [amc] That argument is ignored so I dropped it. 00051 opt.local_port = m_port; 00052 opt.ip_family = AF_INET; 00053 opt.accept_threads = 0; 00054 m_accept_action = netProcessor.accept(this, opt); 00055 ink_assert(NULL != m_accept_action); 00056 } 00057 00058 //------------------------------------------------------------------------- 00059 // LogCollationAccept::~LogCollationAccept 00060 //------------------------------------------------------------------------- 00061 00062 LogCollationAccept::~LogCollationAccept() 00063 { 00064 Debug("log-collation", "LogCollationAccept::~LogCollationAccept"); 00065 00066 // stop the netProcessor 00067 if (m_accept_action) { 00068 m_accept_action->cancel(); 00069 m_accept_action = NULL; 00070 00071 Debug("log-collation", "closing Log::collation_accept_file_descriptor " 00072 "(%d)", Log::collation_accept_file_descriptor); 00073 if (::close(Log::collation_accept_file_descriptor) < 0) { 00074 Error("error closing collate listen file descriptor [%d]: %s", 00075 Log::collation_accept_file_descriptor, strerror(errno)); 00076 } else { 00077 Log::collation_accept_file_descriptor = NO_FD; 00078 } 00079 } else { 00080 ink_assert(!"[ERROR] m_accept_action is NULL"); 00081 } 00082 00083 // stop the eventProcessor 00084 // ... but what if there's more than one pending? 00085 if (m_pending_event && (m_pending_event != ACTION_RESULT_DONE)) { 00086 m_pending_event->cancel(); 00087 } 00088 } 00089 00090 //------------------------------------------------------------------------- 00091 // LogCollationAccept::accept_event 00092 //------------------------------------------------------------------------- 00093 00094 int 00095 LogCollationAccept::accept_event(int event, NetVConnection * net_vc) 00096 { 00097 LogCollationHostSM *sm; 00098 00099 switch (event) { 00100 case NET_EVENT_ACCEPT: 00101 sm = new LogCollationHostSM(net_vc); 00102 ink_assert(NULL != sm); 00103 break; 00104 00105 default: 00106 ink_assert(!"[ERROR] Unexpected Event"); 00107 00108 } 00109 00110 return EVENT_CONT; 00111 }