code format
This commit is contained in:
parent
130b3b878e
commit
e4b1bd4038
@ -1,14 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
|
|
||||||
"q5"
|
|
||||||
"f5"
|
|
||||||
"cs"
|
"cs"
|
||||||
"ss"
|
"f5"
|
||||||
"mt"
|
"mt"
|
||||||
|
"q5"
|
||||||
|
"ss"
|
||||||
|
|
||||||
proto "github.com/golang/protobuf/proto"
|
proto "github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
@ -16,13 +16,13 @@ import (
|
|||||||
type WSPListener struct {
|
type WSPListener struct {
|
||||||
ss.MsgHandlerImpl
|
ss.MsgHandlerImpl
|
||||||
listener net.Listener
|
listener net.Listener
|
||||||
ch chan *f5.MsgHdr
|
ch chan *f5.MsgHdr
|
||||||
msgList q5.ListHead
|
msgList q5.ListHead
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *WSPListener) init() {
|
func (this *WSPListener) init() {
|
||||||
this.ch = make(chan *f5.MsgHdr)
|
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()))
|
q5.ToString(mt.Table.IMCluster.GetListenPort()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
@ -54,9 +54,9 @@ func (this *WSPListener) accept() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *WSPListener) socketRead(conn net.Conn) {
|
func (this *WSPListener) socketRead(conn net.Conn) {
|
||||||
buf := make([]byte, 1024 * 64)
|
buf := make([]byte, 1024*64)
|
||||||
recvBufLen := 0
|
recvBufLen := 0
|
||||||
recvBuf := make([]byte, 1024 * 64 * 2)
|
recvBuf := make([]byte, 1024*64*2)
|
||||||
for {
|
for {
|
||||||
bufLen, err := conn.Read(buf)
|
bufLen, err := conn.Read(buf)
|
||||||
if err == nil && bufLen > 0 {
|
if err == nil && bufLen > 0 {
|
||||||
@ -64,13 +64,13 @@ func (this *WSPListener) socketRead(conn net.Conn) {
|
|||||||
for {
|
for {
|
||||||
{
|
{
|
||||||
readBytes := bufLen - alreadyReadBytes
|
readBytes := bufLen - alreadyReadBytes
|
||||||
if readBytes > MAX_PACKET_LEN - recvBufLen {
|
if readBytes > MAX_PACKET_LEN-recvBufLen {
|
||||||
readBytes = MAX_PACKET_LEN - recvBufLen
|
readBytes = MAX_PACKET_LEN - recvBufLen
|
||||||
}
|
}
|
||||||
|
|
||||||
if readBytes > 0 {
|
if readBytes > 0 {
|
||||||
copy(recvBuf[recvBufLen:],
|
copy(recvBuf[recvBufLen:],
|
||||||
buf[alreadyReadBytes:alreadyReadBytes + readBytes])
|
buf[alreadyReadBytes:alreadyReadBytes+readBytes])
|
||||||
recvBufLen += readBytes
|
recvBufLen += readBytes
|
||||||
alreadyReadBytes += readBytes
|
alreadyReadBytes += readBytes
|
||||||
}
|
}
|
||||||
@ -87,9 +87,7 @@ func (this *WSPListener) socketRead(conn net.Conn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if offset > 0 && offset < recvBufLen {
|
if offset > 0 && offset < recvBufLen {
|
||||||
copy(recvBuf[:],
|
copy(recvBuf[:], recvBuf[offset:])
|
||||||
recvBuf[offset:recvBufLen - offset])
|
|
||||||
|
|
||||||
}
|
}
|
||||||
recvBufLen -= offset
|
recvBufLen -= offset
|
||||||
if recvBufLen >= MAX_PACKET_LEN {
|
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) {
|
func (this *WSPListener) decodePacket(conn net.Conn, buf []byte, offset *int, bufLen int) {
|
||||||
warning := false
|
warning := false
|
||||||
for bufLen - *offset >= f5.WSPROXYPACKHEAD_C_SIZE {
|
for bufLen-*offset >= f5.WSPROXYPACKHEAD_C_SIZE {
|
||||||
msgHead := f5.WSProxyPackHead_C{}
|
msgHead := f5.WSProxyPackHead_C{}
|
||||||
msgHead.Read(buf, *offset)
|
msgHead.Read(buf, *offset)
|
||||||
if msgHead.MagicCode == f5.NET_MSG_MAGIC_CODE {
|
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
|
continue
|
||||||
}
|
}
|
||||||
hdr := new(f5.MsgHdr)
|
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.MsgId = msgHead.MsgId
|
||||||
hdr.SocketHandle = msgHead.SocketHandle
|
hdr.SocketHandle = msgHead.SocketHandle
|
||||||
hdr.SeqId = msgHead.SeqId
|
hdr.SeqId = msgHead.SeqId
|
||||||
hdr.Data = buf[int(*offset) + f5.WSPROXYPACKHEAD_C_SIZE:
|
hdr.Data = buf[int(*offset)+f5.WSPROXYPACKHEAD_C_SIZE : int(*offset)+f5.WSPROXYPACKHEAD_C_SIZE+int(msgHead.PackLen)]
|
||||||
int(*offset) + f5.WSPROXYPACKHEAD_C_SIZE + int(msgHead.PackLen)]
|
|
||||||
this.ch <- hdr
|
this.ch <- hdr
|
||||||
*offset += f5.WSPROXYPACKHEAD_C_SIZE + int(msgHead.PackLen)
|
*offset += f5.WSPROXYPACKHEAD_C_SIZE + int(msgHead.PackLen)
|
||||||
} else {
|
} else {
|
||||||
@ -166,8 +163,8 @@ func (this *WSPListener) sendProxyMsg(conn net.Conn, socketHandle uint16, msg pr
|
|||||||
msgHead.MagicCode = f5.NET_MSG_MAGIC_CODE
|
msgHead.MagicCode = f5.NET_MSG_MAGIC_CODE
|
||||||
msgHead.SocketHandle = socketHandle
|
msgHead.SocketHandle = socketHandle
|
||||||
|
|
||||||
buff := make([]byte, len(msgData) + f5.WSPROXYPACKHEAD_S_SIZE)
|
buff := make([]byte, len(msgData)+f5.WSPROXYPACKHEAD_S_SIZE)
|
||||||
msgHead.Write(buff, 0);
|
msgHead.Write(buff, 0)
|
||||||
copy(buff[f5.WSPROXYPACKHEAD_S_SIZE:], msgData[:])
|
copy(buff[f5.WSPROXYPACKHEAD_S_SIZE:], msgData[:])
|
||||||
conn.Write(buff)
|
conn.Write(buff)
|
||||||
}
|
}
|
||||||
|
2
third_party/f5
vendored
2
third_party/f5
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 155220a3b249ce1aa57b3ce6fcefe5b647407c8e
|
Subproject commit fe1acddcc815ffb3359c460c1dff03ad20da42cd
|
Loading…
x
Reference in New Issue
Block a user