コード例 #1
0
ファイル: serverSocket.c プロジェクト: Brinon/Zero_OS
void boundedServerLoop(int socketFD)
{
    int connectionFD;

#ifdef DEBUG
    printf("Conexions: [%d/%d]\n",NUM_CONECTIONS, MAX_CLIENTS);
#endif

    if(NUM_CONECTIONS >= MAX_CLIENTS)
    {

#ifdef DEBUG
        printf("Num maxim de conexions, pause\n");
#endif
        while (waitpid(-1,NULL,0) > 0);
    }
    connectionFD = acceptNewConnections (socketFD);
    if (connectionFD < 0)
    {
        perror ("Error establishing connection \n");
        deleteSocket(socketFD);
        exit (1);
    }
    doServiceFork(connectionFD);
}
コード例 #2
0
ファイル: serverSocket.c プロジェクト: Brinon/Zero_OS
void unboundedServerLoop(int socketFD)
{
    int connectionFD;
    connectionFD = acceptNewConnections (socketFD);
    if (connectionFD < 0)
    {
        perror ("Error establishing connection \n");
        deleteSocket(socketFD);
        exit (1);
    }
    doServiceFork(connectionFD);
}
コード例 #3
0
ファイル: serverUnbounded.c プロジェクト: Khr0nos/sockets
main (int argc, char *argv[])
{
  int socketFD;
  int connectionFD;
  char buffer[80];
  int ret;
  int port;


  if (argc != 2)
    {
      strcpy (buffer, "Usage: ServerSocket PortNumber\n");
      write (2, buffer, strlen (buffer));
      exit (1);
    }

  port = atoi(argv[1]);
  socketFD = createServerSocket(port);
  if (socketFD < 0)
    {
      perror ("Error creating socket\n");
      exit (1);
    }

  while (1) {
      connectionFD = acceptNewConnections (socketFD);
      if (connectionFD < 0)
      {
          perror ("Error establishing connection \n");
          deleteSocket(socketFD);
          exit (1);
      }

      doServiceFork(connectionFD);
  }
}