Fix --connect-send. Half-close connections so we can detect two read sockets talking to each other.

This commit is contained in:
Ian Gulliver
2016-02-24 20:25:31 -08:00
parent 1635534243
commit 3e2c426e95
4 changed files with 19 additions and 10 deletions

View File

@@ -76,7 +76,7 @@ bool opts_add_connect_send(char *arg) {
return false; return false;
} }
incoming_new(host, arg, send_new_wrapper, serializer); outgoing_new(host, arg, send_new_wrapper, serializer);
free(host); free(host);
return true; return true;
} }

View File

@@ -78,8 +78,7 @@ static void outgoing_disconnect_handler(struct peer *peer) {
assert(!close(outgoing->peer.fd)); assert(!close(outgoing->peer.fd));
} }
fprintf(stderr, "O %s: Peer disconnected; reconnecting...\n", outgoing->id); fprintf(stderr, "O %s: Peer disconnected; reconnecting...\n", outgoing->id);
outgoing_retry(outgoing);
outgoing_resolve(outgoing);
} }
static void outgoing_connect_result(struct outgoing *outgoing, int result) { static void outgoing_connect_result(struct outgoing *outgoing, int result) {

View File

@@ -1,7 +1,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/socket.h>
#include <unistd.h> #include <unistd.h>
#include "airspy_adsb.h" #include "airspy_adsb.h"
@@ -127,6 +129,9 @@ void receive_cleanup() {
} }
void receive_new(int fd, void *unused, struct peer *on_close) { void receive_new(int fd, void *unused, struct peer *on_close) {
int res = shutdown(fd, SHUT_WR);
assert(res == 0 || (res == -1 && errno == ENOTSOCK));
struct receive *receive = malloc(sizeof(*receive)); struct receive *receive = malloc(sizeof(*receive));
assert(receive); assert(receive);

View File

@@ -1,10 +1,12 @@
#include <stdbool.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <strings.h> #include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h> #include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/socket.h>
#include <unistd.h>
#include "airspy_adsb.h" #include "airspy_adsb.h"
#include "beast.h" #include "beast.h"
@@ -115,6 +117,9 @@ struct serializer *send_get_serializer(char *name) {
} }
void send_new(int fd, struct serializer *serializer, struct peer *on_close) { void send_new(int fd, struct serializer *serializer, struct peer *on_close) {
int res = shutdown(fd, SHUT_RD);
assert(res == 0 || (res == -1 && errno == ENOTSOCK));
struct send *send = malloc(sizeof(*send)); struct send *send = malloc(sizeof(*send));
assert(send); assert(send);