static void end_test(grpc_end2end_test_fixture *f) { shutdown_server(f); shutdown_client(f); grpc_completion_queue_shutdown(f->cq); drain_cq(f->cq); grpc_completion_queue_destroy(f->cq); }
static void end_test(grpc_end2end_test_fixture *f) { shutdown_server(f); shutdown_client(f); grpc_completion_queue_shutdown(f->cq); drain_cq(f->cq); grpc_completion_queue_destroy(f->cq); /* Note: shutdown_cq is not used in this test */ grpc_completion_queue_destroy(f->shutdown_cq); }
static void console_shutdown(connection_type* ct, char *when) { int min = 0; //if (!my_stricmp(when, "NOW")) min = 0; //else if (IS_VALID_NUMBER(when)) min = when /* Now */ if (min == 0) { /* Tell */ cq_printf(&ct->wbuf, "%T", "Server shutdown\n"); /* Shutdown */ shutdown_server(); } else /* Delayed */ { /* Set timer (in seconds) */ shutdown_timer= min * 60; } }
int main(int argc, char** argv) { int port = atoi(argv[1]); Server* server = create_server(port); listen_port(server); Connection* con = accept_connection(server); char client_addr[50]; get_connection_address(con, client_addr); printf("CLIENT %s CONNECTED\n", client_addr); receive_greet(con); send_greet_ack(con); //Receive folder anem char buffer[MAX_MSG]; receive_msg(con, buffer); send_ack(con); char filename[100]; strcpy(filename, client_addr); strcat(filename, buffer); int i; for(i = 0; filename[i] != '\0'; i++){ filename[i] = filename[i] == '/'? '.': filename[i]; } char* filebuffer = calloc(sizeof(char), MAX_MSG); int filebuffer_size = MAX_MSG; filebuffer[0] = '\0'; int usedbuffer = 0; //receive filenames while(receive_msg(con, buffer)){ usedbuffer += strlen(buffer)+1; if(usedbuffer > filebuffer_size){ filebuffer_size *= 2; filebuffer = (char*) realloc(filebuffer, sizeof(char)*filebuffer_size*2); } printf("%s\n", buffer); sprintf(filebuffer, "%s%s\n", filebuffer, buffer); send_ack(con); } shutdown_server(server); close_connection(con); FILE* f = fopen(filename, "w"); fprintf(f, "%s", filebuffer); fclose(f); free(filebuffer); return 0; }
/** * Point d'entrée du programme. */ int main(int argc, char *argv[]) { parse_command_line(argc, argv); /* On crée un socket pour se connecter sur un serveur */ if ((server_socket = socket(PF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); return EXIT_FAILURE; } /* Initialisation du bind */ memset(&server_address, 0, sizeof server_address); server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = htonl(INADDR_ANY); server_address.sin_port = htons(port); /* Ze bind */ if (bind(server_socket, (struct sockaddr *) &server_address, sizeof(server_address)) == -1) { perror("bind"); if (close(server_socket) == -1) perror("Impossible de fermer le socket serveur"); return EXIT_FAILURE; } /* On le définit comme écouteur */ if (listen(server_socket, MAX_CLIENT) == -1) { perror("Impossible de mettre le socket serveur en écoute"); if (close(server_socket) == -1) perror("Impossible de fermer le socket serveur"); return EXIT_FAILURE; } verbose("Démarrage du démon sur le port %d ...\n", port); /* Pour quitter le serveur proprement */ signal(SIGINT, trap_ctrlc); for (;;) { /* Variable concrète car il faut pouvoir en avoir l'adresse pour accept() */ socklen_t client_address_size = sizeof client_address; /* On attend une connection */ if ((client_socket = accept(server_socket, (struct sockaddr *) &client_address, &client_address_size)) == -1) { perror("accept"); if (close(server_socket) == -1) perror("Impossible de fermer le socket serveur"); return EXIT_FAILURE; } /* On traite ce client */ process_client(); } shutdown_server(); /* N'arrivera jamais */ return EXIT_FAILURE; }
/** * Fonction de callback appelée lors d'un ctrl+c. */ static void trap_ctrlc(int sig) { sig = sig; /* Evite un warning */ shutdown_server(); }
/** * MaxScale shutdown * @param dcb Client DCB * @param tree Parse tree */ void exec_shutdown_maxscale(DCB *dcb, MAXINFO_TREE *tree) { shutdown_server(); maxinfo_send_ok(dcb); }
int main() { /* using NAME_MAX prevents EINVAL on read() (twice for UTF-16 on NTFS) */ char buf[sizeof(struct inotify_event) + NAME_MAX*2 + 1]; char *crtpath, *qpath, *rqpath, *looppath, *lsthost, *lstport; int sz, offset, rereg, evqok, retryid; struct inotify_event *iev; double retrytmout, lastclock; /* init logging */ syslog_init(); /* extract environment */ crtpath = alloc_env(CABLE_CERTS, "/" CERTS_NAME); qpath = alloc_env(CABLE_QUEUES, "/" QUEUE_NAME); rqpath = alloc_env(CABLE_QUEUES, "/" RQUEUE_NAME); looppath = alloc_env(CABLE_HOME, "/" LOOP_NAME); lsthost = alloc_env(CABLE_HOST, ""); lstport = alloc_env(CABLE_PORT, ""); /* initialize rng */ if (!rand_init()) warning("failed to initialize RNG"); /* initialize process accounting */ if (!init_process_acc()) warning("failed to initialize process accounting"); /* initialize webserver */ if (!init_server(crtpath, qpath, rqpath, lsthost, lstport)) { flog(LOG_ERR, "failed to initialize webserver"); return EXIT_FAILURE; } /* try to reregister watches as long as no signal caught */ for (lastclock = getmontime(), retryid = 0; !stop_requested(); ) { /* support empty CABLE_NOLOOP when testing, to act as pure server */ #ifdef TESTING if (getenv("CABLE_NOLOOP")) { sleepsec(RETRY_TMOUT); continue; } #endif wait_reg_watches(qpath, rqpath); /* read events as long as no signal caught and no unmount / move_self / etc. events read */ for (rereg = evqok = 0; !stop_requested() && !rereg; ) { /* wait for an event, or timeout (later blocking read() results in error) */ retrytmout = RETRY_TMOUT + RETRY_TMOUT * (rand_shift() / 2); if (wait_read(inotfd, retrytmout - (getmontime() - lastclock))) { /* read events (non-blocking), taking care to handle interrupts due to signals */ if ((sz = read(inotfd, buf, sizeof(buf))) == -1 && errno != EINTR) { /* happens buffer is too small (e.g., NTFS + 255 unicode chars) */ warning("error while reading from inotify queue"); rereg = 1; } /* process all events in buffer, sz = -1 and 0 are automatically ignored */ for (offset = 0; offset < sz && !stop_requested() && !rereg; evqok = 1) { /* get handler to next event in read buffer, and update offset */ iev = (struct inotify_event*) (buf + offset); offset += sizeof(struct inotify_event) + iev->len; /* IN_IGNORED is triggered by watched directory removal / fs unmount IN_MOVE_SELF is only triggered by move of actual watched directory (i.e., not its parent) */ if ((iev->mask & (IN_IGNORED | IN_UNMOUNT | IN_Q_OVERFLOW | IN_MOVE_SELF))) rereg = 1; /* ignore non-subdirectory events, and events with incorrect name */ else if (iev->len > 0 && (iev->mask & IN_ISDIR) && is_msgdir(iev->name)) { assert(iev->wd == inotqwd || iev->wd == inotrqwd); if (iev->wd == inotqwd || iev->wd == inotrqwd) { /* stop can be indicated here (while waiting for less processes) */ const char *qtype = (iev->wd == inotqwd) ? QUEUE_NAME : RQUEUE_NAME; run_loop(qtype, iev->name, looppath); } else flog(LOG_WARNING, "unknown watch descriptor"); } } } /* if sufficient time passed since last retries, retry again */ if (!stop_requested() && getmontime() - lastclock >= retrytmout) { /* alternate between queue dirs to prevent lock starvation on self-send */ if ((retryid ^= 1)) retry_dir(QUEUE_NAME, qpath, looppath); else retry_dir(RQUEUE_NAME, rqpath, looppath); lastclock = getmontime(); /* inotify is apparently unreliable on fuse, so reregister when no events */ if (!evqok) rereg = 1; evqok = 0; } } } unreg_watches(); if (!shutdown_server()) flog(LOG_WARNING, "failed to shutdown webserver"); dealloc_env(lstport); dealloc_env(lsthost); dealloc_env(looppath); dealloc_env(rqpath); dealloc_env(qpath); dealloc_env(crtpath); flog(LOG_INFO, "exiting"); closelog(); return EXIT_SUCCESS; }
void iuctl_server_shutdown() { destroy_iuctl(); shutdown_server(); exit(0); }