mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 18:11:28 +01:00
4ffda340d3
And turn "" includes into full-path (which makes it easier to put config.h first, and finds some cases check-includes.sh missed previously). config.h sets _GNU_SOURCE which really needs to be done before any '#includes': we mainly got away with it with glibc, but other platforms like Alpine may have stricter requirements. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
49 lines
747 B
C
49 lines
747 B
C
#include "config.h"
|
|
#include <ccan/noerr/noerr.h>
|
|
#include <common/socket_close.h>
|
|
#include <errno.h>
|
|
#include <sys/socket.h>
|
|
#include <unistd.h>
|
|
|
|
/*
|
|
Simplified (minus all the error checks):
|
|
|
|
shutdown(fd, SHUT_WR);
|
|
for (;;) {
|
|
char unused[64]
|
|
sys_res = read(fd, unused, 64);
|
|
if (sys_res == 0)
|
|
break;
|
|
}
|
|
close(fd);
|
|
*/
|
|
|
|
bool socket_close(int fd)
|
|
{
|
|
char unused[64];
|
|
int sys_res;
|
|
|
|
sys_res = shutdown(fd, SHUT_WR);
|
|
if (sys_res < 0) {
|
|
close_noerr(fd);
|
|
return false;
|
|
}
|
|
|
|
for (;;) {
|
|
do {
|
|
sys_res = read(fd, unused, sizeof(unused));
|
|
} while (sys_res < 0 && errno == EINTR);
|
|
if (sys_res < 0) {
|
|
close_noerr(fd);
|
|
return false;
|
|
}
|
|
if (sys_res == 0)
|
|
break;
|
|
}
|
|
|
|
if (close(fd) < 0)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|