Skip to content

Commit

Permalink
Added SIGPIPE handler for sockets.
Browse files Browse the repository at this point in the history
  • Loading branch information
JDongian committed Jan 8, 2015
1 parent ecf262f commit aee86f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions sample/bot_runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 4 additions & 2 deletions sample/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<SERVER> [<PORT>]]\n");
exit(EXIT_FAILURE);
case 1000:
printf("Invalid arguments.\n"
"Expected arguments: ./mcc [<SERVER> [<PORT>]]\n");
exit(EXIT_FAILURE);
break;
case 1001:
printf("Invalid port.\n"
"Expected arguments: ./mcc [<SERVER> [<PORT>]]\n");
exit(EXIT_FAILURE);
break;
case 3000:
printf("Got a non-positive packet\n");
exit(EXIT_FAILURE);
Expand Down
4 changes: 2 additions & 2 deletions src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aee86f6

Please sign in to comment.