int main(int argc, char *argv[]) { char file_name[] = "web_server_trace.log"; int new_sock_conn; int port_no; int status; struct sockaddr cli_addr; int cli_len; signal(SIGINT, int_handler); ignore_sigpipe(); debg_ofp = fopen(file_name, "w"); if (argc < 2) { fprintf(debg_ofp, "No port no entered hence exiting\n"); fprintf(stderr, "Very Few Arguments enter port no\n"); fflush(debg_ofp); cleanup(-1, debg_ofp); exit(1); } port_no = atoi(argv[1]); status = bootstrap_server(&web_serv_sock_fd, port_no, debg_ofp); if (status != 0){ fprintf(debg_ofp, "ERROR in binding server port\n"); fprintf(stderr, "ERROR bootstrapping server see log files for details\n"); fflush(debg_ofp); cleanup(web_serv_sock_fd, debg_ofp); exit(status); } while(keep_running) { listen(web_serv_sock_fd, CONN_QUEUE); fprintf(debg_ofp, "\nNew TCP Connection\n"); cli_len = sizeof(cli_addr); new_sock_conn = accept(web_serv_sock_fd, (struct sockaddr *) &cli_addr, (socklen_t *) &cli_len); fprintf(debg_ofp, "DEBUG: Connection accepted : %d\n", new_sock_conn); if (new_sock_conn < 0) { fprintf(debg_ofp, "ERROR: in accepting connection\n"); fflush(debg_ofp); cleanup(web_serv_sock_fd, debg_ofp); return 1; } status = handle_connection(new_sock_conn, cli_addr, cli_len, debg_ofp); if (status != 0){ fprintf(debg_ofp, "ERROR in accepting connection\n"); fprintf(stderr, "ERROR in accepting connection see log files for details\n"); fflush(debg_ofp); continue; } } cleanup(web_serv_sock_fd, debg_ofp); }
int main(int argc,char *argv[]) { int error= 0; char tp_path[FN_REFLEN]; char server_path[FN_REFLEN]; char operation[16]; MY_INIT(argv[0]); plugin_data.name= 0; // initialize name /* The following operations comprise the method for enabling or disabling a plugin. We begin by processing the command options then check the directories specified for --datadir, --basedir, --plugin-dir, and --plugin-ini (if specified). If the directories are Ok, we then look for the mysqld executable and the plugin soname. Finally, we build a bootstrap command file for use in bootstraping the server. If any step fails, the method issues an error message and the tool exits. 1) Parse, execute, and verify command options. 2) Check access to directories. 3) Look for mysqld executable. 4) Look for the plugin. 5) Build a bootstrap file with commands to enable or disable plugin. */ if ((error= process_options(argc, argv, operation)) || (error= check_access()) || (error= find_tool("mysqld" FN_EXEEXT, server_path)) || (error= find_plugin(tp_path)) || (error= build_bootstrap_file(operation, bootstrap))) goto exit; /* Dump the bootstrap file if --verbose specified. */ if (opt_verbose && ((error= dump_bootstrap_file(bootstrap)))) goto exit; /* Start the server in bootstrap mode and execute bootstrap commands */ error= bootstrap_server(server_path, bootstrap); exit: /* Remove file */ my_delete(bootstrap, MYF(0)); if (opt_verbose && error == 0) { printf("# Operation succeeded.\n"); } my_end(my_end_arg); exit(error ? 1 : 0); return 0; /* No compiler warnings */ }
int main(int argc, char *argv[]) { char file_name[] = "web_server_trace.log"; int new_sock_conn; int port_no; int status; struct sockaddr cli_addr; int cli_len; pthread_t pthread_arr[MAX_THREADS]; int i = 0, j = 0; hdl_conn_args_t thrd_args[MAX_THREADS]; void *thrd_retval; signal(SIGINT, int_handler); ignore_sigpipe(); debg_ofp = fopen(file_name, "w"); if (argc < 2) { fprintf(debg_ofp, "No port no entered hence exiting\n"); fprintf(stderr, "Very Few Arguments enter port no\n"); fflush(debg_ofp); cleanup(-1, debg_ofp); exit(1); } port_no = atoi(argv[1]); status = bootstrap_server(&web_serv_sock_fd, port_no, debg_ofp); if (status != 0){ fprintf(debg_ofp, "ERROR in binding server port\n"); fprintf(stderr, "ERROR bootstrapping server see log files for details\n"); fflush(debg_ofp); cleanup(web_serv_sock_fd, debg_ofp); exit(status); } i = 0; while(i<MAX_THREADS) { listen(web_serv_sock_fd, CONN_QUEUE); fprintf(debg_ofp, "\nNew TCP Connection\n"); cli_len = sizeof(cli_addr); new_sock_conn = accept(web_serv_sock_fd, (struct sockaddr *) &cli_addr, (socklen_t *) &cli_len); fprintf(debg_ofp, "DEBUG: Connection accepted : %d\n", new_sock_conn); if (new_sock_conn < 0) { fprintf(debg_ofp, "ERROR: in accepting connection\n"); fflush(debg_ofp); cleanup(web_serv_sock_fd, debg_ofp); return 1; } thrd_args[i].new_sock_conn = new_sock_conn; thrd_args[i].cli_addr = cli_addr; thrd_args[i].cli_len = cli_len; thrd_args[i].debg_ofp = debg_ofp; thrd_args[i].status = 0; status = pthread_create(&pthread_arr[i], NULL, handle_connection, &thrd_args); pthread_detach(pthread_arr[i]); i++; } cleanup(web_serv_sock_fd, debg_ofp); }
int main(int argc, char *argv[]) { char file_name[] = "udp_server_trace.log"; int num_bytes; int port_no; int status; struct sockaddr_in cli_addr; int cli_len; char buf[MAX_BUFFER]; signal(SIGINT, int_handler); ignore_sigpipe(); debg_ofp = fopen(file_name, "w"); if (argc < 2) { fprintf(debg_ofp, "No port no entered hence exiting\n"); fprintf(stderr, "Very Few Arguments enter port no\n"); fflush(debg_ofp); cleanup(-1, debg_ofp); exit(1); } port_no = atoi(argv[1]); status = bootstrap_server(&udp_serv_sock_fd, port_no, debg_ofp); if (status != 0){ fprintf(debg_ofp, "ERROR in binding server port\n"); fprintf(stderr, "ERROR bootstrapping server see log files for details\n"); fflush(debg_ofp); cleanup(udp_serv_sock_fd, debg_ofp); exit(status); } while(keep_running) { cli_len = sizeof(cli_addr); num_bytes = recvfrom(udp_serv_sock_fd, buf, MAX_BUFFER, 0, (struct sockaddr *) &cli_addr, (socklen_t *) &cli_len); if (num_bytes == 0) { fprintf(debg_ofp, "UDP client connection closed at client side\n"); continue; } if (num_bytes < 0) { fprintf(debg_ofp, "ERROR: in UDP connection\n"); fflush(debg_ofp); cleanup(udp_serv_sock_fd, debg_ofp); return 1; } fprintf(debg_ofp, "Recieved Message :\n %s", buf); status = handle_connection(udp_serv_sock_fd, buf, cli_addr, cli_len, debg_ofp); if (status != 0){ fprintf(debg_ofp, "ERROR in replying back %d\n", status); fprintf(stderr, "ERROR in UDP reply see log files for details %d\n", status); fflush(debg_ofp); continue; } } cleanup(udp_serv_sock_fd, debg_ofp); }