• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

InkAPIPrivateIOCore.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   Internal SDK stuff
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 #ifndef __INK_API_PRIVATE_IOCORE_H__
00025 #define __INK_API_PRIVATE_IOCORE_H__
00026 #include "ts.h"
00027 #if !defined(__GNUC__)
00028 #include "I_EventSystem.h"
00029 #include "I_Cache.h"
00030 #include "I_Net.h"
00031 #else
00032 #include "P_EventSystem.h"
00033 #include "P_Cache.h"
00034 #include "P_Net.h"
00035 #endif
00036 
00037 enum INKContInternalMagic_t
00038 {
00039   INKCONT_INTERN_MAGIC_ALIVE = 0x00009631,
00040   INKCONT_INTERN_MAGIC_DEAD = 0xDEAD9631
00041 };
00042 
00043 class INKContInternal:public DummyVConnection
00044 {
00045 public:
00046   INKContInternal();
00047   INKContInternal(TSEventFunc funcp, TSMutex mutexp);
00048 
00049   void init(TSEventFunc funcp, TSMutex mutexp);
00050   virtual void destroy();
00051 
00052   void handle_event_count(int event);
00053   int handle_event(int event, void *edata);
00054 
00055 public:
00056   void *mdata;
00057   TSEventFunc m_event_func;
00058   volatile int m_event_count;
00059   volatile int m_closed;
00060   int m_deletable;
00061   int m_deleted;
00062   //INKqa07670: Nokia memory leak bug fix
00063   INKContInternalMagic_t m_free_magic;
00064 };
00065 
00066 class INKVConnInternal:public INKContInternal
00067 {
00068 public:
00069   INKVConnInternal();
00070   INKVConnInternal(TSEventFunc funcp, TSMutex mutexp);
00071 
00072   void init(TSEventFunc funcp, TSMutex mutexp);
00073   virtual void destroy();
00074 
00075   int handle_event(int event, void *edata);
00076 
00077   VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf);
00078 
00079   VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner = false);
00080 
00081   void do_io_transform(VConnection *vc);
00082 
00083   void do_io_close(int lerrno = -1);
00084 
00085   void do_io_shutdown(ShutdownHowTo_t howto);
00086 
00087   void reenable(VIO *vio);
00088 
00089   void retry(unsigned int delay);
00090 
00091   bool get_data(int id, void *data);
00092   bool set_data(int id, void *data);
00093 
00094 public:
00095     VIO m_read_vio;
00096   VIO m_write_vio;
00097   VConnection *m_output_vc;
00098 };
00099 
00100 /****************************************************************
00101  *  IMPORTANT - READ ME
00102  * Any plugin using the IO Core must enter
00103  *   with a held mutex.  SDK 1.0, 1.1 & 2.0 did not
00104  *   have this restriction so we need to add a mutex
00105  *   to Plugin's Continuation if it trys to use the IOCore
00106  * Not only does the plugin have to have a mutex
00107  *   before entering the IO Core.  The mutex needs to be held.
00108  *   We now take out the mutex on each call to ensure it is
00109  *   held for the entire duration of the IOCore call
00110  ***************************************************************/
00111 
00112 //
00113 // FORCE_PLUGIN_MUTEX -- define 'UNSAFE_FORCE_MUTEX' if you
00114 // do *not* want the locking macro to be thread safe.
00115 // Otherwise, access during 'null-mutex' case will be serialized
00116 // in a locking manner (too bad for the net threads).
00117 //
00118 
00119 
00120 #define UNSAFE_FORCE_MUTEX
00121 
00122 #ifdef UNSAFE_FORCE_MUTEX
00123 #define LOCK_MONGO_MUTEX
00124 #define UNLOCK_MONGO_MUTEX
00125 #define MUX_WARNING(p) \
00126 TSDebug ("sdk","(SDK) null mutex detected in critical region (mutex created)"); \
00127 TSDebug ("sdk","(SDK) please create continuation [%p] with mutex", (p));
00128 #else
00129 static ink_mutex big_mux;
00130 
00131 #define MUX_WARNING(p) 1
00132 #define LOCK_MONGO_MUTEX   ink_mutex_acquire (&big_mux)
00133 #define UNLOCK_MONGO_MUTEX ink_mutex_release (&big_mux)
00134 #endif
00135 
00136 #define FORCE_PLUGIN_MUTEX(_c) \
00137   MutexLock ml; \
00138   LOCK_MONGO_MUTEX; \
00139   if (( (INKContInternal*)_c)->mutex == NULL) { \
00140       ( (INKContInternal*)_c)->mutex = new_ProxyMutex(); \
00141       UNLOCK_MONGO_MUTEX; \
00142       MUX_WARNING(_c); \
00143       MUTEX_SET_AND_TAKE_LOCK(ml, ((INKContInternal*)_c)->mutex, this_ethread()); \
00144   } else { \
00145       UNLOCK_MONGO_MUTEX; \
00146       MUTEX_SET_AND_TAKE_LOCK(ml, ((INKContInternal*)_c)->mutex, this_ethread()); \
00147   }
00148 
00149 #ifdef __cplusplus
00150 extern "C"
00151 {
00152 #endif                          /* __cplusplus */
00153 
00154   TSReturnCode sdk_sanity_check_mutex(TSMutex);
00155   TSReturnCode sdk_sanity_check_hostlookup_structure(TSHostLookupResult);
00156   TSReturnCode sdk_sanity_check_iocore_structure(void *);
00157 
00158 /* ----------------------------------------------------------------------
00159  *
00160  * Interfaces for Raft project
00161  *
00162  * ---------------------------------------------------------------------- */
00163 
00164   tsapi TSMutex TSMutexCreateInternal(void);
00165   tsapi int TSMutexCheck(TSMutex mutex);
00166 
00167 
00168 /* IOBuffer */
00169   tsapi void TSIOBufferReaderCopy(TSIOBufferReader readerp, const void *buf, int64_t length);
00170   tsapi int64_t TSIOBufferBlockDataSizeGet(TSIOBufferBlock blockp);
00171   tsapi void TSIOBufferBlockDestroy(TSIOBufferBlock blockp);
00172   typedef void *INKUDPPacket;
00173   typedef void *INKUDPacketQueue;
00174   typedef void *INKUDPConn;
00175 /* ===== UDP Connections ===== */
00176 /****************************************************************************
00177  *  contact: OXYGEN
00178  ****************************************************************************/
00179   tsapi TSAction INKUDPBind(TSCont contp, unsigned int ip, int port);
00180 
00181 /****************************************************************************
00182  *  contact: OXYGEN
00183  ****************************************************************************/
00184   tsapi TSAction INKUDPSendTo(TSCont contp, INKUDPConn udp, unsigned int ip, int port, char *buf, int len);
00185 
00186 /****************************************************************************
00187  *  contact: OXYGEN
00188  ****************************************************************************/
00189   tsapi TSAction INKUDPRecvFrom(TSCont contp, INKUDPConn udp);
00190 
00191 /****************************************************************************
00192  *  Return file descriptor.
00193  *  contact: OXYGEN
00194  ****************************************************************************/
00195   tsapi int INKUDPConnFdGet(INKUDPConn udp);
00196 
00197 /* ===== UDP Packet ===== */
00198 /****************************************************************************
00199  *  contact: OXYGEN
00200  ****************************************************************************/
00201   tsapi INKUDPPacket INKUDPPacketCreate();
00202 
00203 /****************************************************************************
00204  *  contact: OXYGEN
00205  ****************************************************************************/
00206   tsapi TSIOBufferBlock INKUDPPacketBufferBlockGet(INKUDPPacket packet);
00207 
00208 /****************************************************************************
00209  *  contact: OXYGEN
00210  ****************************************************************************/
00211   tsapi unsigned int INKUDPPacketFromAddressGet(INKUDPPacket packet);
00212 
00213 /****************************************************************************
00214  *  contact: OXYGEN
00215  ****************************************************************************/
00216   tsapi int INKUDPPacketFromPortGet(INKUDPPacket packet);
00217 
00218 /****************************************************************************
00219  *  contact: OXYGEN
00220  ****************************************************************************/
00221   tsapi INKUDPConn INKUDPPacketConnGet(INKUDPPacket packet);
00222 
00223 /****************************************************************************
00224  *  contact: OXYGEN
00225  ****************************************************************************/
00226   tsapi void INKUDPPacketDestroy(INKUDPPacket packet);
00227 
00228 /* ===== Packet Queue ===== */
00229 /****************************************************************************
00230  *  contact: OXYGEN
00231  ****************************************************************************/
00232   tsapi INKUDPPacket INKUDPPacketGet(INKUDPacketQueue queuep);
00233 
00234 #ifdef __cplusplus
00235 }
00236 #endif                          /* __cplusplus */
00237 
00238 #endif                          /* __INK_API_PRIVATE_IOCORE_H__ */

Generated by  doxygen 1.7.1