1 /** @file
2 
3   Internal SDK stuff
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 #if !defined(__GNUC__)
26 #include "I_EventSystem.h"
27 #include "I_Cache.h"
28 #include "I_Net.h"
29 #else
30 #include "P_EventSystem.h"
31 #include "P_Cache.h"
32 #include "P_Net.h"
33 #endif
34 
35 enum INKContInternalMagic_t {
36   INKCONT_INTERN_MAGIC_ALIVE = 0x00009631,
37   INKCONT_INTERN_MAGIC_DEAD  = 0xDEAD9631,
38 };
39 
40 class INKContInternal : public DummyVConnection
41 {
42 public:
43   INKContInternal();
44   INKContInternal(TSEventFunc funcp, TSMutex mutexp);
45 
46   void init(TSEventFunc funcp, TSMutex mutexp, void *context = 0);
47   virtual void destroy();
48 
49   void handle_event_count(int event);
50   int handle_event(int event, void *edata);
51 
52 protected:
53   virtual void clear();
54   virtual void free();
55 
56 public:
57   void *mdata;
58   TSEventFunc m_event_func;
59   int m_event_count;
60   int m_closed;
61   int m_deletable;
62   int m_deleted;
63   void *m_context;
64   // INKqa07670: Nokia memory leak bug fix
65   INKContInternalMagic_t m_free_magic;
66 };
67 
68 class INKVConnInternal : public INKContInternal
69 {
70 public:
71   INKVConnInternal();
72   INKVConnInternal(TSEventFunc funcp, TSMutex mutexp);
73 
74   void destroy() override;
75 
76   VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf) override;
77 
78   VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner = false) override;
79 
80   void do_io_transform(VConnection *vc);
81 
82   void do_io_close(int lerrno = -1) override;
83 
84   void do_io_shutdown(ShutdownHowTo_t howto) override;
85 
86   void reenable(VIO *vio) override;
87 
88   void retry(unsigned int delay);
89 
90   bool get_data(int id, void *data) override;
91   bool set_data(int id, void *data) override;
92 
93 protected:
94   void clear() override;
95   void free() override;
96 
97 public:
98   VIO m_read_vio;
99   VIO m_write_vio;
100   VConnection *m_output_vc;
101 };
102 
103 /****************************************************************
104  *  IMPORTANT - READ ME
105  * Any plugin using the IO Core must enter
106  *   with a held mutex.  SDK 1.0, 1.1 & 2.0 did not
107  *   have this restriction so we need to add a mutex
108  *   to Plugin's Continuation if it trys to use the IOCore
109  * Not only does the plugin have to have a mutex
110  *   before entering the IO Core.  The mutex needs to be held.
111  *   We now take out the mutex on each call to ensure it is
112  *   held for the entire duration of the IOCore call
113  ***************************************************************/
114 #define FORCE_PLUGIN_SCOPED_MUTEX(_c)         \
115   sdk_assert(((INKContInternal *)_c)->mutex); \
116   SCOPED_MUTEX_LOCK(ml, ((INKContInternal *)_c)->mutex, this_ethread());
117 
118 #ifdef __cplusplus
119 extern "C" {
120 #endif /* __cplusplus */
121 
122 TSReturnCode sdk_sanity_check_mutex(TSMutex);
123 TSReturnCode sdk_sanity_check_hostlookup_structure(TSHostLookupResult);
124 TSReturnCode sdk_sanity_check_iocore_structure(void *);
125 
126 /* ----------------------------------------------------------------------
127  *
128  * Interfaces for Raft project
129  *
130  * ---------------------------------------------------------------------- */
131 
132 tsapi TSMutex TSMutexCreateInternal(void);
133 tsapi int TSMutexCheck(TSMutex mutex);
134 
135 /* IOBuffer */
136 tsapi int64_t TSIOBufferBlockDataSizeGet(TSIOBufferBlock blockp);
137 tsapi void TSIOBufferBlockDestroy(TSIOBufferBlock blockp);
138 typedef void *INKUDPPacket;
139 typedef void *INKUDPacketQueue;
140 typedef void *INKUDPConn;
141 /* ===== UDP Connections ===== */
142 /****************************************************************************
143  *  contact: OXYGEN
144  ****************************************************************************/
145 tsapi TSAction INKUDPBind(TSCont contp, unsigned int ip, int port);
146 
147 /****************************************************************************
148  *  contact: OXYGEN
149  ****************************************************************************/
150 tsapi TSAction INKUDPSendTo(TSCont contp, INKUDPConn udp, unsigned int ip, int port, char *buf, int len);
151 
152 /****************************************************************************
153  *  contact: OXYGEN
154  ****************************************************************************/
155 tsapi TSAction INKUDPRecvFrom(TSCont contp, INKUDPConn udp);
156 
157 /****************************************************************************
158  *  Return file descriptor.
159  *  contact: OXYGEN
160  ****************************************************************************/
161 tsapi int INKUDPConnFdGet(INKUDPConn udp);
162 
163 /* ===== UDP Packet ===== */
164 /****************************************************************************
165  *  contact: OXYGEN
166  ****************************************************************************/
167 tsapi INKUDPPacket INKUDPPacketCreate();
168 
169 /****************************************************************************
170  *  contact: OXYGEN
171  ****************************************************************************/
172 tsapi TSIOBufferBlock INKUDPPacketBufferBlockGet(INKUDPPacket packet);
173 
174 /****************************************************************************
175  *  contact: OXYGEN
176  ****************************************************************************/
177 tsapi unsigned int INKUDPPacketFromAddressGet(INKUDPPacket packet);
178 
179 /****************************************************************************
180  *  contact: OXYGEN
181  ****************************************************************************/
182 tsapi int INKUDPPacketFromPortGet(INKUDPPacket packet);
183 
184 /****************************************************************************
185  *  contact: OXYGEN
186  ****************************************************************************/
187 tsapi INKUDPConn INKUDPPacketConnGet(INKUDPPacket packet);
188 
189 /****************************************************************************
190  *  contact: OXYGEN
191  ****************************************************************************/
192 tsapi void INKUDPPacketDestroy(INKUDPPacket packet);
193 
194 /* ===== Packet Queue ===== */
195 /****************************************************************************
196  *  contact: OXYGEN
197  ****************************************************************************/
198 tsapi INKUDPPacket INKUDPPacketGet(INKUDPacketQueue queuep);
199 
200 #ifdef __cplusplus
201 }
202 #endif /* __cplusplus */
203