rename ConnServer into ServerConn

This commit is contained in:
aler9
2020-12-05 21:22:33 +01:00
parent 2315ec4bd4
commit 2c9d9ebd75

View File

@@ -14,8 +14,8 @@ const (
serverWriteBufferSize = 4096 serverWriteBufferSize = 4096
) )
// ConnServerConf allows to configure a ConnServer. // ServerConnConf allows to configure a ServerConn.
type ConnServerConf struct { type ServerConnConf struct {
// pre-existing TCP connection to wrap // pre-existing TCP connection to wrap
Conn net.Conn Conn net.Conn
@@ -34,9 +34,9 @@ type ConnServerConf struct {
ReadBufferCount int ReadBufferCount int
} }
// ConnServer is a server-side RTSP connection. // ServerConn is a server-side RTSP connection.
type ConnServer struct { type ServerConn struct {
conf ConnServerConf conf ServerConnConf
br *bufio.Reader br *bufio.Reader
bw *bufio.Writer bw *bufio.Writer
request *base.Request request *base.Request
@@ -44,8 +44,8 @@ type ConnServer struct {
tcpFrameBuffer *multibuffer.MultiBuffer tcpFrameBuffer *multibuffer.MultiBuffer
} }
// NewConnServer allocates a ConnServer. // NewServerConn allocates a ServerConn.
func NewConnServer(conf ConnServerConf) *ConnServer { func NewServerConn(conf ServerConnConf) *ServerConn {
if conf.ReadTimeout == 0 { if conf.ReadTimeout == 0 {
conf.ReadTimeout = 10 * time.Second conf.ReadTimeout = 10 * time.Second
} }
@@ -56,7 +56,7 @@ func NewConnServer(conf ConnServerConf) *ConnServer {
conf.ReadBufferCount = 1 conf.ReadBufferCount = 1
} }
return &ConnServer{ return &ServerConn{
conf: conf, conf: conf,
br: bufio.NewReaderSize(conf.Conn, serverReadBufferSize), br: bufio.NewReaderSize(conf.Conn, serverReadBufferSize),
bw: bufio.NewWriterSize(conf.Conn, serverWriteBufferSize), bw: bufio.NewWriterSize(conf.Conn, serverWriteBufferSize),
@@ -66,18 +66,18 @@ func NewConnServer(conf ConnServerConf) *ConnServer {
} }
} }
// Close closes all the ConnServer resources. // Close closes all the ServerConn resources.
func (s *ConnServer) Close() error { func (s *ServerConn) Close() error {
return s.conf.Conn.Close() return s.conf.Conn.Close()
} }
// NetConn returns the underlying net.Conn. // NetConn returns the underlying net.Conn.
func (s *ConnServer) NetConn() net.Conn { func (s *ServerConn) NetConn() net.Conn {
return s.conf.Conn return s.conf.Conn
} }
// ReadRequest reads a Request. // ReadRequest reads a Request.
func (s *ConnServer) ReadRequest() (*base.Request, error) { func (s *ServerConn) ReadRequest() (*base.Request, error) {
s.conf.Conn.SetReadDeadline(time.Time{}) // disable deadline s.conf.Conn.SetReadDeadline(time.Time{}) // disable deadline
err := s.request.Read(s.br) err := s.request.Read(s.br)
if err != nil { if err != nil {
@@ -88,7 +88,7 @@ func (s *ConnServer) ReadRequest() (*base.Request, error) {
} }
// ReadFrameTCPOrRequest reads an InterleavedFrame or a Request. // ReadFrameTCPOrRequest reads an InterleavedFrame or a Request.
func (s *ConnServer) ReadFrameTCPOrRequest(timeout bool) (interface{}, error) { func (s *ServerConn) ReadFrameTCPOrRequest(timeout bool) (interface{}, error) {
s.frame.Content = s.tcpFrameBuffer.Next() s.frame.Content = s.tcpFrameBuffer.Next()
if timeout { if timeout {
@@ -99,13 +99,13 @@ func (s *ConnServer) ReadFrameTCPOrRequest(timeout bool) (interface{}, error) {
} }
// WriteResponse writes a Response. // WriteResponse writes a Response.
func (s *ConnServer) WriteResponse(res *base.Response) error { func (s *ServerConn) WriteResponse(res *base.Response) error {
s.conf.Conn.SetWriteDeadline(time.Now().Add(s.conf.WriteTimeout)) s.conf.Conn.SetWriteDeadline(time.Now().Add(s.conf.WriteTimeout))
return res.Write(s.bw) return res.Write(s.bw)
} }
// WriteFrameTCP writes an InterleavedFrame. // WriteFrameTCP writes an InterleavedFrame.
func (s *ConnServer) WriteFrameTCP(trackID int, streamType StreamType, content []byte) error { func (s *ServerConn) WriteFrameTCP(trackID int, streamType StreamType, content []byte) error {
frame := base.InterleavedFrame{ frame := base.InterleavedFrame{
TrackID: trackID, TrackID: trackID,
StreamType: streamType, StreamType: streamType,