MCPcopy Create free account
hub / github.com/ElementsProject/lightning / do_read_wire_header

Function do_read_wire_header

wire/wire_io.c:22–51  ·  view source on GitHub ↗

arg->u2.s contains length we've read, arg->u1.vp contains u8 **data. */

Source from the content-addressed store, hash-verified

20
21/* arg->u2.s contains length we've read, arg->u1.vp contains u8 **data. */
22static int do_read_wire_header(int fd, struct io_plan_arg *arg)
23{
24 ssize_t ret;
25 size_t len = arg->u2.s & ~INSIDE_HEADER_BIT;
26 u8 *p = *(u8 **)arg->u1.vp;
27
28 ret = read(fd, p + len, HEADER_LEN - len);
29 if (ret <= 0) {
30 /* Errno isn't set if we hit EOF, so set it to distinct value */
31 if (ret == 0)
32 errno = 0;
33 return -1;
34 }
35 arg->u2.s += ret;
36
37 /* Length bytes read? Set up for normal read of data. */
38 if (arg->u2.s == INSIDE_HEADER_BIT + HEADER_LEN) {
39 arg->u2.s = wirelen_to_cpu(*(wire_len_t *)p);
40 if (arg->u2.s >= INSIDE_HEADER_BIT) {
41 errno = E2BIG;
42 return -1;
43 }
44 /* A type-only message is not unheard of, so optimize a little */
45 if (arg->u2.s != HEADER_LEN)
46 tal_resize((u8 **)arg->u1.vp, arg->u2.s);
47 arg->u1.vp = *(u8 **)arg->u1.vp;
48 }
49
50 return arg->u2.s == 0;
51}
52
53static int do_read_wire(int fd, struct io_plan_arg *arg)
54{

Callers 1

do_read_wireFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected