00001
00002 #ifndef OSCL_TCP_SOCKET_H_INCLUDED
00003 #define OSCL_TCP_SOCKET_H_INCLUDED
00004
00005 #ifndef OSCL_IP_SOCKET_H_INCLUDED
00006 #include "oscl_ip_socket.h"
00007 #endif
00008
00009 #ifndef OSCL_DEFALLOC_H_INCLUDED
00010 #include "oscl_defalloc.h"
00011 #endif
00012
00013 #ifndef OSCL_VECTOR_H_INCLUDED
00014 #include "oscl_vector.h"
00015 #endif
00016
00017 #ifndef OSCL_MEM_H_INCLUDED
00018 #include "oscl_mem.h"
00019 #endif
00020
00021 class OsclBindMethod;
00022 class OsclListenMethod;
00023 class OsclConnectMethod;
00024 class OsclShutdownMethod;
00025 class OsclAcceptMethod;
00026 class OsclSendMethod;
00027 class OsclRecvMethod;
00028
00031 class OsclTCPSocketI : public OsclIPSocketI
00032 {
00033 public:
00034
00035 static OsclTCPSocketI *NewL(Oscl_DefAlloc &a,
00036 OsclSocketServI *aServ,
00037 OsclSocketObserver *aObserver,
00038 uint32 aId);
00039
00040 virtual ~OsclTCPSocketI();
00041
00042 TPVSocketEvent ThreadLogoff();
00043 TPVSocketEvent ThreadLogon(
00044 OsclSocketServI *aServ,
00045 OsclSocketObserver *aObserver
00046 );
00047 int32 Close();
00048 inline int32 Listen(int aQueueSize);
00049
00050
00051 OsclTCPSocketI *GetAcceptedSocketL(uint32 aId);
00052
00053 inline uint8 *GetRecvData(int32 *aLength) ;
00054 inline uint8 *GetSendData(int32 *aLength);
00055
00056
00057 inline TPVSocketEvent BindAsync(OsclNetworkAddress& aAddress,
00058 int32 aTimeoutMsec = -1);
00059 inline void CancelBind();
00060
00061 inline TPVSocketEvent ListenAsync(uint32 qsize,
00062 int32 aTimeoutMsec = -1);
00063 inline void CancelListen();
00064
00065 inline TPVSocketEvent Connect(OsclNetworkAddress& aAddress,
00066 int32 aTimeoutMsec = -1);
00067 inline void CancelConnect();
00068
00069 inline TPVSocketEvent Shutdown(TPVSocketShutdown aHow,
00070 int32 aTimeoutMsec = -1);
00071 inline void CancelShutdown();
00072
00073 inline TPVSocketEvent Accept(int32 aTimeout = -1);
00074 inline void CancelAccept();
00075
00076 inline TPVSocketEvent Send(const uint8* &aPtr, uint32 aLen,
00077 int32 aTimeoutMsec = -1);
00078 inline void CancelSend();
00079
00080 inline TPVSocketEvent Recv(uint8* &aPtr, uint32 aMaxLen,
00081 int32 aTimeoutMsec = -1);
00082 inline void CancelRecv();
00083
00084 private:
00085 static OsclTCPSocketI *NewL(Oscl_DefAlloc &a,
00086 OsclSocketServI *aServ,
00087 OsclSocketI *aSocket,
00088 OsclSocketObserver *aObserver,
00089 uint32 aId);
00090
00091 OsclTCPSocketI(Oscl_DefAlloc &a) : OsclIPSocketI(a),
00092 iConnectMethod(NULL),
00093 iShutdownMethod(NULL),
00094 iAcceptMethod(NULL),
00095 iSendMethod(NULL),
00096 iRecvMethod(NULL)
00097 {}
00098
00099 void ConstructL(OsclSocketServI *aServ,
00100 OsclSocketObserver *aObserver,
00101 uint32 aId);
00102
00103 void ConstructL(OsclSocketServI *aServ,
00104 OsclSocketI *aSocket,
00105 OsclSocketObserver *aObserver,
00106 uint32 aId);
00107
00108 OsclBindMethod *iBindMethod;
00109 OsclListenMethod *iListenMethod;
00110 OsclConnectMethod *iConnectMethod;
00111 OsclShutdownMethod *iShutdownMethod;
00112 OsclAcceptMethod *iAcceptMethod;
00113 OsclSendMethod *iSendMethod;
00114 OsclRecvMethod *iRecvMethod;
00115 };
00116
00117 #include "oscl_socket_listen.h"
00118 #include "oscl_socket_recv.h"
00119 #include "oscl_socket_send.h"
00120 #include "oscl_socket_accept.h"
00121 #include "oscl_socket_shutdown.h"
00122 #include "oscl_socket_connect.h"
00123 #include "oscl_socket_bind.h"
00124
00126 inline int32 OsclTCPSocketI::Listen(int aQueueSize)
00127 {
00128 return iSocket->Listen(aQueueSize) ;
00129 }
00130
00132 inline uint8 *OsclTCPSocketI::GetRecvData(int32 *aLength)
00133 {
00134 return iRecvMethod->GetRecvData(aLength);
00135 }
00136
00138 inline uint8 *OsclTCPSocketI::GetSendData(int32 *aLength)
00139 {
00140 return iSendMethod->GetSendData(aLength);
00141 }
00142
00144 inline TPVSocketEvent OsclTCPSocketI::BindAsync(OsclNetworkAddress& aAddress,
00145 int32 aTimeout)
00146 {
00147 if (!OsclSocketIBase::HasAsyncBind())
00148 return EPVSocketNotImplemented;
00149 if (!iObserver)
00150 return EPVSocketFailure;
00151
00152 iAddress.ipAddr.Set(aAddress.ipAddr.Str());
00153 iAddress.port = aAddress.port;
00154 return (iBindMethod->Bind(aAddress, aTimeout));
00155 }
00156
00157 inline void OsclTCPSocketI::CancelBind()
00158 {
00159 iBindMethod->CancelMethod();
00160 }
00161
00163 inline TPVSocketEvent OsclTCPSocketI::ListenAsync(uint32 qsize,
00164 int32 aTimeout)
00165 {
00166 if (!OsclSocketIBase::HasAsyncListen())
00167 return EPVSocketNotImplemented;
00168 if (!iObserver)
00169 return EPVSocketFailure;
00170
00171 return (iListenMethod->Listen(qsize, aTimeout));
00172 }
00173
00174 inline void OsclTCPSocketI::CancelListen()
00175 {
00176 iListenMethod->CancelMethod();
00177 }
00178
00180 inline TPVSocketEvent OsclTCPSocketI::Connect(OsclNetworkAddress& aAddress,
00181 int32 aTimeout)
00182 {
00183 if (!iObserver)
00184 return EPVSocketFailure;
00185 return (iConnectMethod->Connect(aAddress, aTimeout));
00186 }
00187
00188 inline void OsclTCPSocketI::CancelConnect()
00189 {
00190 iConnectMethod->CancelMethod();
00191 }
00192
00194 inline TPVSocketEvent OsclTCPSocketI::Shutdown(TPVSocketShutdown aHow,
00195 int32 aTimeout)
00196 {
00197 if (!iObserver)
00198 return EPVSocketFailure;
00199 return (iShutdownMethod->Shutdown(aHow, aTimeout));
00200 }
00201
00202 inline void OsclTCPSocketI::CancelShutdown()
00203 {
00204 iShutdownMethod->CancelMethod();
00205 }
00206
00208 inline TPVSocketEvent OsclTCPSocketI::Accept(int32 aTimeout)
00209 {
00210 if (!iObserver)
00211 return EPVSocketFailure;
00212 return (iAcceptMethod->Accept(aTimeout));
00213 }
00214
00215 inline void OsclTCPSocketI::CancelAccept()
00216 {
00217 iAcceptMethod->CancelMethod();
00218 }
00219
00221 inline TPVSocketEvent OsclTCPSocketI::Send(const uint8* &aPtr, uint32 aLen,
00222 int32 aTimeoutMsec)
00223 {
00224 if (!iObserver)
00225 return EPVSocketFailure;
00226 return (iSendMethod->Send(aPtr, aLen, aTimeoutMsec));
00227 }
00228
00229 inline void OsclTCPSocketI::CancelSend()
00230 {
00231 iSendMethod->CancelMethod();
00232 }
00233
00235 inline TPVSocketEvent OsclTCPSocketI::Recv(uint8* &aPtr, uint32 aMaxLen,
00236 int32 aTimeout)
00237 {
00238 if (!iObserver)
00239 return EPVSocketFailure;
00240 return (iRecvMethod->Recv(aPtr, aMaxLen, aTimeout));
00241 }
00242
00243 inline void OsclTCPSocketI::CancelRecv()
00244 {
00245 iRecvMethod->CancelMethod();
00246 }
00247
00248 #endif
00249