ZFFramework
 
Loading...
Searching...
No Matches
ZFUdp.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFUdp_h_
7#define _ZFI_ZFUdp_h_
8
9#include "ZFNetDef.h"
11
12zfclassFwd _ZFP_ZFUdpAddrPrivate;
17public:
19 ZFUdpAddr(void);
20 ZFUdpAddr(ZF_IN const ZFUdpAddr &ref);
21 ~ZFUdpAddr(void);
22 ZFUdpAddr &operator = (ZF_IN const ZFUdpAddr &ref);
23 inline operator zfbool (void) const {
24 return this->valid();
25 }
27
28public:
30 zfbool valid(void) const;
32 void clear(void);
33
37 zfstring remoteInfo(void) const;
38
39public:
44 zfstring ret;
45 this->objectInfoT(ret);
46 return ret;
47 }
48
49public:
50 void _ZFP_addr(ZF_IN void *addr);
51 void *_ZFP_addr(void) const;
52private:
53 _ZFP_ZFUdpAddrPrivate *d;
54};
57ZFOUTPUT_TYPE(ZFUdpAddr, {v.objectInfoT(s);})
58
59zfclassFwd _ZFP_ZFUdpPrivate;
60// ============================================================
64zfclass ZFLIB_ZFNet ZFUdp : zfextend ZFObject {
65 ZFOBJECT_DECLARE(ZFUdp, ZFObject)
66
67public:
80 )
89
94
99
100public:
105 , ZFMP_IN(const zfstring &, host)
107
108 // ============================================================
109public:
118 , ZFMP_IN(const ZFUdpAddr &, addr)
120 , ZFMP_IN(const zfstring &, data)
130 , ZFMP_IN(const ZFUdpAddr &, addr)
132 , ZFMP_IN(const void *, data)
133 , ZFMP_IN(zfindex, size)
143 , ZFMP_IN(const ZFUdpAddr &, addr)
145 , ZFMP_IN(const ZFInput &, input)
147
148 // ============================================================
149public:
158 , ZFMP_IN(const zfstring &, host)
160 , ZFMP_IN(const zfstring &, data)
170 , ZFMP_IN(const zfstring &, host)
172 , ZFMP_IN(const void *, data)
173 , ZFMP_IN(zfindex, size)
183 , ZFMP_IN(const zfstring &, host)
185 , ZFMP_IN(const ZFInput &, input)
187
188 // ============================================================
189public:
201 , ZFMP_OUT_OPT(ZFUdpAddr *, addr, zfnull)
203 , ZFMP_IN_OPT(zftimet, timeout, -1)
205
206public:
209
210protected:
212 virtual void objectOnInit(void);
214 virtual void objectOnDealloc(void);
215
216private:
217 _ZFP_ZFUdpPrivate *d;
218};
219
221#endif // #ifndef _ZFI_ZFUdp_h_
222
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
_zft_zftimet zftimet
time unit, ensured at least 64 bit, ensured signed
Definition ZFCoreTypeDef_CoreType.h:203
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
_ZFT_t_zfuint zfuint
same as unsigned int, see zfindex
Definition ZFCoreTypeDef_CoreType.h:169
#define ZFOUTPUT_TYPE(T_Type, outputAction)
declare your custom type conversion to string, convenient for debug
Definition ZFCoreTypeDef_OtherType.h:221
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZFMP_OUT_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:114
#define ZFMP_IN_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_DECLARE_0(ReturnType, MethodName)
see ZFMethod
Definition ZFMethodDeclare.h:693
#define ZFMETHOD_DECLARE_4(ReturnType, MethodName, ZFMP_0, ZFMP_1, ZFMP_2, ZFMP_3)
see ZFMethod
Definition ZFMethodDeclare.h:1397
#define ZFMETHOD_DECLARE_3(ReturnType, MethodName, ZFMP_0, ZFMP_1, ZFMP_2)
see ZFMethod
Definition ZFMethodDeclare.h:1206
#define ZFMETHOD_DECLARE_1(ReturnType, MethodName, ZFMP_0)
see ZFMethod
Definition ZFMethodDeclare.h:854
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
global header for ZFNet module
#define ZFLIB_ZFNet
used to export symbols
Definition ZFNetDef.h:15
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
#define ZFTYPEID_ACCESS_ONLY_REG(ZFLIB_, TypeName, Type,...)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:205
#define ZFTYPEID_ACCESS_ONLY_DECLARE(ZFLIB_, TypeName, Type)
see ZFTYPEID_DECLARE
Definition ZFTypeIdDeclare.h:195
general input callback
Definition ZFIOCallback_input.h:37
udp packet
Definition ZFUdp.h:16
zfbool valid(void) const
whether the addr is valid
zfstring objectInfo(void) const
return object info
Definition ZFUdp.h:43
zfstring remoteInfo(void) const
get remote info
void objectInfoT(zfstring &ret) const
see objectInfo
void clear(void)
clear the resolved addr
zfbool remoteInfoT(zfstring &remoteAddr) const
get remote info
virtual zfstring recv(ZFUdpAddr *addr=(zft_zfnull), zfuint *port=(zft_zfnull), zftimet timeout=(-1))
recv packet until timeout
virtual void objectOnInit(void)
override this to init your object
virtual zfbool open(zfuint port=(0))
open a socket ready for send or recv
virtual zfuint port()
current opened port, or 0 if not opened or opened with 0 port
virtual ZFUdpAddr addrResolve(const zfstring &host)
resolve host for send
virtual zfbool valid()
true if open successfully
virtual void objectInfoImpl(zfstring &ret)
see objectInfo
virtual zfbool send(const ZFUdpAddr &addr, zfuint port, const zfstring &data)
send packet
virtual void close()
close the socket, see open
virtual void objectOnDealloc(void)
override this to destroy your object