static void handle_terminal_input(int fd, void * user) { int server_fd = *(int*)user; char buffer[128]; int nread; if((nread = read(fd,buffer,sizeof(buffer))) < 0) { perror("read"); exit(1); } message_write_string(server_fd,mt_broadcast,buffer); }
void MyWarningHandler(String errmsg) { message_t reply = message_new(next_serial++); message_add_packet(reply); fprintf(stderr,"Warning: %s\n",errmsg); fflush(stderr); message_put_dblword(reply,WARNING_REPLY); message_write_string(reply,errmsg,string_tag); message_send(client_socket,reply); message_free(reply); }
void MyErrorHandler(String errmsg) { message_t reply = message_new(next_serial++); message_add_packet(reply); fprintf(stderr,"Error: %s\n",errmsg); fflush(stderr); message_put_dblword(reply,ERROR_REPLY); message_write_string(reply,errmsg,string_tag); message_send(client_socket,reply); message_free(reply); longjmp(env,1); exit(-1); }
int main(int argc, char *argv[]) { int fd; do_getopt(argc,argv); fd = initialize_socket(); reactor_initialize(); reactor_add_listener(fd,handle_incoming_message,0); reactor_add_listener(STDIN_FILENO,handle_terminal_input,&fd); message_write_string(fd,mt_connect,config.name); reactor_run(); exit(0); }