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

📄 meme-server.c

📁 EM算法的改进
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * $Id: meme-server.c 1339 2006-09-21 19:46:28Z tbailey $ *  * $Log$ * Revision 1.6  2006/01/03 06:37:00  tbailey * Fix "MEME_BINbin" bug in mast-client.txt. * Fix indentation in meme-server.c and meme-client.c. * * Revision 1.5  2005/10/02 00:18:25  nadya * revert to mast from mast.csh * * Revision 1.4  2005/09/13 21:11:36  nadya * rm exit line from mast/meme submit scripts * * Revision 1.3  2005/08/30 22:46:21  nadya * update calls to mailer * * Revision 1.2  2005/08/24 04:37:07  nadya * change script layout. Don't assume a given directory, * just use full path where needed for files and binaries. * * Revision 1.1.1.1  2005/07/29 17:17:54  nadya * Importing from meme-3.0.14, and adding configure/make * *//*	meme-server	Usage: meme-server <socket> <command> <qcmd>		<socket>  socket number to listen on		<command> command to execute; quote if spaces		<qcmd>   queueing command including switches and %s 			  which will be replaced by the qfile name	If the file sent to the socket contains just the word "ping",	the program exits with success.	2/10/96; created; bgrundy and tbailey*//*Date: Thu, 6 Jul 1995 09:42:01 +0059 (PDT)From: Allan Snavely <allans@SDSC.EDU>Subject: Re: sockets at SDSC <Pine.3.89.9506281510.b717-0100000> To: Bill Grundy <bgrundy@cs.ucsd.edu>	Howdy.  I am enclosing two programs supplied by Siamak. They realize a simple client server between a Paragon and a  workstation.  They don't actually do much; the server (running on the // machine) polls a port.  When it gets a message on that port from the client it forks a process.  I just tested this between ernie (my machine) and xray (both outside the firewall) and it worked. Here's the server.  Compile icc <file.c> -lm                     Run a.out -pn open -sz 1  (on the xray)-------------------------  server follows -----------------------------Format for input file read from the socket:----------------------ADDRESS <return address>PROGRAM memeDESCRIPTION <1 line of text>SWITCHES <switches>LOGINFO <information to log>BEGIN<sequences>Error messages:---------------  10 : Error opening file  11 : Error reading from socket  12 : Error writing to file  13 : Error sending ack to client  14 : Error binding socket  15 : Error listening to socket  16 : Error creating socket  20 : Header field not found  21 : Invalid field name  30 : system error*//*********************************************************************** * Include files ***********************************************************************/#include "meme-cs.h"/*********************************************************************** * Constants ***********************************************************************/#define MAXHEADERLINE 256/* ParaMEME parameters */#define MINW 12#define MAXW 55#define MAXITER 20#define TIME "2:00:00"/* system dependent things *//* returned by system() */#ifdef sunsparc  int SYSTEM_OK = -1;#else  int SYSTEM_OK = 0;#endif/*********************************************************************** * Type definitions ***********************************************************************/typedef struct HEADER {  char address[MAXHEADERLINE];  char program[MAXHEADERLINE];  char remotename[MAXHEADERLINE];  char description[MAXHEADERLINE];  char switches[MAXHEADERLINE];  char loginfo[MAXHEADERLINE];} HEADER;/*********************************************************************** * Globals  ***********************************************************************/int SOCKET_NUMBER;		/* socket to listen on */char *MEME;			/* name of meme executable */char *QCMD;			/* the queueing command *//*********************************************************************** * * void strlower * * Downcase a given string. * ***********************************************************************/void strlower(char *a_string){  int index;  for (index = 0; a_string[index] != '\0'; index++)    a_string[index] = tolower((int)a_string[index]);}/*********************************************************************** * * void read_header_item * * Read one header line from a socket into a HEADER data structure. * ***********************************************************************/void read_header_item(HEADER *a_header, int sock, char *fieldname, int field){  int i;  char buffer[MAXHEADERLINE];  char *info;    /* Read the line into a local buffer. */  if (readline(sock, buffer, MAXHEADERLINE) == 0) {    fprintf(stderr, "job: %d Error reading from socket.\n", (int) getpid());    fflush(stderr);    exit(11);  }  /*printf("%s (%d)\n", buffer, strlen(buffer));*/  /* Check to see if this is a ping */  if (strcmp(buffer, "ping") == 0) {    exit(0);				/* ping; exit with OK status */  }  /* print job number if first field */  if (field == 1) {    printf("\njob: %d\n", (int) getpid());    fflush(stdout);  }  /* Search for the field name in the line. */  if ((info = (char *)strstr(buffer, fieldname)) == NULL) {    fprintf(stderr, "Field %s not found in %s.\n", fieldname, buffer);    fflush(stderr);    exit(20);  }  /* Move past the end of the field name. */  info += strlen(fieldname) + 1;  /* Get the first character of the field name. */  /* (Happily, they are mutually exclusive.) */  switch (fieldname[0]) {    case 'A' :  /* ADDRESS */      strcpy(a_header->address, info);      break;    case 'P' :  /* PROGRAM */      strcpy(a_header->program, info);      break;    case 'R' :  /* REMOTENAME */      strcpy(a_header->remotename, info);      break;    case 'D' :  /* DESCRIPTION */      strcpy(a_header->description, info);      break;    case 'S' :  /* SWITCHES */      /* copy removing any nasty semi-colons to prevent security breach */      for (i=0; info[i]; i++) {        if (info[i] != ';') {          a_header->switches[i] = info[i];        } else {          a_header->switches[i] = ' ';        }      }      a_header->switches[i] = '\0';      break;    case 'L' :  /* LOGINFO */      strcpy(a_header->loginfo, info);      break;    case 'B' :  /* BEGIN */      /* Don't do anything. */      break;    default:      fprintf(stderr, "Invalid fieldname: %s\n", fieldname);      fflush(stderr);      exit(21);  }}/*********************************************************************** * * write_data_file * * Read in some sequences from a socket and write them to a file. * ***********************************************************************/void write_data_file(int sock, char *filename){  int filedescriptor, nread;  char achar;  /* Create the data file and open it in write-only mode. */  if ((filedescriptor = open(filename, 			     O_WRONLY | O_CREAT | O_TRUNC, 400)) == -1) {    fprintf(stderr, "Error creating file %s\n", filename);    fflush(stderr);    exit(10);  }        /* Read from the socket until no more bytes come through. */  for (nread = readn(sock, &achar, 1); nread == 1;       nread = readn(sock, &achar, 1)) {        /*printf("%c", achar);*/    /* Echo incoming data to the file. */    if (write(filedescriptor, &achar, 1) != 1) {      fprintf(stderr, "Error writing to file %s.\n", filename);      fflush(stderr);      exit(12);    }  }  if (nread != 0) {    fprintf(stderr, "Error reading from socket.\n");    fflush(stderr);    exit(11);  }       /* Close the file. */  close(filedescriptor);}/*********************************************************************** * * receive_file * * Read in a file from the socket. * ***********************************************************************/void receive_file(int sock, char *filename, HEADER *a_header){  /* Read in the header. */  read_header_item(a_header, sock, "ADDRESS", 1);  read_header_item(a_header, sock, "PROGRAM", 2);  read_header_item(a_header, sock, "REMOTENAME", 3);  read_header_item(a_header, sock, "DESCRIPTION", 4);  read_header_item(a_header, sock, "SWITCHES", 5);  read_header_item(a_header, sock, "LOGINFO", 6);  read_header_item(a_header, sock, "BEGIN", 7);  /* Echo the sequence data to a file. */  write_data_file(sock, filename);}/*********************************************************************** * * send_ack * * Send a single-byte ack to the client. * ***********************************************************************/void send_ack(int sock){  char achar = '1';  if (writen(sock, &achar, 1) != 1) {    fprintf(stderr, "Error sending ack to client.\n");    fflush(stderr);    exit(13);  }}/*********************************************************************** * * char *newfilename * * Creates a new filename, using the process ID for uniqueness. *      meme.<pid>.<filename> * ***********************************************************************/char *newfilename(char *filename, char * dir){  int length = 6 + 20 + strlen(filename) + 1 + strlen(dir);  char *name = (char *) mymalloc(length);   /* $dir is a palce holder, it will be filled in a shells cript */  sprintf(name, "%s/meme.%ld.%s", dir, (long) getpid(), filename);  return name;}/*********************************************************************** * * void make_q_script * * Write out an NQS submission file for the current job. * ***********************************************************************/void make_q_script(HEADER *a_header, char *meme_input, char *qfilename,                    char *meme_bin, char *meme_logs){  FILE *qfile;  char *resfilename, *datefilename;  long job = (long) getpid(); 		/* get the job number */  char dcmd[256];			/* date command */  /*char *dfmt = "-u '+\%d/\%m/\%y \%H:\%M:\%S'";*/	/* date format */

⌨️ 快捷键说明

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