Add context-aware read/write (#57)

Adds ReadContext/WriteContext methods to endpoints and to streams. Update rawread example tool to use ReadContext for implementation of "timeout" flag.
This commit is contained in:
Sebastian Zagrodzki
2018-11-05 15:33:31 +01:00
committed by GitHub
parent 593cfb67e9
commit da849d96b5
11 changed files with 273 additions and 80 deletions

View File

@@ -17,7 +17,7 @@ package gousb
func (e *endpoint) newStream(size, count int) (*stream, error) {
var ts []transferIntf
for i := 0; i < count; i++ {
t, err := newUSBTransfer(e.ctx, e.h, &e.Desc, size, e.Timeout)
t, err := newUSBTransfer(e.ctx, e.h, &e.Desc, size)
if err != nil {
for _, t := range ts {
t.free()
@@ -29,8 +29,8 @@ func (e *endpoint) newStream(size, count int) (*stream, error) {
return newStream(ts), nil
}
// NewStream prepares a new read stream that will keep reading data from the
// endpoint until closed.
// NewStream prepares a new read stream that will keep reading data from
// the endpoint until closed or until an error or timeout is encountered.
// Size defines a buffer size for a single read transaction and count
// defines how many transactions should be active at any time.
// By keeping multiple transfers active at the same time, a Stream reduces
@@ -44,11 +44,11 @@ func (e *InEndpoint) NewStream(size, count int) (*ReadStream, error) {
return &ReadStream{s: s}, nil
}
// NewStream prepares a new write stream that will write data in the background.
// Size defines a buffer size for a single write transaction and count
// defines how many transactions may be active at any time.
// By buffering the writes, a Stream reduces the latency between subsequent
// transfers and increases writing throughput.
// NewStream prepares a new write stream that will write data in the
// background. Size defines a buffer size for a single write transaction and
// count defines how many transactions may be active at any time. By buffering
// the writes, a Stream reduces the latency between subsequent transfers and
// increases writing throughput.
func (e *OutEndpoint) NewStream(size, count int) (*WriteStream, error) {
s, err := e.newStream(size, count)
if err != nil {