mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-04 03:03:51 +01:00
common/socket_close: remove now only connectd talks to peer.
connectd does this internally now using ccan/io, with appropriate credit for ZmnSCPxj who wrote this code in the first place. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
3281d72169
commit
be299c0d59
5 changed files with 1 additions and 78 deletions
|
@ -50,7 +50,6 @@ CLOSINGD_COMMON_OBJS := \
|
|||
common/status_wiregen.o \
|
||||
common/read_peer_msg.o \
|
||||
common/setup.o \
|
||||
common/socket_close.o \
|
||||
common/status.o \
|
||||
common/status_wire.o \
|
||||
common/subdaemon.o \
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <common/peer_io.h>
|
||||
#include <common/per_peer_state.h>
|
||||
#include <common/read_peer_msg.h>
|
||||
#include <common/socket_close.h>
|
||||
#include <common/status.h>
|
||||
#include <common/subdaemon.h>
|
||||
#include <common/type_to_string.h>
|
||||
|
@ -1097,10 +1096,7 @@ exit_thru_the_giftshop:
|
|||
#endif
|
||||
|
||||
/* We're done! */
|
||||
/* Properly close the channel first. */
|
||||
if (!socket_close(pps->peer_fd))
|
||||
status_unusual("Closing and draining peerfd gave error: %s",
|
||||
strerror(errno));
|
||||
|
||||
/* Sending the below will kill us! */
|
||||
wire_sync_write(REQ_FD, take(towire_closingd_complete(NULL)));
|
||||
tal_free(ctx);
|
||||
|
|
|
@ -76,7 +76,6 @@ COMMON_SRC_NOGEN := \
|
|||
common/route.c \
|
||||
common/setup.c \
|
||||
common/shutdown_scriptpubkey.c \
|
||||
common/socket_close.c \
|
||||
common/sphinx.c \
|
||||
common/status.c \
|
||||
common/status_levels.c \
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
#include "config.h"
|
||||
#include <ccan/noerr/noerr.h>
|
||||
#include <common/socket_close.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* makes read() return EINTR after 5 seconds */
|
||||
static void break_read(int signum)
|
||||
{
|
||||
}
|
||||
|
||||
bool socket_close(int fd)
|
||||
{
|
||||
char unused[64];
|
||||
struct sigaction act, old_act;
|
||||
int sys_res, saved_errno;
|
||||
|
||||
/* We shutdown. Usually they then shutdown too, and read() gives 0 */
|
||||
sys_res = shutdown(fd, SHUT_WR);
|
||||
if (sys_res < 0) {
|
||||
close_noerr(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Let's not get too enthusiastic about waiting. */
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = break_read;
|
||||
sigaction(SIGALRM, &act, &old_act);
|
||||
|
||||
alarm(5);
|
||||
|
||||
while ((sys_res = read(fd, unused, sizeof(unused))) > 0);
|
||||
saved_errno = errno;
|
||||
|
||||
alarm(0);
|
||||
sigaction(SIGALRM, &old_act, NULL);
|
||||
|
||||
if (sys_res < 0) {
|
||||
close(fd);
|
||||
errno = saved_errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
return close(fd) == 0;
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/* common/socket_close - Properly close a socket,
|
||||
* ensuring that any data we write just before
|
||||
* the close has been transmitted to the other
|
||||
* side, and ignoring any data the other side
|
||||
* has sent at the time the close was started.
|
||||
*
|
||||
* Reference:
|
||||
*
|
||||
* http://ia800504.us.archive.org/3/items/TheUltimateSo_lingerPageOrWhyIsMyTcpNotReliable/the-ultimate-so_linger-page-or-why-is-my-tcp-not-reliable.html
|
||||
*/
|
||||
#ifndef LIGHTNING_COMMON_SOCKET_CLOSE_H
|
||||
#define LIGHTNING_COMMON_SOCKET_CLOSE_H
|
||||
#include "config.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Return false if something failed, true if
|
||||
* nothing failed.
|
||||
* If something failed, error is stored in
|
||||
* `errno.
|
||||
*/
|
||||
bool socket_close(int fd);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_SOCKET_CLOSE_H */
|
Loading…
Add table
Reference in a new issue