⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkpointserver.c

📁 Path MPICH-V for MPICH the MPI Implementation
💻 C
字号:
/*  MPICH-V2  Copyright (C) 2002, 2003 Groupe Cluster et Grid, LRI, Universite de Paris Sud  This file is part of MPICH-V2.  MPICH-V2 is free software; you can redistribute it and/or modify  it under the terms of the GNU General Public License as published by  the Free Software Foundation; either version 2 of the License, or  (at your option) any later version.  MPICH-V2 is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with MPICH-V2; if not, write to the Free Software  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  $Id: checkpointServer.c,v 1.6 2006/01/18 18:09:35 rodrigue Exp $*//*  Programme serveur de checkpoint */#include <stdlib.h>#include <stdio.h>#include <string.h>#include <errno.h>#include <unistd.h>#include <signal.h>#include <sys/types.h>#include <sys/wait.h>#include <sys/socket.h>#include <netinet/in.h>#include <netdb.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/utsname.h>#include <arpa/inet.h>#include "config.h"#include "debug.h"#include "checkpointServerError.h"#include "checkpointServerProto.h"#include "checkpointServerFile.h"#include "server.h"static char idFile[4096];static void on_sigchld(int s){   while( waitpid(-1, NULL, WNOHANG) > 0) /* nothing */ ;   signal(SIGCHLD, on_sigchld);}int main(int argc, char *argv[]) {  int se;  int sproto;  int sdata;  struct sockaddr_in addr;  socklen_t saddr;  struct hostent *he;  struct utsname nodename;  int socketToDispatcher;  struct gengetopt_args_info *args;  char *chkptpath = NULL;  signal(SIGCHLD, on_sigchld);	  if(uname(&nodename) < 0) qerror("Cannot get localhost name");  sprintf(idFile, "CS(%s)", nodename.nodename);  args = initialize_mpichv_service(idFile, argc, argv, &socketToDispatcher,				   &se);  if(args == NULL)    exit(1);  printi("CS_init","Checkpoint server launched");  chkptpath = args->tmp_dir_arg;  if(!chkptpath) chkptpath = CKPT_REPOSITORY_PATH;    if(chdir(chkptpath) == -1)     qerror("chdir to chkptfiles directory %s", chkptpath);  while(1)  {    saddr = sizeof(addr);    if((sproto = accept(se, (struct sockaddr *)&addr, &saddr)) == -1)       qerror("accept");    if((he = gethostbyaddr(&addr.sin_addr,sizeof(addr.sin_addr),AF_INET)) == NULL) herror("gethostbyaddr");    printi("CS_accept", "Client %s proto connection accepted", he->h_name);    switch(fork())    {      case -1 : qerror("fork");      case 0 :        close(se);        /* second part socket */        if((se = socket(AF_INET,SOCK_STREAM,0)) == -1) qerror("socket");        saddr = sizeof(addr);        addr.sin_family = AF_INET;        addr.sin_addr.s_addr = INADDR_ANY;        addr.sin_port = htons(0);        printi("CS_accept", "Binding data server for %s (%s) to mandatory port", he->h_name, inet_ntoa(addr.sin_addr));        if(bind(se,(struct sockaddr *)&addr,sizeof(addr)) == -1) qerror("bind");        if(listen(se,5) == -1) qerror("listen");        if(getsockname(se , (struct sockaddr *) &addr, &saddr) < 0) qerror("getsockname failed, aborting");        printi("CS_accept", "Bound data server for %s to port %d", he->h_name, ntohs(addr.sin_port));        if(write(sproto, &(addr.sin_port), sizeof(in_port_t)) != sizeof(in_port_t))        {          printw("Client %s crashed during connect transaction", he->h_name);          close(sproto);          close(se);          exit(-1);        }        saddr = sizeof(addr);        if((sdata = accept(se,(struct sockaddr *)&addr,&saddr)) == -1) qerror("accept");        printi("CS_accept", "Client %s data connection accepted", he->h_name);        traiter_message(sproto, sdata);        exit(0);      default :        close(sproto);        while(waitpid(-1,NULL,WNOHANG) > 0);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -