mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 07:06:58 +08:00
add new Server struct
This commit is contained in:
56
serverconf.go
Normal file
56
serverconf.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package gortsplib
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DefaultServerConf is the default ServerConf.
|
||||
var DefaultServerConf = ServerConf{}
|
||||
|
||||
// Serve starts a server on the given address.
|
||||
func Serve(address string, handler ServerHandler) (*Server, error) {
|
||||
return DefaultServerConf.Serve(address, handler)
|
||||
}
|
||||
|
||||
// ServerConf allows to configure a Server.
|
||||
// All fields are optional.
|
||||
type ServerConf struct {
|
||||
// timeout of read operations.
|
||||
// It defaults to 10 seconds
|
||||
ReadTimeout time.Duration
|
||||
|
||||
// timeout of write operations.
|
||||
// It defaults to 10 seconds
|
||||
WriteTimeout time.Duration
|
||||
|
||||
// read buffer count.
|
||||
// If greater than 1, allows to pass buffers to routines different than the one
|
||||
// that is reading frames.
|
||||
// It defaults to 1
|
||||
ReadBufferCount int
|
||||
|
||||
// function used to initialize the TCP listener.
|
||||
// It defaults to net.ListenTCP.
|
||||
ListenTCP func(network string, address *net.TCPAddr) (*net.TCPListener, error)
|
||||
}
|
||||
|
||||
// Serve starts a server on the given address.
|
||||
func (c ServerConf) Serve(address string, handler ServerHandler) (*Server, error) {
|
||||
addr, err := net.ResolveTCPAddr("tcp", address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
listener, err := c.ListenTCP("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s := &Server{
|
||||
c: c,
|
||||
listener: listener,
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
Reference in New Issue
Block a user