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

ProtoSM.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    ProtoSM.h
00027 
00028    Description:
00029       Common elements for protocol state machines
00030 
00031 
00032  ****************************************************************************/
00033 
00034 #ifndef _PROTO_SM_H_
00035 #define _PROTO_SM_H_
00036 
00037 template<class VCTentry, int max_entries> struct ProtoVCTable
00038 {
00039 public:
00040   ProtoVCTable();
00041   VCTentry vc_table[max_entries];
00042 
00043   VCTentry *new_entry();
00044   VCTentry *find_entry(VConnection *);
00045   VCTentry *find_entry(VIO *);
00046   void remove_entry(VCTentry *);
00047   void cleanup_entry(VCTentry *);
00048   void cleanup_all();
00049   bool is_table_clear();
00050 };
00051 
00052 template<class VCTentry, int max_entries> inline ProtoVCTable<VCTentry, max_entries>::ProtoVCTable()
00053 {
00054   memset(&vc_table, 0, sizeof(vc_table));
00055 }
00056 
00057 template<class VCTentry, int max_entries> inline VCTentry * ProtoVCTable<VCTentry, max_entries>::new_entry()
00058 {
00059   for (int i = 0; i < max_entries; i++) {
00060     if (vc_table[i].vc == NULL) {
00061       return vc_table + i;
00062     }
00063   }
00064 
00065   ink_release_assert(0);
00066   return NULL;
00067 }
00068 
00069 template<class VCTentry, int max_entries>
00070   inline VCTentry * ProtoVCTable<VCTentry, max_entries>::find_entry(VConnection * vc)
00071 {
00072   for (int i = 0; i < max_entries; i++) {
00073     if (vc_table[i].vc == vc) {
00074       return vc_table + i;
00075     }
00076   }
00077 
00078   return NULL;
00079 }
00080 
00081 template<class VCTentry, int max_entries>
00082   inline VCTentry * ProtoVCTable<VCTentry, max_entries>::find_entry(VIO * vio)
00083 {
00084   for (int i = 0; i < max_entries; i++) {
00085     if (vc_table[i].read_vio == vio || vc_table[i].write_vio == vio) {
00086       ink_assert(vc_table[i].vc != NULL);
00087       return vc_table + i;
00088     }
00089   }
00090 
00091   return NULL;
00092 }
00093 
00094 // bool ProtoVCTable::remove_entry(HttpVCEntry* e)
00095 //
00096 //    Deallocates all buffers from the associated
00097 //      entry and re-initializes it's other fields
00098 //      for reuse
00099 //
00100 template<class VCTentry, int max_entries>
00101   inline void ProtoVCTable<VCTentry, max_entries>::remove_entry(VCTentry * e)
00102 {
00103   ink_assert(e->vc == NULL || e->in_tunnel);
00104   if (e->read_buffer) {
00105     free_MIOBuffer(e->read_buffer);
00106   }
00107   if (e->write_buffer) {
00108     free_MIOBuffer(e->write_buffer);
00109   }
00110   memset(e, 0, sizeof(VCTentry));
00111 }
00112 
00113 // void ProtoVCTable::cleanup_entry(HttpVCEntry* e)
00114 //
00115 //    Closes the associate vc for the entry,
00116 //     and the call remove_entry
00117 //
00118 template<class VCTentry, int max_entries>
00119   inline void ProtoVCTable<VCTentry, max_entries>::cleanup_entry(VCTentry * e)
00120 {
00121 
00122   ink_assert(e->vc);
00123   if (e->in_tunnel == false) {
00124     e->vc->do_io_close();
00125     e->vc = NULL;
00126   }
00127   remove_entry(e);
00128 }
00129 
00130 template<class VCTentry, int max_entries> inline void ProtoVCTable<VCTentry, max_entries>::cleanup_all()
00131 {
00132   for (int i = 0; i < max_entries; i++) {
00133     if (vc_table[i].vc != NULL) {
00134       cleanup_entry(vc_table + i);
00135     }
00136   }
00137 }
00138 
00139 
00140 template<class VCTentry, int max_entries> inline bool ProtoVCTable<VCTentry, max_entries>::is_table_clear()
00141 {
00142   for (int i = 0; i < max_entries; i++) {
00143     if (vc_table[i].vc != NULL) {
00144       return false;
00145     }
00146   }
00147   return true;
00148 }
00149 
00150 #endif

Generated by  doxygen 1.7.1