/** * Start the interface and main client loop */ int interface(struct config* config){ CONFIG = config; init_interface(); fd_set master; fd_set readset; FD_ZERO(&readset); FD_ZERO(&master); FD_SET(config->self.socket, &master); FD_SET(STDIN, &master); int max_sock = config->self.socket; struct timeval tv; while(EXIT == 0){ readset = master; tv.tv_sec = 0; tv.tv_usec = 100; select(max_sock+1, &readset, NULL, NULL, &tv); if(tv.tv_sec == 0 && tv.tv_usec == 0){ if(handle_user() != 0){ perror("BAD THINGS HAPPENED!"); EXIT = 1; } continue; } for(int i = 0; i < max_sock+1; ++i){ if (FD_ISSET(i, &readset)){ if(i == config->self.socket){ if(handle_server(config->self.socket) < 0){ close_interface(); perror("Connection closed to server"); return -1; } }else if(i == STDIN){ handle_user(); } } } refresh(); } return 0; }
int main(int ac, char **av) { int ret; t_cli *cli; if (ac == 3) { if (init(&cli, av[1], av[2]) == -1) return (-1); ret = connect(cli->sock, (SOCKADDR *)&cli->sin, sizeof(cli->sin)); if (ret == -1) return (-1); puts("connecte au server"); while (1) { if (handle_signal() == -1) return (-1); if (cli->logged == 1 && cli->passed == 1) { if (handle_cmd(cli) == -1) return (-1); } else if (handle_user(cli) == -1) return (-1); } } }
int main(int argc, char ** argv) { catalyzer_config * config = handle_user(argc, argv); catalyzer_io input, output; input.cio_fd = 0; input.cio_duplication = 2; output.cio_fd = 1; output.cio_duplication = input.cio_duplication * config->downsample; input.cio_buf_head = malloc(sizeof(int) * config->num_samples * input.cio_duplication); output.cio_buf_head = malloc(sizeof(int) * config->num_samples * input.cio_duplication); main_loop(&input, &output, config->downsample, config->num_samples, 0); return 0; }
static apr_status_t ftp_protocol_loop(struct lfd_sess * sess) { apr_status_t rc = APR_SUCCESS; int rnfrto; // "rename from" and "rename to" should go togheter char * temp_name; temp_name = NULL; rnfrto = 0; while(APR_SUCCESS == rc) { apr_pool_clear(sess->loop_pool); rc = lfd_cmdio_get_cmd_and_arg(sess, &sess->ftp_cmd_str, &sess->ftp_arg_str); if(APR_SUCCESS != rc) return rc; // special case if(lfd_cmdio_cmd_equals(sess, "RNTO")) { if(rnfrto) { rnfrto = 0; rc = handle_rnto(sess, temp_name); } else rc = handle_bad_rnto(sess); continue; } // here we treat all the other cases if(rnfrto){ rnfrto = 0; rc = handle_bad_rnto(sess); continue; } if(lfd_cmdio_cmd_equals(sess, "PASV")) { rc = handle_pasv(sess); } else if(lfd_cmdio_cmd_equals(sess, "SYST")) { rc = handle_syst(sess); } else if(lfd_cmdio_cmd_equals(sess, "USER")) { rc = handle_user(sess); } else if(lfd_cmdio_cmd_equals(sess, "PASS")) { rc = handle_pass(sess); } else if(lfd_cmdio_cmd_equals(sess, "QUIT")) { rc = handle_quit(sess); return rc; } else if(lfd_cmdio_cmd_equals(sess, "ABOR")) { rc = handle_abort(sess); } else if(lfd_cmdio_cmd_equals(sess, "PORT")) { rc = handle_port(sess); } else if(lfd_cmdio_cmd_equals(sess, "RMD")) { rc = handle_dir_remove(sess); } else if(lfd_cmdio_cmd_equals(sess, "MKD")) { rc = handle_dir_create(sess); } else if(lfd_cmdio_cmd_equals(sess, "PWD")) { rc = handle_pwd(sess); } else if(lfd_cmdio_cmd_equals(sess, "CWD")) { rc = handle_cwd(sess); } else if(lfd_cmdio_cmd_equals(sess, "CDUP")) { rc = handle_cdup(sess); } else if(lfd_cmdio_cmd_equals(sess, "RNFR")) { rc = handle_rnfr(sess, &temp_name); if(APR_SUCCESS == rc && NULL != temp_name) rnfrto = 1; } else if(lfd_cmdio_cmd_equals(sess, "TYPE")) { rc = handle_type(sess); } else if(lfd_cmdio_cmd_equals(sess, "RETR")) { rc = handle_retr(sess); } else if(lfd_cmdio_cmd_equals(sess, "STOR")) { rc = handle_stor(sess); } else if(lfd_cmdio_cmd_equals(sess, "DELE")) { rc = handle_dele(sess); } else if(lfd_cmdio_cmd_equals(sess, "STOU")) { rc = handle_stou(sess); } else if(lfd_cmdio_cmd_equals(sess, "LIST")) { rc = handle_list(sess); } else if(lfd_cmdio_cmd_equals(sess, "FEAT")) { rc = handle_feat(sess); } else if(lfd_cmdio_cmd_equals(sess, "APPE")) { rc = handle_appe(sess); } else if(lfd_cmdio_cmd_equals(sess, "SITE")) { rc = handle_site(sess); } else if(lfd_cmdio_cmd_equals(sess, "ALLO")) { rc = lfd_cmdio_write(sess, FTP_ALLOOK, "ALLO command ignored."); } else if(lfd_cmdio_cmd_equals(sess, "REIN")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "REIN not implemented."); } else if(lfd_cmdio_cmd_equals(sess, "ACCT")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "ACCT not implemented."); } else if(lfd_cmdio_cmd_equals(sess, "SMNT")) { rc = lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "SMNT not implemented."); } else //default { printf("The cmd [%s] has no installed handler! \n", sess->ftp_cmd_str); if(NULL != sess->ftp_arg_str) printf("The cmd args were [%s] \n", sess->ftp_arg_str); lfd_cmdio_write(sess, FTP_COMMANDNOTIMPL, "Command not implemented."); } } return rc; }