chore: tuic-server support heartbeat command

This commit is contained in:
gVisor bot 2022-11-28 18:28:22 +08:00
parent 81e03ec904
commit df306be1ec
2 changed files with 9 additions and 2 deletions

View file

@ -349,7 +349,7 @@ func NewHeartbeat() Heartbeat {
} }
} }
func ReadHeartbeatWithHead(head CommandHead, reader BufferedReader) (c Response, err error) { func ReadHeartbeatWithHead(head CommandHead, reader BufferedReader) (c Heartbeat, err error) {
c.CommandHead = head c.CommandHead = head
if c.CommandHead.TYPE != HeartbeatType { if c.CommandHead.TYPE != HeartbeatType {
err = fmt.Errorf("error command type: %s", c.CommandHead.TYPE) err = fmt.Errorf("error command type: %s", c.CommandHead.TYPE)
@ -357,7 +357,7 @@ func ReadHeartbeatWithHead(head CommandHead, reader BufferedReader) (c Response,
return return
} }
func ReadHeartbeat(reader BufferedReader) (c Response, err error) { func ReadHeartbeat(reader BufferedReader) (c Heartbeat, err error) {
head, err := ReadCommandHead(reader) head, err := ReadCommandHead(reader)
if err != nil { if err != nil {
return return

View file

@ -261,6 +261,13 @@ func (s *serverHandler) handleUniStream() (err error) {
writeClosed := v.(*atomic.Bool) writeClosed := v.(*atomic.Bool)
writeClosed.Store(true) writeClosed.Store(true)
} }
case HeartbeatType:
var heartbeat Heartbeat
heartbeat, err = ReadHeartbeatWithHead(commandHead, reader)
if err != nil {
return
}
heartbeat.BytesLen()
} }
return return
}() }()