]> 127.0.0.1 Git - part/.git/commitdiff
1 v0.28.20240811150311
authorqydysky <qydysky@foxmail.com>
Sun, 11 Aug 2024 14:58:57 +0000 (22:58 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 11 Aug 2024 14:58:57 +0000 (22:58 +0800)
websocket/Client.go

index 3608ca4d282d29b5bf3e14107d56710f6a36fa5e..543c3b282d68680c849ff1e4967a0d394da4949e 100644 (file)
@@ -57,14 +57,15 @@ func New_client(config *Client) (*Client, error) {
                WTOMs:             300 * 1000,
                Func_normal_close: func() {},
                Func_abort_close:  func() {},
+               BufSize:           10,
                msg:               msgq.NewType[*WsMsg](),
        }
        tmp.Url = config.Url
        if tmp.Url == "" {
                return nil, errors.New(`url == ""`)
        }
-       if v := config.BufSize; v <= 1 {
-               tmp.BufSize = 1
+       if v := config.BufSize; v >= 1 {
+               tmp.BufSize = v
        }
        if v := config.TO; v != 0 {
                tmp.RTOMs = v
@@ -166,11 +167,11 @@ func (o *Client) Handle() (*msgq.MsgType[*WsMsg], error) {
                                if msg, e := pio.ReadAll(r, buf); e != nil {
                                        err = e
                                } else {
-                                       msgs[cuP] = append(msgs[cuP][:0], msg...)
                                        cuP++
                                        if cuP >= o.BufSize {
                                                cuP = 0
                                        }
+                                       msgs[cuP] = append(msgs[cuP][:0], msg...)
                                }
                        }
                        if err != nil {