Main Page Modules Class Hierarchy Data Structures File List Data Fields Globals Related Pages

# oscl_udp_socket.h

Go to the documentation of this file.

    00001
    00002 #ifndef OSCL_UDP_SOCKET_H_INCLUDED
    00003 #define OSCL_UDP_SOCKET_H_INCLUDED
    00004
    00005 #include "oscl_ip_socket.h"
    00006 #include "oscl_defalloc.h"
    00007
    00008 class OsclSendToMethod;
    00009 class OsclRecvFromMethod;
    00010 class OsclBindMethod;
    00011
    00014 class OsclUDPSocketI : public OsclIPSocketI
    00015 {
    00016     public:
    00017         static OsclUDPSocketI *NewL(Oscl_DefAlloc &a,
    00018                                     OsclSocketServI *aServ,
    00019                                     OsclSocketObserver *aObserver,
    00020                                     uint32 aId);
    00021
    00022         virtual ~OsclUDPSocketI();
    00023
    00024         //Synchronous methods
    00025         int32 Close();
    00026         int32 JoinMulticastGroup(OsclIpMReq& aMReq);
    00027         int32 SetMulticastTTL(int32 aTTL);
    00028         inline uint8 *GetRecvData(int32 *aLength);
    00029         inline uint8 *GetSendData(int32 *aLength);
    00030         TPVSocketEvent ThreadLogoff();
    00031         TPVSocketEvent ThreadLogon(
    00032             OsclSocketServI *aServ,
    00033             OsclSocketObserver *aObserver
    00034         );
    00035
    00036         //Asynchronous methods
    00037         inline TPVSocketEvent BindAsync(OsclNetworkAddress& aAddress,
    00038                                         int32 aTimeoutMsec = -1);
    00039         inline void CancelBind();
    00040
    00041         inline TPVSocketEvent SendTo(const uint8* &aPtr, uint32 aLen,
    00042                                      OsclNetworkAddress& aAddress,
    00043                                      int32 aTimeoutMsec = -1);
    00044         inline void CancelSendTo();
    00045
    00046         inline TPVSocketEvent RecvFrom(uint8* &aPtr, uint32 aMaxLen,
    00047                                        OsclNetworkAddress& aAddress,
    00048                                        int32 aTimeoutMsec = -1,
    00049                                        uint32 aMultiMaxLen = 0,
    00050                                        Oscl_Vector<uint32, OsclMemAllocator>* aPacketLen = NULL,
    00051                                        Oscl_Vector<OsclNetworkAddress, OsclMemAllocator>* aPacketSource = NULL);
    00052         inline void CancelRecvFrom();
    00053
    00054     private:
    00055         OsclUDPSocketI(Oscl_DefAlloc &a) : OsclIPSocketI(a), iSendToMethod(NULL),
    00056                 iRecvFromMethod(NULL)
    00057         {}
    00058
    00059         void ConstructL(OsclSocketServI *aServ,
    00060                         OsclSocketObserver *aObserver,
    00061                         uint32 aId);
    00062
    00063         OsclBindMethod *iBindMethod;
    00064         OsclSendToMethod *iSendToMethod;
    00065         OsclRecvFromMethod *iRecvFromMethod;
    00066 };
    00067
    00068 #include "oscl_socket_recv_from.h"
    00069 #include "oscl_socket_send_to.h"
    00070 #include "oscl_socket_bind.h"
    00071
    00073 inline uint8 *OsclUDPSocketI::GetRecvData(int32 *aLength)
    00074 {
    00075     return iRecvFromMethod->GetRecvData(aLength);
    00076 }
    00077
    00079 inline uint8 *OsclUDPSocketI::GetSendData(int32 *aLength)
    00080 {
    00081     return iSendToMethod->GetSendData(aLength);
    00082 }
    00083
    00085 inline TPVSocketEvent OsclUDPSocketI::BindAsync(OsclNetworkAddress& aAddress,
    00086         int32 aTimeoutMsec)
    00087 {
    00088     if (!OsclSocketIBase::HasAsyncBind())
    00089         return EPVSocketNotImplemented;
    00090     if (!iObserver)
    00091         return EPVSocketFailure;//not available.
    00092
    00093     iAddress.ipAddr.Set(aAddress.ipAddr.Str());
    00094     iAddress.port = aAddress.port;
    00095     return (iBindMethod->Bind(aAddress, aTimeoutMsec));
    00096 }
    00097
    00098 inline void OsclUDPSocketI::CancelBind()
    00099 {
    00100     iBindMethod->CancelMethod();
    00101 }
    00102
    00104 inline TPVSocketEvent OsclUDPSocketI::SendTo(const uint8* &aPtr, uint32 aLen,
    00105         OsclNetworkAddress& aAddress,
    00106         int32 aTimeoutMsec)
    00107 {
    00108     if (!iObserver)
    00109         return EPVSocketFailure;//socket is logged off.
    00110     return (iSendToMethod->SendTo(aPtr, aLen, aAddress, aTimeoutMsec));
    00111 }
    00112
    00113 inline void OsclUDPSocketI::CancelSendTo()
    00114 {
    00115     iSendToMethod->CancelMethod();
    00116 }
    00117
    00119 inline TPVSocketEvent OsclUDPSocketI::RecvFrom(uint8* &aPtr, uint32 aMaxLen,
    00120         OsclNetworkAddress& aAddress,
    00121         int32 aTimeoutMsec, uint32 aMultiMax,
    00122         Oscl_Vector<uint32, OsclMemAllocator>* aPacketLen,
    00123         Oscl_Vector<OsclNetworkAddress, OsclMemAllocator>* aPacketSource)
    00124 {
    00125     if (!iObserver)
    00126         return EPVSocketFailure;//socket is logged off.
    00127     return (iRecvFromMethod->RecvFrom(aPtr, aMaxLen, aAddress, aTimeoutMsec, aMultiMax, aPacketLen, aPacketSource));
    00128 }
    00129
    00130 inline void OsclUDPSocketI::CancelRecvFrom()
    00131 {
    00132     iRecvFromMethod->CancelMethod();
    00133 }
    00134
    00135 #endif
    00136