diff --git a/gotasks/specgen_task.go b/gotasks/specgen_task.go index 921e8c8..438b694 100644 --- a/gotasks/specgen_task.go +++ b/gotasks/specgen_task.go @@ -412,7 +412,7 @@ func unmarshalXmlFile(file *zip.File, data interface{}) error { return err } decoder := xml.NewDecoder(r) - r.Close() + defer r.Close() return decoder.Decode(data) } diff --git a/httpu/httpu.go b/httpu/httpu.go index 862c3de..f52dad6 100644 --- a/httpu/httpu.go +++ b/httpu/httpu.go @@ -3,6 +3,7 @@ package httpu import ( "bufio" "bytes" + "errors" "fmt" "log" "net" @@ -28,6 +29,20 @@ func NewHTTPUClient() (*HTTPUClient, error) { return &HTTPUClient{conn: conn}, nil } +// NewHTTPUClientAddr creates a new HTTPUClient which will broadcast packets +// from the specified address, opening up a new UDP socket for the purpose +func NewHTTPUClientAddr(addr string) (*HTTPUClient, error) { + ip := net.ParseIP(addr) + if ip == nil { + return nil, errors.New("Invalid listening address") + } + conn, err := net.ListenPacket("udp", ip.String()+":0") + if err != nil { + return nil, err + } + return &HTTPUClient{conn: conn}, nil +} + // Close shuts down the client. The client will no longer be useful following // this. func (httpu *HTTPUClient) Close() error { diff --git a/ssdp/registry.go b/ssdp/registry.go index 2f84bea..d3bc114 100644 --- a/ssdp/registry.go +++ b/ssdp/registry.go @@ -18,7 +18,7 @@ const ( ) var ( - maxAgeRx = regexp.MustCompile("max-age=([0-9]+)") + maxAgeRx = regexp.MustCompile("max-age= *([0-9]+)") ) const (