Add an option to expect all client drawing to succeed

Alias `no-wait'.  So far the server always draws everything.  If that stops
being the case, we might want to introduce a denial response and additional
logic in the client, so that it can fix its own version of the picture.
This commit is contained in:
Přemysl Eric Janouch 2015-02-08 02:33:02 +01:00
parent 30e61e2728
commit 8fc107a31b
1 changed files with 14 additions and 3 deletions

View File

@ -112,6 +112,8 @@ struct app_context
struct msg_reader msg_reader; ///< Server message reader struct msg_reader msg_reader; ///< Server message reader
write_queue_t write_queue; ///< Server write queue write_queue_t write_queue; ///< Server write queue
bool no_wait; ///< Don't wait for server confirmations
// Server: // Server:
int listen_fd; ///< Listening FD int listen_fd; ///< Listening FD
ev_io listen_watcher; ///< Listening FD watcher ev_io listen_watcher; ///< Listening FD watcher
@ -514,11 +516,13 @@ draw_point_internal (app_context_t *app, int x, int y, uint8_t color)
static void static void
draw_point (app_context_t *app, int x, int y, uint8_t color) draw_point (app_context_t *app, int x, int y, uint8_t color)
{ {
// We don't actually draw anything immediately in client mode,
// instead we wait for confirmation from the server
if (app->mode == NETWORK_MODE_CLIENT) if (app->mode == NETWORK_MODE_CLIENT)
{ {
send_draw_point_request (app, x, y, color); send_draw_point_request (app, x, y, color);
// We don't usually draw anything immediately in client mode,
// instead we wait for confirmation from the server
if (!app->no_wait)
return; return;
} }
@ -1372,6 +1376,7 @@ struct app_options
{ {
struct addrinfo *client_address; ///< Address to connect to struct addrinfo *client_address; ///< Address to connect to
struct addrinfo *server_address; ///< Address to listen at struct addrinfo *server_address; ///< Address to listen at
bool no_wait; ///< Don't wait for server confirmations
}; };
static void static void
@ -1439,6 +1444,8 @@ parse_program_arguments (app_options_t *options, int argc, char **argv)
{ 'V', "version", NULL, 0, "output version information and exit" }, { 'V', "version", NULL, 0, "output version information and exit" },
{ 's', "server", "[ADDRESS]:PORT", 0, "start a server" }, { 's', "server", "[ADDRESS]:PORT", 0, "start a server" },
{ 'c', "client", "[ADDRESS]:PORT", 0, "connect to a server" }, { 'c', "client", "[ADDRESS]:PORT", 0, "connect to a server" },
{ 'n', "no-wait", NULL, OPT_LONG_ONLY,
"don't wait for server confirmations" },
{ 0, NULL, NULL, 0, NULL } { 0, NULL, NULL, 0, NULL }
}; };
@ -1476,6 +1483,9 @@ parse_program_arguments (app_options_t *options, int argc, char **argv)
if (!(options->client_address = parse_address (optarg, 0))) if (!(options->client_address = parse_address (optarg, 0)))
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
break; break;
case 'n':
options->no_wait = true;
break;
default: default:
fprintf (stderr, "%s: %s\n", "error", "wrong options"); fprintf (stderr, "%s: %s\n", "error", "wrong options");
opt_handler_usage (&oh, stderr); opt_handler_usage (&oh, stderr);
@ -1617,6 +1627,7 @@ main (int argc, char *argv[])
else else
app.mode = NETWORK_MODE_STANDALONE; app.mode = NETWORK_MODE_STANDALONE;
app.no_wait = options.no_wait;
app_options_free (&options); app_options_free (&options);
termo_t *tk = termo_new (STDIN_FILENO, NULL, 0); termo_t *tk = termo_new (STDIN_FILENO, NULL, 0);