From aba051523d5ac98d96e856f865983b496968d820 Mon Sep 17 00:00:00 2001 From: Joshua Date: Thu, 8 Jan 2015 01:49:56 -0600 Subject: [PATCH] Added SIGPIPE handler for sockets. --- sample/bot_runner.c | 1 + sample/exceptions.h | 6 ++++-- src/api.c | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sample/bot_runner.c b/sample/bot_runner.c index d128f40..a0e2a7a 100644 --- a/sample/bot_runner.c +++ b/sample/bot_runner.c @@ -22,6 +22,7 @@ int main(int argc, char *argv[], char **envp) int server_port = DEFAULT_SERVER_PORT;\ signal(SIGINT, internal_error); + signal(SIGPIPE, internal_error); if (argc == 3) { server_name = argv[1]; diff --git a/sample/exceptions.h b/sample/exceptions.h index e4f694d..3863389 100644 --- a/sample/exceptions.h +++ b/sample/exceptions.h @@ -16,16 +16,18 @@ static void internal_error(int signal) { case 0: printf("Program terminated by user.\n"); exit(EXIT_SUCCESS); + case 111: + printf("Could not connect. Check that the server is up?\n" + "Expected arguments: ./mcc [ []]\n"); + exit(EXIT_FAILURE); case 1000: printf("Invalid arguments.\n" "Expected arguments: ./mcc [ []]\n"); exit(EXIT_FAILURE); - break; case 1001: printf("Invalid port.\n" "Expected arguments: ./mcc [ []]\n"); exit(EXIT_FAILURE); - break; case 3000: printf("Got a non-positive packet\n"); exit(EXIT_FAILURE); diff --git a/src/api.c b/src/api.c index 3b99d2a..5c43332 100644 --- a/src/api.c +++ b/src/api.c @@ -54,8 +54,8 @@ bool next_int_token(int* value, char *string, char **saveptr) void execute_command(bot_t *bot, char *command, char *strargs) { if (strcmp(command, "help") == 0) { - send_play_serverbound_chat(bot, "Available commands:"); - send_play_serverbound_chat(bot, "slot, "); + send_play_serverbound_chat(bot, "Available chat commands:"); + send_play_serverbound_chat(bot, "[slot]"); } else if (strcmp(command, "slot") == 0) { char **saveptr = calloc(1, sizeof(char *)); bool valid_input = true;