2021-12-04 21:53:56 +10:30
|
|
|
#include "config.h"
|
2017-02-21 15:15:29 +10:30
|
|
|
#include <ccan/read_write_all/read_write_all.h>
|
2017-08-29 01:35:01 +09:30
|
|
|
#include <common/cryptomsg.h>
|
2018-08-02 16:19:55 +09:30
|
|
|
#include <common/peer_failed.h>
|
2022-01-08 23:53:29 +10:30
|
|
|
#include <common/peer_io.h>
|
2019-06-04 03:41:25 +09:30
|
|
|
#include <common/per_peer_state.h>
|
2017-08-29 01:35:01 +09:30
|
|
|
#include <common/status.h>
|
2017-02-24 16:22:56 +10:30
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
2018-08-09 10:00:30 +09:30
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2021-09-19 13:07:58 +02:00
|
|
|
#include <sys/socket.h>
|
2017-05-24 19:40:16 +09:30
|
|
|
#include <wire/wire.h>
|
2022-01-08 23:52:29 +10:30
|
|
|
#include <wire/wire_io.h>
|
|
|
|
#include <wire/wire_sync.h>
|
2017-02-21 15:15:29 +10:30
|
|
|
|
2022-01-08 23:53:29 +10:30
|
|
|
void peer_write(struct per_peer_state *pps, const void *msg TAKES)
|
2017-02-21 15:15:29 +10:30
|
|
|
{
|
2019-11-17 22:12:33 +10:30
|
|
|
status_peer_io(LOG_IO_OUT, NULL, msg);
|
2018-02-05 14:39:28 +10:30
|
|
|
|
2022-01-11 11:47:30 +10:30
|
|
|
/* We ignore write errors; we might still have something to read,
|
|
|
|
* so we'd rather fail there. */
|
|
|
|
wire_sync_write(pps->peer_fd, msg);
|
2017-02-21 15:15:29 +10:30
|
|
|
}
|
|
|
|
|
2022-01-08 23:53:29 +10:30
|
|
|
u8 *peer_read(const tal_t *ctx, struct per_peer_state *pps)
|
2017-02-21 15:15:29 +10:30
|
|
|
{
|
2022-01-11 11:45:58 +10:30
|
|
|
u8 *msg = wire_sync_read(ctx, pps->peer_fd);
|
|
|
|
if (!msg)
|
2018-08-02 16:19:55 +09:30
|
|
|
peer_failed_connection_lost();
|
2022-01-08 23:52:29 +10:30
|
|
|
|
2022-01-11 11:45:58 +10:30
|
|
|
status_peer_io(LOG_IO_IN, NULL, msg);
|
2018-02-05 14:39:28 +10:30
|
|
|
|
2022-01-11 11:45:58 +10:30
|
|
|
return msg;
|
2017-02-21 15:15:29 +10:30
|
|
|
}
|