00001 00002 #ifndef OSCL_SOCKET_SERV_IMP_PV_H_INCLUDED 00003 #define OSCL_SOCKET_SERV_IMP_PV_H_INCLUDED 00004 00005 #include "oscl_socket_serv_imp_base.h" 00006 #include "oscl_socket_serv_imp_reqlist.h" 00007 #include "oscl_socket_tuneables.h" 00008 00009 00013 #if PV_SOCKET_SERVER_IS_THREAD 00014 #include "oscl_semaphore.h" 00015 #include "oscl_mutex.h" 00016 #else 00017 #include "oscl_scheduler_ao.h" 00018 #endif 00019 00020 class PVServiStats; 00021 00024 #if (PV_SOCKET_SERVER_IS_THREAD) 00025 class OsclSocketServI: public HeapBase, public OsclSocketServIBase 00026 #else 00027 class OsclSocketServI: public OsclTimerObject, public OsclSocketServIBase 00028 #endif 00029 { 00030 public: 00031 static OsclSocketServI* NewL(Oscl_DefAlloc &a); 00032 int32 Connect(uint32 aMessageSlots, bool aShareSession); 00033 void Close(bool); 00034 00035 //check if calling context is server thread. 00036 //in non-threaded implementation, will always return "true". 00037 bool IsServerThread(); 00038 00039 private: 00040 OsclSocketServI(Oscl_DefAlloc &a); 00041 ~OsclSocketServI(); 00042 void ConstructL(); 00043 00044 //socket request list. 00045 OsclSocketServRequestList iSockServRequestList; 00046 00047 #if PV_SOCKET_SERVER_SELECT_LOOPBACK_SOCKET 00048 //blocking select wakeup feature 00049 class LoopbackSocket 00050 { 00051 public: 00052 LoopbackSocket() 00053 { 00054 iEnable = false; 00055 iContainer = NULL; 00056 } 00057 bool iEnable; 00058 void Read(); 00059 void ProcessSelect(TOsclSocket&); 00060 void Init(OsclSocketServI* aContainer); 00061 void Cleanup(); 00062 void Write(); 00063 #if PV_OSCL_SOCKET_STATS_LOGGING 00064 OsclSocketStats iStats; 00065 #endif 00066 private: 00067 TOsclSockAddr iAddr; 00068 TOsclSocket iSocket; 00069 OsclSocketServI* iContainer; 00070 }; 00071 LoopbackSocket iLoopbackSocket; 00072 #endif 00073 uint32 iSelectPollIntervalMsec; 00074 00075 void WakeupBlockingSelect() 00076 { 00077 #if PV_SOCKET_SERVER_SELECT_LOOPBACK_SOCKET 00078 if (iLoopbackSocket.iEnable) 00079 iLoopbackSocket.Write(); 00080 #endif 00081 } 00082 00083 int32 StartServImp(); 00084 void ConstructServImp(); 00085 void CleanupServImp(); 00086 void StopServImp(); 00087 void ServerEntry(); 00088 void ServerExit(); 00089 00090 #if PV_SOCKET_SERVER_IS_THREAD 00091 TOsclThreadId iThreadId; 00092 //start & exit semaphores. 00093 OsclSemaphore iStart, iExit; 00094 //thread exit flag 00095 bool iClose; 00096 public: 00097 //this needs to be public for use by the thread routine. 00098 void InThread(); 00099 private: 00100 #else 00101 //for AO implemenation. 00102 void Run(); 00103 void WakeupAO(); 00104 #if PV_SOCKET_SERVER_SELECT 00105 int iNhandles; 00106 int iNfds; 00107 #endif 00108 #endif 00109 00110 #if PV_SOCKET_SERVER_SELECT 00111 //select flags. 00112 fd_set iReadset, iWriteset, iExceptset; 00113 void ProcessSocketRequests(int &, int &n); 00114 #else 00115 void ProcessSocketRequests(); 00116 #endif 00117 00118 friend class OsclSocketServRequestList; 00119 friend class LoopbackSocket; 00120 00121 friend class OsclTCPSocketI; 00122 friend class OsclUDPSocketI; 00123 friend class OsclSocketI; 00124 friend class OsclDNSI; 00125 friend class OsclSocketRequest; 00126 friend class OsclSocketServ; 00127 00128 PVServiStats* iServiStats; 00129 00130 }; 00131 00134 #define OSCL_READSET_FLAG 0x04 00135 #define OSCL_WRITESET_FLAG 0x02 00136 #define OSCL_EXCEPTSET_FLAG 0x01 00137 00138 00139 #endif 00140 00141 00142