Exemplo n.º 1
0
int
main (int argc, char *argv[])
{
  u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT;
  ACE_INET_Addr l_addr (port);
  ACE_TLI_Acceptor server (l_addr, 1); // Create server, reuse addr if in use.
  ACE_TLI_Stream new_stream;

  // Wait for a connection from a client.  This is an example of a
  // concurrent server.

  for (;;)
    {
      if (server.accept (new_stream) == -1)
        ACE_OS::t_error ("server.accept error");

      if (thr_mgr.spawn (ACE_THR_FUNC (lookup_name),
                         (void *) new_stream.get_handle (),
                         THR_DETACHED) == -1)
        ACE_DEBUG ((LM_ERROR,
                    "server: can't create worker thread %d\n"));
    }

  ACE_NOTREACHED (return 0);
}
Exemplo n.º 2
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT;
  ACE_TLI_Acceptor server;
  ACE_TLI_Stream new_stream;

  // Open the server and reuse the address if in use...
  if (server.open (ACE_INET_Addr (port), 1) == -1)
    ACE_OS::t_error ("server.open"), ACE_OS::exit (1);

  // Wait for a connection from a client.  This is an example of a
  // concurrent server.

  for (int count = 1; ; count++)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "thread %t, blocking for accept #%d\n",
                  count));

      if (server.accept (new_stream) == -1)
        ACE_OS::t_error ("server.accept error");

      else if (thr_mgr.spawn (ACE_THR_FUNC (read_file),
                              (void *) new_stream.get_handle (),
                              THR_DETACHED | THR_BOUND) == -1)
        ACE_OS::perror ("can't create worker thread\n");
    }

  ACE_NOTREACHED (return 0);
}