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