• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 
19 #ifndef OSCL_TCP_SOCKET_H_INCLUDED
20 #define OSCL_TCP_SOCKET_H_INCLUDED
21 
22 #ifndef OSCL_IP_SOCKET_H_INCLUDED
23 #include "oscl_ip_socket.h"
24 #endif
25 
26 #ifndef OSCL_DEFALLOC_H_INCLUDED
27 #include "oscl_defalloc.h"
28 #endif
29 
30 #ifndef OSCL_VECTOR_H_INCLUDED
31 #include "oscl_vector.h"
32 #endif
33 
34 #ifndef OSCL_MEM_H_INCLUDED
35 #include "oscl_mem.h"
36 #endif
37 
38 class OsclBindMethod;
39 class OsclListenMethod;
40 class OsclConnectMethod;
41 class OsclShutdownMethod;
42 class OsclAcceptMethod;
43 class OsclSendMethod;
44 class OsclRecvMethod;
45 
46 /**Internal implementation class for OsclTCPSocket
47 */
48 class OsclTCPSocketI : public OsclIPSocketI
49 {
50     public:
51         //Synchronous methods
52         static OsclTCPSocketI *NewL(Oscl_DefAlloc &a,
53                                     OsclSocketServI *aServ,
54                                     OsclSocketObserver *aObserver,
55                                     uint32 aId);
56 
57         virtual ~OsclTCPSocketI();
58 
59         int32 Close();
60         inline int32 Listen(int aQueueSize);
61         //the returned value is platform-specific
62 
63         OsclTCPSocketI *GetAcceptedSocketL(uint32 aId);
64 
65         inline uint8 *GetRecvData(int32 *aLength) ;
66         inline uint8 *GetSendData(int32 *aLength);
67 
68         //Asynchronous methods
69         inline TPVSocketEvent BindAsync(OsclNetworkAddress& aAddress,
70                                         int32 aTimeoutMsec = -1);
71         inline void CancelBind();
72 
73         inline TPVSocketEvent ListenAsync(uint32 qsize,
74                                           int32 aTimeoutMsec = -1);
75         inline void CancelListen();
76 
77         inline TPVSocketEvent Connect(OsclNetworkAddress& aAddress,
78                                       int32 aTimeoutMsec = -1);
79         inline void CancelConnect();
80 
81         inline TPVSocketEvent Shutdown(TPVSocketShutdown  aHow,
82                                        int32 aTimeoutMsec = -1);
83         inline void CancelShutdown();
84 
85         inline TPVSocketEvent Accept(int32 aTimeout = -1);
86         inline void CancelAccept();
87 
88         inline TPVSocketEvent Send(const uint8* &aPtr, uint32 aLen,
89                                    int32 aTimeoutMsec = -1);
90         inline void CancelSend();
91 
92         inline TPVSocketEvent Recv(uint8* &aPtr, uint32 aMaxLen,
93                                    int32 aTimeoutMsec = -1);
94         inline void CancelRecv();
95 
96     private:
97         static OsclTCPSocketI *NewL(Oscl_DefAlloc &a,
98                                     OsclSocketServI *aServ,
99                                     OsclSocketI *aSocket,
100                                     OsclSocketObserver *aObserver,
101                                     uint32 aId);
102 
OsclTCPSocketI(Oscl_DefAlloc & a)103         OsclTCPSocketI(Oscl_DefAlloc &a) : OsclIPSocketI(a),
104                 iConnectMethod(NULL),
105                 iShutdownMethod(NULL),
106                 iAcceptMethod(NULL),
107                 iSendMethod(NULL),
108                 iRecvMethod(NULL)
109         {}
110 
111         void ConstructL(OsclSocketServI *aServ,
112                         OsclSocketObserver *aObserver,
113                         uint32 aId);
114 
115         void ConstructL(OsclSocketServI *aServ,
116                         OsclSocketI *aSocket,
117                         OsclSocketObserver *aObserver,
118                         uint32 aId);
119 
120         OsclBindMethod *iBindMethod;
121         OsclListenMethod *iListenMethod;
122         OsclConnectMethod *iConnectMethod;
123         OsclShutdownMethod *iShutdownMethod;
124         OsclAcceptMethod *iAcceptMethod;
125         OsclSendMethod *iSendMethod;
126         OsclRecvMethod *iRecvMethod;
127 };
128 
129 #include "oscl_socket_listen.h"
130 #include "oscl_socket_recv.h"
131 #include "oscl_socket_send.h"
132 #include "oscl_socket_accept.h"
133 #include "oscl_socket_shutdown.h"
134 #include "oscl_socket_connect.h"
135 #include "oscl_socket_bind.h"
136 
137 //////////////////////////////////////////////////////////////////////////////////
Listen(int aQueueSize)138 inline int32 OsclTCPSocketI::Listen(int aQueueSize)
139 {
140     return iSocket->Listen(aQueueSize) ;
141 }
142 
143 //////////////////////////////////////////////////////////////////////////////////
GetRecvData(int32 * aLength)144 inline uint8 *OsclTCPSocketI::GetRecvData(int32 *aLength)
145 {
146     return iRecvMethod->GetRecvData(aLength);
147 }
148 
149 //////////////////////////////////////////////////////////////////////////////////
GetSendData(int32 * aLength)150 inline uint8 *OsclTCPSocketI::GetSendData(int32 *aLength)
151 {
152     return iSendMethod->GetSendData(aLength);
153 }
154 
155 //////////////////////////////////////////////////////////////////////////////////
BindAsync(OsclNetworkAddress & aAddress,int32 aTimeout)156 inline TPVSocketEvent OsclTCPSocketI::BindAsync(OsclNetworkAddress& aAddress,
157         int32 aTimeout)
158 {
159     if (!OsclSocketIBase::HasAsyncBind())
160         return EPVSocketFailure;//not available.
161 
162     iAddress.ipAddr.Set(aAddress.ipAddr.Str());
163     iAddress.port = aAddress.port;
164     return (iBindMethod->Bind(aAddress, aTimeout));
165 }
166 
CancelBind()167 inline void OsclTCPSocketI::CancelBind()
168 {
169     iBindMethod->CancelMethod();
170 }
171 
172 //////////////////////////////////////////////////////////////////////////////////
ListenAsync(uint32 qsize,int32 aTimeout)173 inline TPVSocketEvent OsclTCPSocketI::ListenAsync(uint32 qsize,
174         int32 aTimeout)
175 {
176     if (!OsclSocketIBase::HasAsyncListen())
177         return EPVSocketFailure;//not available
178 
179     return (iListenMethod->Listen(qsize, aTimeout));
180 }
181 
CancelListen()182 inline void OsclTCPSocketI::CancelListen()
183 {
184     iListenMethod->CancelMethod();
185 }
186 
187 //////////////////////////////////////////////////////////////////////////////////
Connect(OsclNetworkAddress & aAddress,int32 aTimeout)188 inline TPVSocketEvent OsclTCPSocketI::Connect(OsclNetworkAddress& aAddress,
189         int32 aTimeout)
190 {
191     return (iConnectMethod->Connect(aAddress, aTimeout));
192 }
193 
CancelConnect()194 inline void OsclTCPSocketI::CancelConnect()
195 {
196     iConnectMethod->CancelMethod();
197 }
198 
199 //////////////////////////////////////////////////////////////////////////////////
Shutdown(TPVSocketShutdown aHow,int32 aTimeout)200 inline TPVSocketEvent OsclTCPSocketI::Shutdown(TPVSocketShutdown  aHow,
201         int32 aTimeout)
202 {
203     return (iShutdownMethod->Shutdown(aHow, aTimeout));
204 }
205 
CancelShutdown()206 inline void OsclTCPSocketI::CancelShutdown()
207 {
208     iShutdownMethod->CancelMethod();
209 }
210 
211 //////////////////////////////////////////////////////////////////////////////////
Accept(int32 aTimeout)212 inline TPVSocketEvent OsclTCPSocketI::Accept(int32 aTimeout)
213 {
214     return (iAcceptMethod->Accept(aTimeout));
215 }
216 
CancelAccept()217 inline void OsclTCPSocketI::CancelAccept()
218 {
219     iAcceptMethod->CancelMethod();
220 }
221 
222 //////////////////////////////////////////////////////////////////////////////////
Send(const uint8 * & aPtr,uint32 aLen,int32 aTimeoutMsec)223 inline TPVSocketEvent OsclTCPSocketI::Send(const uint8* &aPtr, uint32 aLen,
224         int32 aTimeoutMsec)
225 {
226     return (iSendMethod->Send(aPtr, aLen, aTimeoutMsec));
227 }
228 
CancelSend()229 inline void OsclTCPSocketI::CancelSend()
230 {
231     iSendMethod->CancelMethod();
232 }
233 
234 //////////////////////////////////////////////////////////////////////////////////
Recv(uint8 * & aPtr,uint32 aMaxLen,int32 aTimeout)235 inline TPVSocketEvent OsclTCPSocketI::Recv(uint8* &aPtr, uint32 aMaxLen,
236         int32 aTimeout)
237 {
238     return (iRecvMethod->Recv(aPtr, aMaxLen, aTimeout));
239 }
240 
CancelRecv()241 inline void OsclTCPSocketI::CancelRecv()
242 {
243     iRecvMethod->CancelMethod();
244 }
245 
246 #endif
247 
248