diff --git a/usb/usb.go b/usb/usb.go index cf820a9..b106815 100644 --- a/usb/usb.go +++ b/usb/usb.go @@ -27,7 +27,7 @@ import ( type Context struct { ctx *C.libusb_context - done chan bool + done chan struct{} } func (c *Context) Debug(level int) { @@ -36,7 +36,7 @@ func (c *Context) Debug(level int) { func NewContext() *Context { c := &Context{ - done: make(chan bool), + done: make(chan struct{}), } if errno := C.libusb_init(&c.ctx); errno != 0 { @@ -44,7 +44,10 @@ func NewContext() *Context { } go func() { - tv := C.struct_timeval{0, 100000} + tv := C.struct_timeval{ + tv_sec: 0, + tv_usec: 100000, + } for { select { case <-c.done: @@ -104,7 +107,6 @@ func (c *Context) ListDevices(each func(desc *Descriptor) bool) ([]*Device, erro } func (c *Context) Close() error { - c.done <- true close(c.done) if c.ctx != nil { C.libusb_exit(c.ctx) diff --git a/usb/usb.test b/usb/usb.test new file mode 100755 index 0000000..2cd1d0f Binary files /dev/null and b/usb/usb.test differ diff --git a/usb/usb_test.go b/usb/usb_test.go index 78c4159..22aad4f 100644 --- a/usb/usb_test.go +++ b/usb/usb_test.go @@ -84,7 +84,7 @@ func TestEnum(t *testing.T) { func TestMultipleContexts(t *testing.T) { var buf bytes.Buffer log.SetOutput(&buf) - for i := 0; i < 10; i++ { + for i := 0; i < 2; i++ { ctx := NewContext() _, err := ctx.ListDevices(func(desc *Descriptor) bool { return false