123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- //go:build windows
- package yu_hpsocket
- // TcpPackServer
- // @Description: TcpPackServerListener 对象,请自己创建和销毁,目的是保证安全
- type TcpPackServer struct {
- Server[TcpPackServer]
- TcpServer
- }
- // NewTcpPackServer
- //
- // @Description: 创建 TcpPackServer 对象
- func NewTcpPackServer() (t *TcpPackServer) {
- t = &TcpPackServer{}
- return
- }
- // Create
- //
- // @Description: 创建 TcpPackServer 环境
- func (t *TcpPackServer) Create(SSL bool) bool {
- t.Close()
- if t.hListener, _, _ = Create_HP_TcpPackServerListener.Call(); t.hListener == 0 {
- return false
- }
- if t.SSL = SSL; t.SSL {
- t.hServer, _, _ = Create_HP_SSLPackServer.Call(t.hListener)
- } else {
- t.hServer, _, _ = Create_HP_TcpPackServer.Call(t.hListener)
- }
- if t.hServer == 0 {
- Destroy_HP_TcpPackServerListener.Call(t.hListener)
- t.hListener = 0
- return false
- }
- _server_on_set(t.hServer, &_server_item{
- _type: _server_type_TcpPackServer,
- t: t,
- })
- return true
- }
- // Close
- //
- // @Description: 销毁 TcpPackServer 环境
- func (t *TcpPackServer) Close() {
- t.Stop()
- t.Wait(-1)
- if t.hServer != 0 {
- if t.SSL {
- Destroy_HP_SSLPackServer.Call(t.hServer)
- } else {
- Destroy_HP_TcpPackServer.Call(t.hServer)
- }
- _server_on_del(t.hServer)
- t.hServer = 0
- }
- if t.hListener != 0 {
- Destroy_HP_TcpPackServerListener.Call(t.hListener)
- t.hListener = 0
- }
- }
- // SetMaxPackSize
- //
- // @Description: 设置数据包最大长度(有效数据包最大长度不能超过 4194303/0x3FFFFF 字节,默认:262144/0x40000)
- func (t *TcpPackServer) SetMaxPackSize(MaxPackSize int) *TcpPackServer {
- if !t.isValid() {
- return t
- }
- HP_TcpPackServer_SetMaxPackSize.Call(t.hServer, MaxPackSize)
- return t
- }
- // SetPackHeaderFlag
- //
- // @Description: 设置包头标识(有效包头标识取值范围 0 ~ 1023/0x3FF,当包头标识为 0 时不校验包头,默认:0)
- func (t *TcpPackServer) SetPackHeaderFlag(PackHeaderFlag int) *TcpPackServer {
- if !t.isValid() {
- return t
- }
- HP_TcpPackServer_SetPackHeaderFlag.Call(t.hServer, PackHeaderFlag)
- return t
- }
- // GetMaxPackSize
- //
- // @Description: 获取数据包最大长度
- func (t *TcpPackServer) GetMaxPackSize() int {
- if !t.isValid() {
- return 0
- }
- return HP_TcpPackServer_GetMaxPackSize.CallInt(t.hServer)
- }
- // GetPackHeaderFlag
- //
- // @Description: 获取包头标识
- func (t *TcpPackServer) GetPackHeaderFlag() uintptr {
- if !t.isValid() {
- return 0
- }
- return HP_TcpPackServer_GetPackHeaderFlag.CallUintptr(t.hServer)
- }
|