优化网络IO使用buffer读取

This commit is contained in:
yangjiechina
2024-06-15 19:31:17 +08:00
parent 17973b3e9e
commit 89de34bd98
22 changed files with 355 additions and 288 deletions

View File

@@ -41,16 +41,20 @@ func (s *server) Close() {
panic("implement me")
}
func (s *server) OnConnected(conn net.Conn) {
func (s *server) OnConnected(conn net.Conn) []byte {
log.Sugar.Debugf("rtmp连接 conn:%s", conn.RemoteAddr().String())
t := conn.(*transport.Conn)
t.Data = NewSession(conn)
return nil
}
func (s *server) OnPacket(conn net.Conn, data []byte) {
func (s *server) OnPacket(conn net.Conn, data []byte) []byte {
log.Sugar.Infof("rtmp包大小:%d", len(data))
t := conn.(*transport.Conn)
err := t.Data.(*Session).Input(conn, data)
session := t.Data.(*Session)
err := session.Input(conn, data)
if err != nil {
log.Sugar.Errorf("处理rtmp包失败 err:%s conn:%s", err.Error(), conn.RemoteAddr().String())
@@ -59,6 +63,12 @@ func (s *server) OnPacket(conn net.Conn, data []byte) {
t.Data.(*Session).Close()
t.Data = nil
}
if session.isPublisher {
return session.receiveBuffer.GetBlock()
}
return nil
}
func (s *server) OnDisConnected(conn net.Conn, err error) {