int main(int argc, char **argv) { if (argc != 4) { Misc::usage(argv); return -1; } else { QScopedPointer<QCoreApplication> app(createApplication(argc, argv)); if (qobject_cast<QApplication *>(app.data())) { QString locale = QLocale::system().name().section('_', 0, 0); QTranslator translator; translator.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); app->installTranslator(&translator); double prepareCook(Misc::stringToNumber(argv[1])); int numberCook(Misc::stringToNumber(argv[2])); int replaceStock(Misc::stringToNumber(argv[3])); Reception reception(prepareCook, numberCook, replaceStock); try { reception.init(); } catch (const Error &error) { std::cerr << error.where() << ": " << error.what() << std::endl; return -1; } MainWindow window(NULL, &reception); window.show(); return app->exec(); } else { return -1; } } }
int main (int argc, char *argv[]){ //traitement parametres entree int listenPort = 25; int listenfd,connfd,pid; socklen_t len; struct sockaddr_in servaddr,cliaddr; struct sigaction; //On ignore (SIG_IGN) le signal que chaque fils qui se termine envoie à son père (SIGCHLD) //Ainsi, les fils ne passent pas par l'Etat zombie signal(SIGCHLD,SIG_IGN); listenfd=socket(AF_INET,SOCK_STREAM,0);//Creation du socket if(listenfd < 0){ perror("Error While Opening The Sotcket"); exit(1); } bzero(&servaddr,sizeof(servaddr));//mise a zero de la structure servaddr.sin_family=AF_INET;//IPv4 servaddr.sin_addr.s_addr=htonl(INADDR_ANY);//connexion acceptée pour toute adresse(adresse de l'hote convertit en adresse reseau) servaddr.sin_port=htons(listenPort);//port sur lequel ecoute le serveur if(bind(listenfd,(struct sockaddr *)& servaddr,sizeof(servaddr))<0){//on relie le descripteur à la structure de socket perror("ERROR Binding of Isaac (or the socket maybe ?"); exit(7); } listen(listenfd,10);//convertit la socket en socket passive,attendant les connexions. 10=nombre maximal de clients mis en attente de connexion par le noyau len=sizeof(cliaddr); for(;;) { connfd=accept(listenfd,(struct sockaddr*)&cliaddr,&len); if(connfd < 0){ perror("ERROR Accepting the Connection (no more connection available ? "); exit(4); } printf("connexion : port %d\n",listenPort); pid=fork(); if(pid<0){ perror("Cannot create child process to treat the new connexion"); exit(6); } if(pid==0) { /* Inside client process */ close(listenfd); SmtpStatus Status = reception(connfd);//fonction chargée de travailler avec le client //Envoi du message au prochian relai envoi(&Status); close(connfd); } close(connfd); } return(0); }
void NetworkLink::makeSignalConnection() { connect(m_socketTcp, SIGNAL(readyRead()), this, SLOT(reception())); connect(m_socketTcp, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erreurDeConnexion(QAbstractSocket::SocketError))); connect(m_socketTcp, SIGNAL(disconnected()), this, SLOT(p_disconnect())); }
int main(int argc, char *argv[]) { int server_socket, client_socket; int sockaddr_size; struct sockaddr_in server_addr; unsigned short port; if(argc < 2) { puts("Argument missing, usage: <port>..."); exit(1); } port = atoi(argv[1]); signal(SIGCHLD, sigchldHandler); if((server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(1); } bzero(&server_addr, sizeof(struct sockaddr_in)); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); server_addr.sin_addr.s_addr = htonl(INADDR_ANY); if(bind(server_socket, (struct sockaddr *)&server_addr, sizeof(struct sockaddr_in)) < 0) { perror("bind"); exit(1); } if(listen(server_socket, SOMAXCONN) < 0) { perror("listen"); exit(1); } sockaddr_size = sizeof(struct sockaddr_in); while(1) { if((client_socket = accept(server_socket, 0, 0)) < 0) { perror("accept"); exit(1); } pid_t pid = fork(); if(pid == -1) { perror("fork"); exit(1); } else if(pid == 0) { int ret = reception(client_socket); close(client_socket); exit(ret); } } close(server_socket); return 0; }
int main(int const ac, char** const av) { try { Parser const parser(ac, av); Reception reception(parser); reception.start(); } catch (PlazzaError const &e) { std::cerr << std::string(av[0]) << ": " << e.what() << "." << std::endl; return (EXIT_FAILURE); } return (EXIT_SUCCESS); }
int main(int ac, char **av) { pthread_t ui_thread; try { Parser parser(ac, av); Reception reception(parser); pthread_create(&ui_thread, NULL, &main_ui, &reception); reception.start(); } catch (PlazzaError &e) { std::cerr << std::string(av[0]) << ": " << e.what() << "." << std::endl; return (EXIT_FAILURE); } return (EXIT_SUCCESS); }
int main() { struct sigaction action; /* autres variables (a completer) */ int semid,i; setbuf(stdout, NULL); /* Creation du segment de memoire partagee */ // A completer if ( (nb_recepteurs = init_shm(sizeof(t_segpart))) == NULL) { perror("init_shm"); exit(1); } nb_recepteurs->a = 0; /* creation des semaphores */ // A completer if ((semid = creer_sem(NR+2)) == -1) { perror("creer_sem"); exit(1); } /* initialisation des semaphores */ // A completer init_un_sem(EMET,1); init_un_sem(RECEPT1,0); init_un_sem(RECEPT2,0); init_un_sem(RECEPT3,0); init_un_sem(RECEPT4,0); init_un_sem(RECEPT5,0); init_un_sem(NBRECEPT,1); /* creation des processus emetteurs */ for (i=0; i < NE ;i++) { if ((emet_pid[i] = fork()) == -1) { perror("fork"); exit(0); } else if (emet_pid[i] == 0) { emettre(i); } } // A completer - les pid des processus crees doivent // etre stockes dans le tableau emet_pid /* creation des processus recepteurs */ // A completer - les pid des processus crees doivent // etre stockes dans le tableau recep_pid for (i=0; i < NR ;i++) { if ((recep_pid[i] = fork()) == -1) { perror("fork"); exit(0); } else if (recep_pid[i] == 0) { reception(i+1); } } /* redefinition du traitement de Ctrl-C pour arreter le programme */ sigemptyset(&action.sa_mask); action.sa_flags = 0; action.sa_handler = handle_sigint; sigaction(SIGINT, &action, 0); pause(); /* attente du Ctrl-C */ return EXIT_SUCCESS; }