From e4b1bd40384b609d187c1aa7c432976657f87041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=AE=B7=E5=8B=87?= Date: Mon, 4 Sep 2023 18:32:44 +0800 Subject: [PATCH] code format --- server/imserver/wsplistener.go | 37 ++++++++++++++++------------------ third_party/f5 | 2 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/server/imserver/wsplistener.go b/server/imserver/wsplistener.go index adf24332..c46f8498 100644 --- a/server/imserver/wsplistener.go +++ b/server/imserver/wsplistener.go @@ -1,14 +1,14 @@ package main import ( - "net" "fmt" + "net" - "q5" - "f5" "cs" - "ss" + "f5" "mt" + "q5" + "ss" proto "github.com/golang/protobuf/proto" ) @@ -16,13 +16,13 @@ import ( type WSPListener struct { ss.MsgHandlerImpl listener net.Listener - ch chan *f5.MsgHdr - msgList q5.ListHead + ch chan *f5.MsgHdr + msgList q5.ListHead } func (this *WSPListener) init() { this.ch = make(chan *f5.MsgHdr) - listener, err := net.Listen("tcp", "0.0.0.0:" + + listener, err := net.Listen("tcp", "0.0.0.0:"+ q5.ToString(mt.Table.IMCluster.GetListenPort())) if err != nil { @@ -54,9 +54,9 @@ func (this *WSPListener) accept() { } func (this *WSPListener) socketRead(conn net.Conn) { - buf := make([]byte, 1024 * 64) + buf := make([]byte, 1024*64) recvBufLen := 0 - recvBuf := make([]byte, 1024 * 64 * 2) + recvBuf := make([]byte, 1024*64*2) for { bufLen, err := conn.Read(buf) if err == nil && bufLen > 0 { @@ -64,13 +64,13 @@ func (this *WSPListener) socketRead(conn net.Conn) { for { { readBytes := bufLen - alreadyReadBytes - if readBytes > MAX_PACKET_LEN - recvBufLen { + if readBytes > MAX_PACKET_LEN-recvBufLen { readBytes = MAX_PACKET_LEN - recvBufLen } if readBytes > 0 { copy(recvBuf[recvBufLen:], - buf[alreadyReadBytes:alreadyReadBytes + readBytes]) + buf[alreadyReadBytes:alreadyReadBytes+readBytes]) recvBufLen += readBytes alreadyReadBytes += readBytes } @@ -87,9 +87,7 @@ func (this *WSPListener) socketRead(conn net.Conn) { } if offset > 0 && offset < recvBufLen { - copy(recvBuf[:], - recvBuf[offset:recvBufLen - offset]) - + copy(recvBuf[:], recvBuf[offset:]) } recvBufLen -= offset if recvBufLen >= MAX_PACKET_LEN { @@ -106,11 +104,11 @@ func (this *WSPListener) socketRead(conn net.Conn) { func (this *WSPListener) decodePacket(conn net.Conn, buf []byte, offset *int, bufLen int) { warning := false - for bufLen - *offset >= f5.WSPROXYPACKHEAD_C_SIZE { + for bufLen-*offset >= f5.WSPROXYPACKHEAD_C_SIZE { msgHead := f5.WSProxyPackHead_C{} msgHead.Read(buf, *offset) if msgHead.MagicCode == f5.NET_MSG_MAGIC_CODE { - if bufLen - *offset < int(f5.WSPROXYPACKHEAD_C_SIZE) + int(msgHead.PackLen) { + if bufLen-*offset < int(f5.WSPROXYPACKHEAD_C_SIZE)+int(msgHead.PackLen) { continue } hdr := new(f5.MsgHdr) @@ -118,8 +116,7 @@ func (this *WSPListener) decodePacket(conn net.Conn, buf []byte, offset *int, bu hdr.MsgId = msgHead.MsgId hdr.SocketHandle = msgHead.SocketHandle hdr.SeqId = msgHead.SeqId - hdr.Data = buf[int(*offset) + f5.WSPROXYPACKHEAD_C_SIZE: - int(*offset) + f5.WSPROXYPACKHEAD_C_SIZE + int(msgHead.PackLen)] + hdr.Data = buf[int(*offset)+f5.WSPROXYPACKHEAD_C_SIZE : int(*offset)+f5.WSPROXYPACKHEAD_C_SIZE+int(msgHead.PackLen)] this.ch <- hdr *offset += f5.WSPROXYPACKHEAD_C_SIZE + int(msgHead.PackLen) } else { @@ -166,8 +163,8 @@ func (this *WSPListener) sendProxyMsg(conn net.Conn, socketHandle uint16, msg pr msgHead.MagicCode = f5.NET_MSG_MAGIC_CODE msgHead.SocketHandle = socketHandle - buff := make([]byte, len(msgData) + f5.WSPROXYPACKHEAD_S_SIZE) - msgHead.Write(buff, 0); + buff := make([]byte, len(msgData)+f5.WSPROXYPACKHEAD_S_SIZE) + msgHead.Write(buff, 0) copy(buff[f5.WSPROXYPACKHEAD_S_SIZE:], msgData[:]) conn.Write(buff) } diff --git a/third_party/f5 b/third_party/f5 index 155220a3..fe1acddc 160000 --- a/third_party/f5 +++ b/third_party/f5 @@ -1 +1 @@ -Subproject commit 155220a3b249ce1aa57b3ce6fcefe5b647407c8e +Subproject commit fe1acddcc815ffb3359c460c1dff03ad20da42cd