mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
optimization of bytes conversion
This commit is contained in:
@@ -38,7 +38,7 @@ type WebsocketClient struct {
|
|||||||
timeoutsec time.Duration
|
timeoutsec time.Duration
|
||||||
|
|
||||||
bRun bool
|
bRun bool
|
||||||
ping string
|
ping []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -71,12 +71,12 @@ func (ws *WebsocketClient) Init(slf IWebsocketClient, strurl, strProxyPath strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
ws.url = strurl
|
ws.url = strurl
|
||||||
ws.ping = `ping`
|
ws.ping = []byte(`ping`)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WebsocketClient) SetPing(ping string) {
|
func (ws *WebsocketClient) SetPing(ping string) {
|
||||||
ws.ping = ping
|
ws.ping = []byte(ping)
|
||||||
}
|
}
|
||||||
|
|
||||||
//OnRun ...
|
//OnRun ...
|
||||||
@@ -182,7 +182,7 @@ func (ws *WebsocketClient) writeMsg() error {
|
|||||||
|
|
||||||
case <-timerC:
|
case <-timerC:
|
||||||
if ws.state == 2 {
|
if ws.state == 2 {
|
||||||
err := ws.WriteMessage([]byte(ws.ping))
|
err := ws.WriteMessage(ws.ping)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
service.GetLogger().Printf(service.LEVER_WARN, "websocket client is disconnect [%s],information is %v", ws.url, err)
|
service.GetLogger().Printf(service.LEVER_WARN, "websocket client is disconnect [%s],information is %v", ws.url, err)
|
||||||
ws.state = 0
|
ws.state = 0
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ type IWebsocketServer interface {
|
|||||||
CreateClient(conn *websocket.Conn) *WSClient
|
CreateClient(conn *websocket.Conn) *WSClient
|
||||||
Disconnect(clientid uint64)
|
Disconnect(clientid uint64)
|
||||||
ReleaseClient(pclient *WSClient)
|
ReleaseClient(pclient *WSClient)
|
||||||
|
Clients() []uint64
|
||||||
|
BroadcastMsg(messageType int, msg []byte) int
|
||||||
}
|
}
|
||||||
|
|
||||||
type IMessageReceiver interface {
|
type IMessageReceiver interface {
|
||||||
|
|||||||
Reference in New Issue
Block a user