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 #if !defined (I_VIO_h) 00026 #define I_VIO_h 00027 00028 #include "libts.h" 00029 #include "I_EventSystem.h" 00030 #if !defined(I_IOBuffer_h) 00031 #error "include I_IOBuffer.h" 00032 -- -include I_IOBuffer.h 00033 #endif 00034 #include "ink_apidefs.h" 00035 class Continuation; 00036 class VConnection; 00037 class IOVConnection; 00038 class MIOBuffer; 00039 class ProxyMutex; 00040 00041 /** 00042 Descriptor for an IO operation. 00043 00044 A VIO is a descriptor for an in progress IO operation. It is 00045 returned from do_io_read() and do_io_write() methods on VConnections. 00046 Through the VIO, the state machine can monitor the progress of 00047 an operation and reenable the operation when data becomes available. 00048 00049 The VIO operation represents several types of operations, and 00050 they can be identified through the 'op' member. It can take any 00051 of the following values: 00052 00053 <table> 00054 <tr> 00055 <td align="center"><b>Constant</b></td> 00056 <td align="center"><b>Meaning</b></td> 00057 </tr> 00058 <tr><td>READ</td><td>The VIO represents a read operation</td></tr> 00059 <tr><td>WRITE</td><td>The VIO represents a write operation</td></tr> 00060 <tr><td>CLOSE</td><td>The VIO represents the request to close the 00061 VConnection</td></tr> 00062 <tr><td>ABORT</td><td></td></tr> 00063 <tr><td>SHUTDOWN_READ</td><td></td></tr> 00064 <tr><td>SHUTDOWN_WRITE</td><td></td></tr> 00065 <tr><td>SHUTDOWN_READWRITE</td><td></td></tr> 00066 <tr><td>SEEK</td><td></td></tr> 00067 <tr><td>PREAD</td><td></td></tr> 00068 <tr><td>PWRITE</td><td></td></tr> 00069 <tr><td>STAT</td><td></td></tr> 00070 </table> 00071 00072 */ 00073 class VIO 00074 { 00075 public: 00076 ~VIO() 00077 { 00078 } 00079 00080 /** Interface for the VConnection that owns this handle. */ 00081 Continuation *get_continuation(); 00082 void set_continuation(Continuation * cont); 00083 00084 /** 00085 Set nbytes to be what is current available. 00086 00087 Interface to set nbytes to be ndone + buffer.reader()->read_avail() 00088 if a reader is set. 00089 */ 00090 void done(); 00091 00092 /** 00093 Determine the number of bytes remaining. 00094 00095 Convenience function to determine how many bytes the operation 00096 has remaining. 00097 00098 @return The number of bytes to be processed by the operation. 00099 00100 */ 00101 int64_t ntodo(); 00102 00103 ///////////////////// 00104 // buffer settings // 00105 ///////////////////// 00106 void set_writer(MIOBuffer * writer); 00107 void set_reader(IOBufferReader * reader); 00108 MIOBuffer *get_writer(); 00109 IOBufferReader *get_reader(); 00110 00111 /** 00112 Reenable the IO operation. 00113 00114 Interface that the state machine uses to reenable an I/O 00115 operation. Reenable tells the VConnection that more data is 00116 available for the operation and that it should try to continue 00117 the operation in progress. I/O operations become disabled when 00118 they can make no forward progress. For a read this means that 00119 it's buffer is full. For a write, that it's buffer is empty. 00120 If reenable is called and progress is still not possible, it 00121 is ignored and no events are generated. However, unnecessary 00122 reenables (ones where no progress can be made) should be avoided 00123 as they hurt system throughput and waste CPU. 00124 00125 */ 00126 inkcoreapi void reenable(); 00127 00128 /** 00129 Reenable the IO operation. 00130 00131 Interface that the state machine uses to reenable an I/O 00132 operation. Reenable tells the VConnection that more data is 00133 available for the operation and that it should try to continue 00134 the operation in progress. I/O operations become disabled when 00135 they can make no forward progress. For a read this means that 00136 it's buffer is full. For a write, that it's buffer is empty. 00137 If reenable is called and progress is still not possible, it 00138 is ignored and no events are generated. However, unnecessary 00139 reenables (ones where no progress can be made) should be avoided 00140 as they hurt system throughput and waste CPU. 00141 00142 */ 00143 inkcoreapi void reenable_re(); 00144 00145 VIO(int aop); 00146 VIO(); 00147 00148 enum 00149 { 00150 NONE = 0, READ, WRITE, CLOSE, ABORT, 00151 SHUTDOWN_READ, SHUTDOWN_WRITE, SHUTDOWN_READWRITE, 00152 SEEK, PREAD, PWRITE, STAT 00153 }; 00154 00155 public: 00156 00157 /** 00158 Continuation to callback. 00159 00160 Used by the VConnection to store who is the continuation to 00161 call with events for this operation. 00162 00163 */ 00164 Continuation * _cont; 00165 00166 /** 00167 Number of bytes to be done for this operation. 00168 00169 The total number of bytes this operation must complete. 00170 00171 */ 00172 int64_t nbytes; 00173 00174 /** 00175 Number of bytes already completed. 00176 00177 The number of bytes that already have been completed for the 00178 operation. Processor can update this value only if they hold 00179 the lock. 00180 00181 */ 00182 int64_t ndone; 00183 00184 /** 00185 Type of operation. 00186 00187 The type of operation that this VIO represents. 00188 00189 */ 00190 int op; 00191 00192 /** 00193 Provides access to the reader or writer for this operation. 00194 00195 Contains a pointer to the IOBufferReader if the operation is a 00196 write and a pointer to a MIOBuffer if the operation is a read. 00197 00198 */ 00199 MIOBufferAccessor buffer; 00200 00201 /** 00202 Internal backpointer to the VConnection for use in the reenable 00203 functions. 00204 00205 */ 00206 VConnection *vc_server; 00207 00208 /** 00209 Reference to the state machine's mutex. 00210 00211 Maintains a reference to the state machine's mutex to allow 00212 processors to safely lock the operation even if the state machine 00213 has closed the VConnection and deallocated itself. 00214 00215 */ 00216 Ptr<ProxyMutex> mutex; 00217 }; 00218 00219 #include "I_VConnection.h" 00220 #endif