hp socket 网络库如何构造 extra 用户数据包含不定长字符串的方法
如何装一个不定长的字符串? 就是指针, 并且要控制指针的释放,所以要用动态指针
import util.metaProperty;
namespace aaz.libhpsocket.app.userData;
class str{
ctor(s){
this@ = _metaProperty;
if(s){
if(type(s) != type.string){
error("参数@1必须是字符串",2)
}
this.value = s;
}
}
pointer pValue;
}
namespace str{
_metaProperty = ..util.metaProperty(
value = {
_get = function(){
if(owner.pValue){
return ..raw.str(owner.pValue);
}
}
_set = function(v){
if(v===null){
if(owner.pValue){
owner.pValue = ..raw.realloc(0, owner.pValue)
}
return ;
}
owner.pValue = ..raw.realloc(#v, owner.pValue, v);
}
};
)
}
使用:
import aaz.libhpsocket.app.userData;
import aaz.libhpsocket.app.userData.str;
namespace aaz.libhpsocket.app.websocket.client;
class userData{
ctor(wsPath, wsOrigin){
this = ..aaz.libhpsocket.app.userData();
}
free = function(){
this.wsKey.value = null;
this.wsPath.value = null;
this.wsOrigin.value = null;
}
struct wsKey = ..aaz.libhpsocket.app.userData.str();
struct wsPath = ..aaz.libhpsocket.app.userData.str(wsPath);
struct wsOrigin = ..aaz.libhpsocket.app.userData.str(wsOrigin);
}
具体案列请看 https://chengxu.xyz/t/21357
登录后方可回帖
感谢分享,请问您的
hp socket 网络库
是包含了全部hpsocket的内容吗,还是只有部分