mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 19:42:20 +00:00
Test splitHostPort error cases
This commit is contained in:
parent
aba6215bbc
commit
d1d6eb17b6
@ -33,19 +33,19 @@ type Packet struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Split host and port from listen address
|
// Split host and port from listen address
|
||||||
func splitHostPort(hostport string) (string, uint16) {
|
func splitHostPort(hostport string) (string, uint16, error) {
|
||||||
host, portS, err := net.SplitHostPort(hostport)
|
host, portS, err := net.SplitHostPort(hostport)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to split host and port from %s", hostport)
|
return "", 0, err
|
||||||
}
|
}
|
||||||
if host == "" {
|
if host == "" {
|
||||||
host = "0.0.0.0"
|
host = "0.0.0.0"
|
||||||
}
|
}
|
||||||
port64, err := strconv.ParseUint(portS, 10, 16)
|
port64, err := strconv.ParseUint(portS, 10, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Port is not a integer: %s", err)
|
return "", 0, err
|
||||||
}
|
}
|
||||||
return host, uint16(port64)
|
return host, uint16(port64), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetNumberConnectedSessions get the number of currently connected clients
|
// GetNumberConnectedSessions get the number of currently connected clients
|
||||||
@ -62,7 +62,10 @@ func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel, webrtcChan
|
|||||||
|
|
||||||
// Start SRT in listening mode
|
// Start SRT in listening mode
|
||||||
log.Printf("SRT server listening on %s", cfg.ListenAddress)
|
log.Printf("SRT server listening on %s", cfg.ListenAddress)
|
||||||
host, port := splitHostPort(cfg.ListenAddress)
|
host, port, err := splitHostPort(cfg.ListenAddress)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to split host and port from %s", cfg.ListenAddress)
|
||||||
|
}
|
||||||
sck := srtgo.NewSrtSocket(host, port, nil)
|
sck := srtgo.NewSrtSocket(host, port, nil)
|
||||||
if err := sck.Listen(cfg.MaxClients); err != nil {
|
if err := sck.Listen(cfg.MaxClients); err != nil {
|
||||||
log.Fatal("Unable to listen for SRT clients:", err)
|
log.Fatal("Unable to listen for SRT clients:", err)
|
||||||
|
@ -9,15 +9,35 @@ import (
|
|||||||
|
|
||||||
// TestSplitHostPort Try to split a host like 127.0.0.1:1234 in host, port (127.0.0.1, 1234à
|
// TestSplitHostPort Try to split a host like 127.0.0.1:1234 in host, port (127.0.0.1, 1234à
|
||||||
func TestSplitHostPort(t *testing.T) {
|
func TestSplitHostPort(t *testing.T) {
|
||||||
host, port := splitHostPort("127.0.0.1:1234")
|
// Split 127.0.0.1:1234
|
||||||
|
host, port, err := splitHostPort("127.0.0.1:1234")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to split host and port, %s", err)
|
||||||
|
}
|
||||||
if host != "127.0.0.1" || port != 1234 {
|
if host != "127.0.0.1" || port != 1234 {
|
||||||
t.Errorf("splitHostPort returned %v:%d != 127.0.0.1:1234", host, port)
|
t.Errorf("splitHostPort returned %v:%d != 127.0.0.1:1234", host, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
host, port = splitHostPort(":1234")
|
// Split :1234
|
||||||
|
host, port, err = splitHostPort(":1234")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Failed to split host and port, %s", err)
|
||||||
|
}
|
||||||
if host != "0.0.0.0" || port != 1234 {
|
if host != "0.0.0.0" || port != 1234 {
|
||||||
t.Errorf("splitHostPort returned %v:%d != 0.0.0.0:1234", host, port)
|
t.Errorf("splitHostPort returned %v:%d != 0.0.0.0:1234", host, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Split demo, should fail
|
||||||
|
host, port, err = splitHostPort("demo")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("splitHostPort managed to split unsplitable hostport")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split demo:port, should fail
|
||||||
|
host, port, err = splitHostPort("demo:port")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("splitHostPort managed to split unsplitable hostport")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestServeSRT Serve a SRT server, stream content during 5 seconds and ensure that it is well received
|
// TestServeSRT Serve a SRT server, stream content during 5 seconds and ensure that it is well received
|
||||||
|
Loading…
Reference in New Issue
Block a user