Fixes #2, allow server goroutines to exit on deadlines and context cancel.

This commit is contained in:
Jonas Köritz 2019-10-15 12:59:06 +02:00
parent 03ca0f77e6
commit e82f5a97c9
5 changed files with 108 additions and 58 deletions

View file

@ -61,7 +61,10 @@ type StoredFile struct {
}
// CreateCamera creates a new Camera instance
func CreateCamera(ipAddress net.IP, port int, username, password string) *Camera {
func CreateCamera(ipAddress net.IP, port int, username, password string) (*Camera, error) {
if ipAddress == nil {
return nil, errors.New("Cannot create camera without an IP-Address")
}
camera := &Camera{
ipAddress: ipAddress,
port: port,
@ -70,7 +73,7 @@ func CreateCamera(ipAddress net.IP, port int, username, password string) *Camera
messageHandlers: make(map[uint32][]MessageHandler, 0),
verbose: true,
}
return camera
return camera, nil
}
// Connect to the camera and start responding to keepalive packets