Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00095
00096
00097
00098
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
00114
00115
00116
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