Esempio n. 1
0
void partition_data_multithread(long number_of_data, char* inputfilename, char* outputfilename)
{
  mpi::communicator world;
  long partition_index = number_of_data/world.size();
  pout << "begin partition\n";
  std::thread datasend(partition_data_sendthread<T>,inputfilename,partition_index);
  std::thread datarecv(partition_data_recvthread<T>,outputfilename);

  datasend.join();
  datarecv.join();

  world.barrier();

}
/******** DOSTUFF() *********************
 There is a separate instance of this function 
 for each connection.  It handles all communication
 once a connnection has been established.
 *****************************************/
void dostuff (int sock)
{
   int n,m;
   char buffer[BUF_SIZE],request[BUF_SIZE];
   bzero(buffer,BUF_SIZE);
   ReqInfo internalData;
   n = recv(sock,buffer,BUF_SIZE-1,0);
   if (n < 0) error("ERROR reading from socket");
   strcpy(request,buffer);
    internalData = parseRequest(request);
    //printf("%s,%s\n",internalData.Method,internalData.Protocol);
    printf("Here is the message:\n%s",buffer);
    bzero(buffer,BUF_SIZE);
    //PART A: Dump Request Message to the Console
    while (n == BUF_SIZE-1)
    {
        n = recv(sock,buffer,BUF_SIZE-1,0);
        if (n < 0) error("ERROR reading from socket");
        printf("%s",buffer);
        bzero(buffer,BUF_SIZE);
    }
   if(!IsValidHeader(internalData))
   {
       m = send(sock,"HTTP/1.1 400 Bad Request\r\n\r\n 400 Bad Request",sizeof("HTTP/1.1 400 Bad Request\r\n\r\n 400 Bad Request")-1,0);
       printf("HTTP/1.1 400 Bad Request\r\n\r\n");
       if (m < 0) error("ERROR writing to socket");
   }
   else if(Length(internalData.Path)<0)
    {
        m = send(sock,"HTTP/1.1 404 Not Found\r\n\r\n 404 Not found",sizeof("HTTP/1.1 404 Not Found\r\n\r\n 404 Not found")-1,0);
        printf("HTTP/1.1 404 Not Found\r\n\r\n");
        if (m < 0) error("ERROR writing to socket");
        //printf("%d",m);
        fprintf(stderr,"file cannot open\n");
    }
   
    else
    {datasend(sock,internalData.Path);}
   
}