-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standby support #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,14 @@ int main(int argc, char **argv) { | |
sigact.sa_flags = 0; | ||
sigaction(SIGTERM, &sigact, NULL); | ||
sigaction(SIGINT, &sigact, NULL); | ||
restart: | ||
pthread_create(&threadServer, NULL, serverThread, NULL); | ||
|
||
pthread_join(threadServer, NULL); | ||
|
||
if (timeToExit == 2) { | ||
slog(LOG_INFO, SLOG_INFO, "Restarting."); | ||
timeToExit = 0; | ||
goto restart; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it could be better handled in just a normal loop, like:
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,8 @@ option "port" p "rtl_tcp port" | |
option "host" h "rtl_tcp host address" | ||
string typestr="address" default="localhost" optional | ||
option "listen" l "Listening port for client connections" | ||
int typestr="port" default="7878" optional | ||
int typestr="port" default="7878" optional option "delayed" d "Delayed | ||
connection to the server" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line wrapping (and the next one) causes some issues in formatting for the --help and comments in the cmdline handler. |
||
flag off option "restart" r "Restart server's connection when last | ||
client disconnects" | ||
flag off |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,9 +215,10 @@ static void serverReadCB(struct bufferevent *bev, void *ctx) { | |
slog(LOG_INFO, SLOG_INFO, "Connected to server."); | ||
} else { // Failed to receive the magic header | ||
slog(LOG_ERROR, SLOG_ERROR, "Failed to receive magic header from server."); | ||
bufferevent_free(bev); | ||
connectToServerSoon(ctx); | ||
return; | ||
//bufferevent_free(bev); | ||
//connectToServerSoon(ctx); | ||
//return; | ||
serverInfo.state = SERVER_CONNECTED; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really see why this is being set to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More or less... yes! |
||
} | ||
// Send stored and set parameters on reconnect | ||
int i; | ||
|
@@ -251,6 +252,10 @@ static void serverReadCB(struct bufferevent *bev, void *ctx) { | |
if(sendDataToAllClients(data) == 0) { | ||
// No one was listening | ||
free(data); | ||
if (config.delayed) { | ||
slog(LOG_INFO, SLOG_INFO, "Last user disconnected."); | ||
if (config.restart) timeToExit = 2; else timeToExit = 1; | ||
} | ||
} else { | ||
dataBlocks++; | ||
dataBlocksSize += data->len; | ||
|
@@ -388,6 +393,11 @@ static void connectCB(struct evconnlistener *listener, | |
base, sock, BEV_OPT_CLOSE_ON_FREE); | ||
#endif | ||
|
||
if (config.delayed && (serverConnection == NULL || LIST_FIRST(&clients) == NULL)) { | ||
slog(LOG_INFO, SLOG_INFO, "Connection to server triggered."); | ||
connectToServer(&serverConnection); | ||
} | ||
|
||
struct client *client = addClient(bev, ptr); | ||
memcpy(&client->sa, addr, len); | ||
char ipBuf[128]; | ||
|
@@ -397,7 +407,7 @@ static void connectCB(struct evconnlistener *listener, | |
evutil_inet_ntop(client->sa.sa_family, &client->sin6.sin6_addr, ipBuf, 128); | ||
else | ||
snprintf(ipBuf, 128, "from unknown address"); | ||
slog(LOG_INFO, SLOG_INFO, "Connection from client %s", ipBuf); | ||
slog(LOG_INFO, SLOG_INFO, "Connection from client %s%s", ipBuf, LIST_NEXT(client,peer) == NULL ? " (first!)" : ""); | ||
bufferevent_setcb(bev, clientReadCB, NULL, errorEventCB, client); | ||
bufferevent_setwatermark(bev, EV_WRITE, 0, 4*1024*1024); // Limit output to 4MB? | ||
bufferevent_enable(bev, EV_READ|EV_WRITE); | ||
|
@@ -483,8 +493,12 @@ void *serverThread(void *arg) { | |
} | ||
|
||
slog(LOG_INFO, SLOG_INFO, "Listening for clients on port %d", config.clientPort); | ||
|
||
connectToServer(&serverConnection); | ||
|
||
if (!config.delayed) { | ||
connectToServer(&serverConnection); | ||
} else { | ||
slog(LOG_INFO, SLOG_INFO, "connection to server delayed."); | ||
} | ||
|
||
struct evhttp *http; | ||
struct evhttp_bound_socket *handle; | ||
|
@@ -539,6 +553,12 @@ void *serverThread(void *arg) { | |
evhttp_free(http); | ||
|
||
event_base_free(event_base); | ||
|
||
if (serverConnection != NULL) { | ||
bufferevent_free(serverConnection); | ||
serverInfo.state = SERVER_DISCONNECTED; | ||
slog(LOG_INFO, SLOG_INFO, "Disconnecting from server."); | ||
} | ||
|
||
slog(LOG_INFO, SLOG_INFO, "End of server thread."); | ||
return NULL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a spelling mistake on 'order', which should be 'other'.