Commit f4af71f1 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Fix tcp_connect code to not use connect() twice.

Add a little bit of logging.
parent da65aa74
......@@ -72,5 +72,12 @@ int main(int argc, char **argv)
command_handle(command, &fdrx);
}
if (command_state_get(command) == COMMAND_STATE_DISCONNECTED) {
printf("Not connected.\n");
printf("Usage: %s <host> <port>\n", argv[0]);
printf("Typical ports: %d, %d\n",
CONSOLE_COMMAND_PORT, CTRL_COMMAND_PORT);
}
return 0;
}
......@@ -409,6 +409,12 @@ static void *log_client(void *arg)
return NULL;
}
void log_level_set(enum log_type console_level, enum log_type remote_level)
{
log_level_console = console_level;
log_level_remote = remote_level;
}
int log_client_start(char *host, int port, enum log_type console_level,
enum log_type remote_level, char *name)
{
......
......@@ -37,6 +37,8 @@ void log_server_flush(void);
void log_flush_stdout(void);
void log_level_set(enum log_type console_level, enum log_type remote_level);
int log_client_start(char *host, int port, enum log_type console_level,
enum log_type remote_level, char *name);
......
/*
Trace support
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2011
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2011, 2015
Copyright Stichting C.A. Muller Radioastronomiestation, 2011
This program is free software: you can redistribute it and/or modify
......
/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2013
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2007, 2013, 2015
Copyright Stichting C.A. Muller Radioastronomiestation, 2007
This program is free software: you can redistribute it and/or modify
......@@ -26,6 +26,7 @@
#include <netinet/in.h>
#include <trace/trace.h>
#include <log/log.h>
#include <dt_port_numbers.h>
static char *host = "localhost";
......@@ -50,6 +51,8 @@ int main(int argc, char **argv)
{
struct trace *trace;
log_level_set(LOG_T_DEBUG, LOG_T_DEBUG);
if (argc > 1) {
host = argv[1];
}
......@@ -62,6 +65,8 @@ int main(int argc, char **argv)
trace->handler_interval = handler_interval;
trace->handler_list_entry = handler_list_entry;
log_flush_stdout();
while (trace_state_get(trace) == TRACE_STATE_CONNECTED) {
fd_set fdrx;
int high = 0;
......@@ -75,6 +80,9 @@ int main(int argc, char **argv)
trace_handle(trace, &fdrx);
}
log_flush_stdout();
if (trace_state_get(trace) == TRACE_STATE_DISCONNECTED) {
printf("Not connected.\n");
printf("Usage: %s <host> <port>\n", argv[0]);
......
/*
trace tcp connection handling
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2013
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2013, 2015
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
/*
tcp_connect.c
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007, 2008, 2011
Copyright Jeroen Vreeken (jeroen@vreeken.net), 2007, 2008, 2011, 2015
Copyright Stichting C.A. Muller Radioastronomiestation, 2007, 2008, 2011
This program is free software: you can redistribute it and/or modify
......@@ -71,25 +71,26 @@ int tcp_connect(char *host, int port)
fd_set fdset_tx, fdset_err;
struct timeval tv;
tv.tv_sec = tcp_connect_timeout;
tv.tv_usec = 0;
if (connect(sock, entry->ai_addr, entry->ai_addrlen)) {
int ret;
do {
errno = 0;
FD_ZERO(&fdset_tx);
FD_ZERO(&fdset_err);
FD_SET(sock, &fdset_tx);
FD_SET(sock, &fdset_err);
tv.tv_sec = tcp_connect_timeout;
tv.tv_usec = 0;
if (connect(sock, entry->ai_addr, entry->ai_addrlen)) {
while (
select(sock+1, NULL, &fdset_tx, &fdset_err, &tv)<0
ret = select(sock+1, NULL, &fdset_tx, NULL,
&tv);
} while (
ret < 0
&&
(errno == EAGAIN || errno == EINTR));
if (connect(sock, entry->ai_addr, entry->ai_addrlen)) {
close(sock);
sock = -1;
}
(errno == EAGAIN || errno == EINTR ||
errno == EINPROGRESS));
}
if (sock >= 0) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment