Common pattern: create a sockpair for this channel, return one as a peer_fd */
| 50 | |
| 51 | /* Common pattern: create a sockpair for this channel, return one as a peer_fd */ |
| 52 | struct peer_fd *sockpair(const tal_t *ctx, struct channel *channel, |
| 53 | int *otherfd, const u8 **warning) |
| 54 | { |
| 55 | int fds[2]; |
| 56 | |
| 57 | if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) != 0) { |
| 58 | /* Note: preserves errno! */ |
| 59 | log_broken(channel->log, |
| 60 | "Failed to create socketpair: %s", |
| 61 | strerror(errno)); |
| 62 | if (warning) |
| 63 | *warning = towire_warningfmt(ctx, &channel->cid, |
| 64 | "Trouble in paradise?"); |
| 65 | return NULL; |
| 66 | } |
| 67 | *otherfd = fds[1]; |
| 68 | return new_peer_fd(ctx, fds[0]); |
| 69 | } |
| 70 | |
| 71 | static void destroy_peer(struct peer *peer) |
| 72 | { |
no test coverage detected