1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#include "internals.h"
/* `tio_usb_send_bulk()`: send a USB bulk packet. */
TIO_EXTERN(int) tio_usb_send_bulk(tio_stream_t *stream,
unsigned char const *data, size_t size, unsigned int timeout /* in ms */)
{
int err;
tio_usb_send_bulk_t *func;
if (stream->tio_stream_dead_parent) {
err = tio_error_stream;
goto fail;
}
if (!(func = stream->tio_stream_usb_send_bulk)) {
err = stream->tio_stream_parent
? tio_usb_send_bulk(stream->tio_stream_parent, data, size,
timeout)
: tio_error_op;
goto fail;
}
/* Execute the request. */
if ((err = (*func)(stream->tio_stream_cookie, data, size, timeout)))
goto fail;
err = tio_ok;
fail:
stream->tio_stream_lasterr = err;
return (err);
}
/* `tio_usb_recv_bulk()`: receive an USB bulk packet. */
TIO_EXTERN(int) tio_usb_recv_bulk(tio_stream_t *stream, unsigned char *buf,
size_t size, unsigned int timeout /* in ms */)
{
int err;
tio_usb_recv_bulk_t *func;
if (stream->tio_stream_dead_parent) {
err = tio_error_stream;
goto fail;
}
if (!(func = stream->tio_stream_usb_recv_bulk)) {
err = stream->tio_stream_parent
? tio_usb_recv_bulk(stream->tio_stream_parent, buf, size, timeout)
: tio_error_op;
goto fail;
}
/* Execute the request. */
if ((err = (*func)(stream->tio_stream_cookie, buf, size, timeout)))
goto fail;
err = tio_ok;
fail:
stream->tio_stream_lasterr = err;
return (err);
}
|