This is a bit too much boilerplate for these, which mainly do the same
thing.
We add annotaitons to new_peer_fd so the compiler knows that it cannot
return NULL, otherwise with -O3 we get:
```
lightningd/peer_control.c: In function ‘peer_connected_hook_final’:
lightningd/peer_control.c:1388:28: error: ‘error’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
1388 | take(towire_connectd_peer_send_msg(NULL, &channel->peer->id,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lightningd/peer_control.c:1313:19: note: ‘error’ was declared here
1313 | const u8 *error;
| ^~~~~
lightningd/peer_control.c: In function ‘peer_spoke’:
lightningd/peer_control.c:1999:28: error: ‘error’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
1999 | take(towire_connectd_peer_send_msg(NULL, &peer->id,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [Makefile:311: lightningd/peer_control.o] Error 1
```
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
22 lines
614 B
C
22 lines
614 B
C
#ifndef LIGHTNING_LIGHTNINGD_PEER_FD_H
|
|
#define LIGHTNING_LIGHTNINGD_PEER_FD_H
|
|
#include "config.h"
|
|
#include <ccan/compiler/compiler.h>
|
|
#include <ccan/tal/tal.h>
|
|
|
|
/* Tal wrapper for fd connecting subd to connectd */
|
|
struct peer_fd {
|
|
/* If not -1, closed on freeing */
|
|
int fd;
|
|
};
|
|
|
|
/* Allocate a new per-peer state and add destructor to close fd if set. */
|
|
RETURNS_NONNULL
|
|
struct peer_fd *new_peer_fd(const tal_t *ctx, int peer_fd);
|
|
|
|
/* Array version of above: tal_count(fds) must be 1 */
|
|
RETURNS_NONNULL
|
|
struct peer_fd *new_peer_fd_arr(const tal_t *ctx, const int *fd);
|
|
|
|
#endif /* LIGHTNING_LIGHTNINGD_PEER_FD_H */
|