mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
dev_disconnect: make it more reliable.
I have seen some strange flakiness (under VALGRIND), which I have traced down to dev-disconnect "+" not working as expected. In particular, the message is not sent out before closing the fd. This seems to fix it on Linux, though it's so intermittant that it's hard to be completely sure. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
6e7cfcc76e
commit
2b7e5f7f5a
@ -4,6 +4,8 @@
|
||||
#include <common/dev_disconnect.h>
|
||||
#include <common/status.h>
|
||||
#include <fcntl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
@ -96,6 +98,15 @@ void dev_sabotage_fd(int fd)
|
||||
|
||||
/* Close one. */
|
||||
close(fds[0]);
|
||||
|
||||
#if defined(TCP_NODELAY)
|
||||
/* On Linux, at least, this flushes. */
|
||||
int opt = TCP_NODELAY;
|
||||
int val = 1;
|
||||
setsockopt(fd, IPPROTO_TCP, opt, &val, sizeof(val));
|
||||
#else
|
||||
#error No TCP_NODELAY?
|
||||
#endif
|
||||
/* Move other over to the fd we want to sabotage. */
|
||||
dup2(fds[1], fd);
|
||||
close(fds[1]);
|
||||
|
Loading…
Reference in New Issue
Block a user