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 20#include "oscl_socket.h" 21#include "oscl_socket_imp.h" 22#include "oscl_socket_serv_imp.h" 23#include "oscl_error.h" 24#include "oscl_udp_socket.h" 25#include "oscl_tcp_socket.h" 26 27//Socket server 28 29OSCL_EXPORT_REF OsclSocketServ *OsclSocketServ::NewL(Oscl_DefAlloc &alloc) 30{ 31 OsclAny*p = alloc.ALLOCATE(sizeof(OsclSocketServ)); 32 OsclError::LeaveIfNull(p); 33 OsclSocketServ *self = OSCL_PLACEMENT_NEW(p, OsclSocketServ(alloc)); 34 OsclError::LeaveIfNull(self); 35 OsclError::PushL(self); 36 self->iServ = OsclSocketServI::NewL(alloc); 37 OsclError::Pop(); 38 return self; 39} 40 41OSCL_EXPORT_REF OsclSocketServ::~OsclSocketServ() 42{ 43 if (iServ) 44 { 45 iServ->~OsclSocketServI(); 46 iAlloc.deallocate(iServ); 47 } 48} 49 50OSCL_EXPORT_REF int32 OsclSocketServ::Connect(uint32 aMessageSlots) 51{ 52 return (int32)iServ->Connect(aMessageSlots); 53} 54 55OSCL_EXPORT_REF void OsclSocketServ::Close(bool aCleanup) 56{ 57 iServ->Close(aCleanup); 58} 59 60OSCL_EXPORT_REF OsclUDPSocket *OsclUDPSocket::NewL(Oscl_DefAlloc &alloc, 61 OsclSocketServ& aServ, 62 OsclSocketObserver *aObserver, 63 uint32 aId) 64{ 65 OsclAny* p = alloc.ALLOCATE(sizeof(OsclUDPSocket)); 66 OsclError::LeaveIfNull(p); 67 OsclUDPSocket *self = OSCL_PLACEMENT_NEW(p, OsclUDPSocket(alloc)); 68 OsclError::LeaveIfNull(self); 69 OsclError::PushL(self); 70 self->iUDPSocket = OsclUDPSocketI::NewL(alloc, aServ.iServ, aObserver, aId); 71 OsclError::Pop(); 72 return self; 73} 74 75OSCL_EXPORT_REF OsclUDPSocket::~OsclUDPSocket() 76{ 77 if (iUDPSocket) 78 { 79 iUDPSocket->~OsclUDPSocketI(); 80 iAlloc.deallocate(iUDPSocket); 81 } 82} 83 84OSCL_EXPORT_REF int32 OsclUDPSocket::Bind(OsclNetworkAddress& aAddress) 85{ 86 return iUDPSocket->Bind(aAddress); 87} 88 89OSCL_EXPORT_REF int32 OsclUDPSocket::Join(OsclNetworkAddress& aAddress) 90{ 91 return iUDPSocket->Join(aAddress); 92} 93 94OSCL_EXPORT_REF TPVSocketEvent OsclUDPSocket::BindAsync(OsclNetworkAddress& aAddress, int32 aTimeoutMsec) 95{ 96 return iUDPSocket->BindAsync(aAddress, aTimeoutMsec); 97} 98 99OSCL_EXPORT_REF void OsclUDPSocket::CancelBind() 100{ 101 iUDPSocket->CancelBind(); 102} 103 104OSCL_EXPORT_REF int32 OsclUDPSocket::Close() 105{ 106 return iUDPSocket->Close(); 107} 108 109OSCL_EXPORT_REF uint8 *OsclUDPSocket::GetRecvData(int32 *aLength) 110{ 111 return iUDPSocket->GetRecvData(aLength); 112} 113 114OSCL_EXPORT_REF uint8 *OsclUDPSocket::GetSendData(int32 *aLength) 115{ 116 return iUDPSocket->GetSendData(aLength); 117} 118 119OSCL_EXPORT_REF TPVSocketEvent OsclUDPSocket::SendTo( 120 const uint8* aPtr, uint32 aLen, 121 OsclNetworkAddress& aAddress, 122 int32 aTimeoutMsec) 123{ 124 return iUDPSocket->SendTo(aPtr, aLen, aAddress, aTimeoutMsec); 125} 126 127OSCL_EXPORT_REF void OsclUDPSocket::CancelSendTo() 128{ 129 iUDPSocket->CancelSendTo(); 130} 131 132OSCL_EXPORT_REF TPVSocketEvent OsclUDPSocket::RecvFrom( 133 uint8* aPtr, uint32 aMaxLen, 134 OsclNetworkAddress& aAddress, 135 int32 aTimeoutMsec, 136 uint32 aMultiMaxLen, 137 Oscl_Vector<uint32, OsclMemAllocator>* aPacketLen, 138 Oscl_Vector<OsclNetworkAddress, OsclMemAllocator>* aPacketSource) 139{ 140 return iUDPSocket->RecvFrom(aPtr, aMaxLen, aAddress, aTimeoutMsec, aMultiMaxLen, aPacketLen, aPacketSource); 141} 142 143OSCL_EXPORT_REF void OsclUDPSocket::CancelRecvFrom() 144{ 145 iUDPSocket->CancelRecvFrom(); 146} 147 148OSCL_EXPORT_REF int32 OsclUDPSocket::SetRecvBufferSize(uint32 size) 149{ 150 return iUDPSocket->SetRecvBufferSize(size); 151} 152 153OSCL_EXPORT_REF OsclTCPSocket *OsclTCPSocket::NewL(Oscl_DefAlloc &alloc, 154 OsclSocketServ& aServ, 155 OsclSocketObserver *aObserver, 156 uint32 aId) 157{ 158 OsclAny* p = alloc.ALLOCATE(sizeof(OsclTCPSocket)); 159 OsclError::LeaveIfNull(p); 160 OsclTCPSocket *self = OSCL_PLACEMENT_NEW(p, OsclTCPSocket(alloc)); 161 OsclError::LeaveIfNull(self); 162 OsclError::PushL(self); 163 { 164 self->iTCPSocket = OsclTCPSocketI::NewL(alloc, aServ.iServ, aObserver, aId); 165 } 166 OsclError::Pop(); 167 return self; 168} 169 170OsclTCPSocket *OsclTCPSocket::NewL(Oscl_DefAlloc &alloc, OsclTCPSocketI* aSocket) 171{ 172 OsclAny* p = alloc.ALLOCATE(sizeof(OsclTCPSocket)); 173 OsclError::LeaveIfNull(p); 174 OsclTCPSocket *self = OSCL_PLACEMENT_NEW(p, OsclTCPSocket(alloc)); 175 OsclError::LeaveIfNull(self); 176 OsclError::PushL(self); 177 { 178 if (!aSocket) 179 OsclError::Leave(OsclErrGeneral); 180 self->iTCPSocket = aSocket; 181 } 182 OsclError::Pop(); 183 return self; 184} 185 186OSCL_EXPORT_REF OsclTCPSocket::~OsclTCPSocket() 187{ 188 if (iTCPSocket) 189 { 190 iTCPSocket->~OsclTCPSocketI(); 191 iAlloc.deallocate(iTCPSocket); 192 } 193} 194 195OSCL_EXPORT_REF int32 OsclTCPSocket::Bind(OsclNetworkAddress& aAddress) 196{ 197 return iTCPSocket->Bind(aAddress); 198} 199 200OSCL_EXPORT_REF TPVSocketEvent OsclTCPSocket::BindAsync(OsclNetworkAddress& aAddress, int32 aTimeoutMsec) 201{ 202 return iTCPSocket->BindAsync(aAddress, aTimeoutMsec); 203} 204 205OSCL_EXPORT_REF void OsclTCPSocket::CancelBind() 206{ 207 iTCPSocket->CancelBind(); 208} 209 210OSCL_EXPORT_REF int32 OsclTCPSocket::Close() 211{ 212 return iTCPSocket->Close(); 213} 214 215OSCL_EXPORT_REF int32 OsclTCPSocket::Listen(int32 aQueueSize) 216{ 217 return iTCPSocket->Listen(aQueueSize); 218} 219 220OSCL_EXPORT_REF TPVSocketEvent OsclTCPSocket::ListenAsync(int32 qsize, int32 aTimeoutMsec) 221{ 222 return iTCPSocket->ListenAsync(qsize, aTimeoutMsec); 223} 224 225OSCL_EXPORT_REF void OsclTCPSocket::CancelListen() 226{ 227 iTCPSocket->CancelListen(); 228} 229 230OSCL_EXPORT_REF OsclTCPSocket *OsclTCPSocket::GetAcceptedSocketL(uint32 aId) 231{ 232 return OsclTCPSocket::NewL(iAlloc, iTCPSocket->GetAcceptedSocketL(aId)); 233} 234 235OSCL_EXPORT_REF uint8 *OsclTCPSocket::GetRecvData(int32 *aLength) 236{ 237 return iTCPSocket->GetRecvData(aLength); 238} 239 240OSCL_EXPORT_REF uint8 *OsclTCPSocket::GetSendData(int32 *aLength) 241{ 242 return iTCPSocket->GetSendData(aLength); 243} 244 245OSCL_EXPORT_REF TPVSocketEvent OsclTCPSocket::Connect(OsclNetworkAddress& aAddress, 246 int32 aTimeoutMsec) 247{ 248 return iTCPSocket->Connect(aAddress, aTimeoutMsec); 249} 250 251OSCL_EXPORT_REF void OsclTCPSocket::CancelConnect() 252{ 253 iTCPSocket->CancelConnect(); 254} 255 256OSCL_EXPORT_REF TPVSocketEvent OsclTCPSocket::Shutdown(TPVSocketShutdown aHow, 257 int32 aTimeoutMsec) 258{ 259 return iTCPSocket->Shutdown(aHow, aTimeoutMsec); 260} 261 262OSCL_EXPORT_REF void OsclTCPSocket::CancelShutdown() 263{ 264 iTCPSocket->CancelShutdown(); 265} 266 267OSCL_EXPORT_REF TPVSocketEvent OsclTCPSocket::Accept(int32 aTimeout) 268{ 269 return iTCPSocket->Accept(aTimeout); 270} 271 272OSCL_EXPORT_REF void OsclTCPSocket::CancelAccept() 273{ 274 iTCPSocket->CancelAccept(); 275} 276 277OSCL_EXPORT_REF TPVSocketEvent OsclTCPSocket::Send( 278 const uint8* aPtr, uint32 aLen, 279 int32 aTimeoutMsec) 280{ 281 return iTCPSocket->Send(aPtr, aLen, aTimeoutMsec); 282} 283 284OSCL_EXPORT_REF void OsclTCPSocket::CancelSend() 285{ 286 iTCPSocket->CancelSend(); 287} 288 289OSCL_EXPORT_REF TPVSocketEvent OsclTCPSocket::Recv( 290 uint8* aPtr, uint32 aMaxLen, 291 int32 aTimeoutMsec) 292{ 293 return iTCPSocket->Recv(aPtr, aMaxLen, aTimeoutMsec); 294} 295 296OSCL_EXPORT_REF void OsclTCPSocket::CancelRecv() 297{ 298 iTCPSocket->CancelRecv(); 299} 300 301 302 303 304 305