xref: /trafficserver/iocore/eventsystem/P_VIO.h (revision 9c09dbc1)
1 /** @file
2 
3   A brief file description
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #pragma once
25 #include "I_VIO.h"
26 
27 TS_INLINE
28 VIO::VIO(int aop) : op(aop), buffer(), mutex(nullptr) {}
29 
30 /////////////////////////////////////////////////////////////
31 //
32 //  VIO::VIO()
33 //
34 /////////////////////////////////////////////////////////////
35 TS_INLINE
36 VIO::VIO() : buffer(), mutex(nullptr) {}
37 
38 TS_INLINE Continuation *
39 VIO::get_continuation()
40 {
41   return cont;
42 }
43 TS_INLINE void
44 VIO::set_writer(MIOBuffer *writer)
45 {
46   buffer.writer_for(writer);
47 }
48 TS_INLINE void
49 VIO::set_reader(IOBufferReader *reader)
50 {
51   buffer.reader_for(reader);
52 }
53 TS_INLINE MIOBuffer *
54 VIO::get_writer()
55 {
56   return buffer.writer();
57 }
58 TS_INLINE IOBufferReader *
59 VIO::get_reader()
60 {
61   return (buffer.reader());
62 }
63 TS_INLINE int64_t
64 VIO::ntodo()
65 {
66   return nbytes - ndone;
67 }
68 TS_INLINE void
69 VIO::done()
70 {
71   if (buffer.reader()) {
72     nbytes = ndone + buffer.reader()->read_avail();
73   } else {
74     nbytes = ndone;
75   }
76 }
77 
78 /////////////////////////////////////////////////////////////
79 //
80 //  VIO::set_continuation()
81 //
82 /////////////////////////////////////////////////////////////
83 TS_INLINE void
84 VIO::set_continuation(Continuation *acont)
85 {
86   if (vc_server) {
87     vc_server->set_continuation(this, acont);
88   }
89   if (acont) {
90     mutex = acont->mutex;
91     cont  = acont;
92   } else {
93     mutex = nullptr;
94     cont  = nullptr;
95   }
96   return;
97 }
98 
99 /////////////////////////////////////////////////////////////
100 //
101 //  VIO::reenable()
102 //
103 /////////////////////////////////////////////////////////////
104 TS_INLINE void
105 VIO::reenable()
106 {
107   this->_disabled = false;
108   if (vc_server) {
109     vc_server->reenable(this);
110   }
111 }
112 
113 /////////////////////////////////////////////////////////////
114 //
115 //  VIO::reenable_re()
116 //
117 /////////////////////////////////////////////////////////////
118 TS_INLINE void
119 VIO::reenable_re()
120 {
121   this->_disabled = false;
122   if (vc_server) {
123     vc_server->reenable_re(this);
124   }
125 }
126 
127 TS_INLINE void
128 VIO::disable()
129 {
130   this->_disabled = true;
131 }
132 
133 TS_INLINE bool
134 VIO::is_disabled()
135 {
136   return this->_disabled;
137 }
138