Allocate libusb buffers in C (#11)
* add alloc/free_transfer_and_buffer. Manages the buffer memory on the C side. * switch libusb.go to use the new alloc/free_transfer_and_buffer. Add a new buffer() call to get access to the allocated buffer as a Go slice. * Fake USB transfer uses the new alloc/free/buffer interface. * Switch to the new libusb.alloc signature, where libusb owns the buffer. * newUSBTransfer now allocates a separate buffer, do a copy on endpoint.transfer. * newUSBTransfer will now allocate it's own buffer. * Enable autodetach in rawread.
This commit is contained in:
@@ -89,17 +89,23 @@ func (e *endpoint) transfer(buf []byte) (int, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
t, err := newUSBTransfer(e.h, &e.Desc, buf, e.Timeout)
|
||||
t, err := newUSBTransfer(e.h, &e.Desc, len(buf), e.Timeout)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer t.free()
|
||||
if e.Desc.Direction == EndpointDirectionOut {
|
||||
copy(t.data(), buf)
|
||||
}
|
||||
|
||||
if err := t.submit(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
n, err := t.wait()
|
||||
if e.Desc.Direction == EndpointDirectionIn {
|
||||
copy(buf, t.data())
|
||||
}
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user