xref: /trafficserver/iocore/eventsystem/P_VIO.h (revision dc0fb99b)
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
VIO(int aop)28 VIO::VIO(int aop) : op(aop), buffer(), mutex(nullptr) {}
29 
30 TS_INLINE
VIO()31 VIO::VIO() : buffer(), mutex(nullptr) {}
32 
33 TS_INLINE Continuation *
get_continuation() const34 VIO::get_continuation() const
35 {
36   return cont;
37 }
38 
39 TS_INLINE void
set_writer(MIOBuffer * writer)40 VIO::set_writer(MIOBuffer *writer)
41 {
42   buffer.writer_for(writer);
43 }
44 
45 TS_INLINE void
set_reader(IOBufferReader * reader)46 VIO::set_reader(IOBufferReader *reader)
47 {
48   buffer.reader_for(reader);
49 }
50 
51 TS_INLINE MIOBuffer *
get_writer() const52 VIO::get_writer() const
53 {
54   return buffer.writer();
55 }
56 
57 TS_INLINE IOBufferReader *
get_reader() const58 VIO::get_reader() const
59 {
60   return (buffer.reader());
61 }
62 
63 TS_INLINE int64_t
ntodo() const64 VIO::ntodo() const
65 {
66   return nbytes - ndone;
67 }
68 
69 TS_INLINE void
done()70 VIO::done()
71 {
72   if (buffer.reader()) {
73     nbytes = ndone + buffer.reader()->read_avail();
74   } else {
75     nbytes = ndone;
76   }
77 }
78 
79 TS_INLINE void
set_continuation(Continuation * acont)80 VIO::set_continuation(Continuation *acont)
81 {
82   if (vc_server) {
83     vc_server->set_continuation(this, acont);
84   }
85   if (acont) {
86     mutex = acont->mutex;
87     cont  = acont;
88   } else {
89     mutex = nullptr;
90     cont  = nullptr;
91   }
92   return;
93 }
94 
95 TS_INLINE void
reenable()96 VIO::reenable()
97 {
98   this->_disabled = false;
99   if (vc_server) {
100     vc_server->reenable(this);
101   }
102 }
103 
104 TS_INLINE void
reenable_re()105 VIO::reenable_re()
106 {
107   this->_disabled = false;
108   if (vc_server) {
109     vc_server->reenable_re(this);
110   }
111 }
112 
113 TS_INLINE void
disable()114 VIO::disable()
115 {
116   this->_disabled = true;
117 }
118 
119 TS_INLINE bool
is_disabled() const120 VIO::is_disabled() const
121 {
122   return this->_disabled;
123 }
124