code format

This commit is contained in:
殷勇 2023-09-04 18:32:44 +08:00
parent 130b3b878e
commit e4b1bd4038
2 changed files with 18 additions and 21 deletions

View File

@ -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)
}

2
third_party/f5 vendored

@ -1 +1 @@
Subproject commit 155220a3b249ce1aa57b3ce6fcefe5b647407c8e
Subproject commit fe1acddcc815ffb3359c460c1dff03ad20da42cd