Skip to content

Commit

Permalink
cmd可以读取raw
Browse files Browse the repository at this point in the history
cmd可以读取raw
  • Loading branch information
magiclvzs committed Nov 16, 2018
1 parent db6480f commit f7fd67f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ var Config = struct {
SSLCrtPath string
SSLKeyPath string
EnableWss bool
}{UdpServerGoCnt: 64, TimeSyncInterval: 10, PoolSize: 50000}
ReadDataBuffer int
}{UdpServerGoCnt: 64, TimeSyncInterval: 10, PoolSize: 50000, ReadDataBuffer: 1 << 12}

var stopCheckIndex uint64
var stopCheckMap = struct {
Expand Down
7 changes: 6 additions & 1 deletion msgque.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type IMsgQue interface {
DelCallback(m *Message)
SetSendFast()
SetTimeout(t int)
SetCmdReadRaw()
GetTimeout() int
Reconnect(t int) //重连间隔 最小1s,此函数仅能连接关闭是调用

Expand Down Expand Up @@ -115,7 +116,9 @@ func (r *msgQue) getGMsg(add bool) *gMsg {
gm := gmsgArray[r.gmsgId]
return gm
}
func (r *msgQue) SetCmdReadRaw() {

}
func (r *msgQue) Available() bool {
return r.available
}
Expand Down Expand Up @@ -490,7 +493,9 @@ func StartServer(addr string, typ MsgType, handler IMsgHandler, parser IParserFa
if addrs[0] == "wss" {
Config.EnableWss = true
}
LogInfo("ws type msgque noly support MsgTypeCmd now auto set to MsgTypeCmd")
if typ != MsgTypeCmd {
LogInfo("ws type msgque noly support MsgTypeCmd now auto set to MsgTypeCmd")
}
msgque := newWsListen(naddr[0], url, MsgTypeCmd, handler, parser)
Go(func() {
LogDebug("process listen for ws msgque:%d", msgque.id)
Expand Down
22 changes: 19 additions & 3 deletions msgque_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type tcpMsgQue struct {
address string
wait sync.WaitGroup
connecting int32
rawBuffer []byte
}

func (r *tcpMsgQue) SetCmdReadRaw() {
r.rawBuffer = make([]byte, Config.ReadDataBuffer)
}

func (r *tcpMsgQue) GetNetType() NetType {
Expand Down Expand Up @@ -57,8 +62,8 @@ func (r *tcpMsgQue) LocalAddr() string {
}

func (r *tcpMsgQue) RemoteAddr() string {
if r.realRemoteAddr != ""{
return r.realRemoteAddr
if r.realRemoteAddr != "" {
return r.realRemoteAddr
}
if r.conn != nil {
return r.conn.RemoteAddr().String()
Expand Down Expand Up @@ -221,8 +226,19 @@ func (r *tcpMsgQue) writeMsg() {

func (r *tcpMsgQue) readCmd() {
reader := bufio.NewReader(r.conn)
var err error
var len int
var data []byte
for !r.IsStop() {
data, err := reader.ReadBytes('\n')
if r.rawBuffer != nil {
len, err = reader.Read(r.rawBuffer)
if err == nil && len > 0 {
data = make([]byte, len)
copy(data, r.rawBuffer)
}
} else {
data, err = reader.ReadBytes('\n')
}
if err != nil {
break
}
Expand Down

0 comments on commit f7fd67f

Please sign in to comment.