Ejemplo n.º 1
0
void open(Acceptor& acceptor, const typename Acceptor::endpoint_type& endpoint,
    int backlog, boost::system::error_code& error)
{
  acceptor.open(endpoint.protocol(), error);
  if (error)
  {
    return;
  }

  close_guard<Acceptor> acceptor_close_guard(acceptor);

  typename Acceptor::reuse_address reuse_address_opt(true);
  acceptor.set_option(reuse_address_opt, error);
  if (error)
  {
    return;
  }

  acceptor.bind(endpoint, error);
  if (error)
  {
    return;
  }

  acceptor.listen(backlog, error);

  if (!error)
  {
    acceptor_close_guard.release();
  }
}
Ejemplo n.º 2
0
Acceptor* AcceptorManager::create(Dispatcher* disp)
{
	Acceptor* acceptor = new Acceptor(_ioMux, _ssMgr, disp);

	acceptor->setType(EVENT_OBJECT_ACCEPTOR);

	_activatedAcceptors.push_back(acceptor);

	return acceptor;
}
Ejemplo n.º 3
0
Archivo: Link.cpp Proyecto: dhgoo/Link
bool Link::open(const char* ip, unsigned short port, Dispatcher* disp)
{
	if (_initialized == false) init();

	Acceptor* acceptor = _acceptorManager->create(disp);
	if (acceptor->open(ip, port) == false)
		return false;

	return true;
}
Ejemplo n.º 4
0
int run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("FlReactor_Test"));

  Fl_Window window (300, 370);

  Test_Window tw (10, 75, window.w () - 20, window.h ()-90);
  window.resizable (&tw);

  Fl_Hor_Slider slider (60, 5, window.w () - 70, 30, "Sides:");
  slider.align (FL_ALIGN_LEFT);
  slider.callback (sides_cb, &tw);
  slider.value (tw.sides ());
  slider.step (1);
  slider.bounds (3, 10);

  ACE_FlReactor reactor;
  ACE_Reactor r (&reactor);

  Fl_Box *box = new Fl_Box (FL_UP_BOX, 10, 40,
                            window.w () - 20, 30,
                            "Setting up");
  box->labelfont (FL_BOLD);

  Acceptor acceptor (&tw, box);

  ACE_INET_Addr address;

  if (acceptor.open (address, &r) == -1)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "%p\n",
                       "open acceptor"),
                      -1);

  acceptor.acceptor ().get_local_addr (address);

  const int bufsiz = 128;
  char buf[bufsiz];

  address.addr_to_string (buf, bufsiz, 0);

  char msg[2 * bufsiz];
  ACE_OS::sprintf (msg, "Listening on <%s>\n", buf);

  box->label (msg);
  box->redraw ();

  window.end ();
  window.show (argc, argv);
  tw.show ();

  return Fl::run ();

  ACE_END_TEST;
}
void HandleSet::HandleEvents(Reactor *reactor, LeaderFollowerPool *lfp, long timeout) {
	StartTrace(HandleSet.HandleEvents);

	Acceptor *acceptor = WaitForEvents(timeout);
	if (acceptor) {
		reactor->ProcessEvent(acceptor->DoAccept(), lfp);
	} else {
		// timeout case
		lfp->PromoteNewLeader();
	}
}
Ejemplo n.º 6
0
Task::Task(ACE_TCHAR const * endpoint)
  : endpoint_ (endpoint)
  , reactor_ (new ACE_TP_Reactor)
{
  ACE_INET_Addr local_sap (endpoint_);
  Acceptor * acceptor = new Acceptor;

  if(acceptor->open(local_sap, &reactor_, ACE_NONBLOCK) == -1)
    {
      ACE_ERROR((LM_ERROR, "Cannot open endpoint <%s>\n", endpoint_));
    }
}
Ejemplo n.º 7
0
Archivo: main.cpp Proyecto: Shumen/cgi
int handle_request(Acceptor& a)
{
  request req(a.protocol_service());   // Our request.

  int ret = 0;
  for (;;) // Handle requests until something goes wrong
           // (an exception will be thrown).
  {
    a.accept(req);
    response resp;    // A response object to make our lives easier.
    ret = handle_request(req, resp);
  }

  return ret;
}
Ejemplo n.º 8
0
int main() {
  SelectReactor selectReactor;
  Reactor reactor(&selectReactor);
  Acceptor<ServerHandler> acceptor;
  InetAddr listenAddr(ListenPort);

  // when connection established, make new io handler and register it to reactor
  if (acceptor.open(listenAddr, &reactor) == -1) {
    cout << "acceptor failed, errno: " << errno << endl;
    return -1;
  }

  reactor.runReactorEventLoop();

  return 0;
}
Ejemplo n.º 9
0
 inline auto accept(Acceptor& acceptor, Socket& socket, typename Acceptor::endpoint_type& endpoint, error_code& ec)
 {
     return make_awaiter<void>([&](auto&& cb)
     {
         acceptor.async_accept(socket, endpoint, std::move(cb));
     }, ec);
 }
Ejemplo n.º 10
0
 inline auto accept(Acceptor& acceptor, Socket& socket)
 {
     return make_awaiter<void>([&](auto&& cb)
     {
         acceptor.async_accept(socket, std::move(cb));
     });
 }
Ejemplo n.º 11
0
bool NetPipe::Open(size_t buf_size)
{
		assert(!m_reader.IsValid() && !m_writer.IsValid());
		
		if(m_reader.IsValid() || m_writer.IsValid()) return false;
		
		InetAddress addr;
		addr.SetAddr(::htonl(INADDR_LOOPBACK));
		addr.SetPort(0);
		
		Acceptor acceptor;
		
		CHECK_AND_RET( acceptor.Open(addr) );
		
		
		CHECK_AND_RET( acceptor.GetLocalAddr(addr) );
		



		CHECK_AND_RET( m_writer.Open() );
		
		int opt_val = 0;
		CHECK_AND_RET( m_writer.SetOpt(IPPROTO_TCP, TCP_NODELAY, &opt_val, sizeof(opt_val))	);
		
		opt_val = buf_size;
		
		CHECK_AND_RET( m_writer.SetOpt(SOL_SOCKET, SO_SNDBUF, &opt_val, sizeof(opt_val)) );

		CHECK_AND_RET(	Connector::Connect(m_writer, addr, 0)	);

		CHECK_AND_RET(	acceptor.Accept(m_reader) );

		assert(m_reader.IsValid() && m_writer.IsValid());

		m_reader.CloseWriter();
		m_writer.CloseReader();
		
		CHECK_AND_RET( m_reader.Enable(NET_NONBLOCK) && m_writer.Enable(NET_NONBLOCK) );

		return true;

}
Ejemplo n.º 12
0
int Client_Connection::open(void *acceptor_or_connector)
{
    typedef Acceptor<Client_Connection, ACE_SOCK_ACCEPTOR> Acceptor;
    Acceptor *acceptor = static_cast<Acceptor*>(acceptor_or_connector);
    m_holder = acceptor->holder();
    int open_ret = Connection::open(acceptor_or_connector);

    if(open_ret < 0)
    {
        return -1;
    }
    
    if(!m_holder->verify_connection(this))
    {
        return -1;
    }

    m_holder->add_connection(this);

    return 0;    
}
bool LeaderFollowerPool::InitReactor(ROAnything args) {
	StartTrace(LeaderFollowerPool.InitReactor);
	TraceAny(args, "Init arguments:");

	long argSz = args.GetSize();

	if (argSz <= 0) {
		Trace("argSz:[" << argSz << "]");
		SYSERROR("no acceptors: argument <= 0");
		return false;
	}
	if (!fReactor) {
		Trace("Reactor not set");
		SYSERROR("Reactor not set");
		return false;
	}

	for (long i = 0; i < argSz; ++i) {
		Acceptor *acceptor = (Acceptor *) args[i].AsIFAObject(0);
		if (acceptor) {
			int retVal;
			if ((retVal = acceptor->PrepareAcceptLoop()) != 0) {
				String logMsg;
				logMsg << "server (" << args.SlotName(i) << ")  prepare accept failed with retVal " << (long) retVal;
				SYSERROR(logMsg);
				Trace(logMsg);
				return false;
			}
			// start the accept loop
			OStringStream os;
			os << std::setw(20) << args.SlotName(i) << " Accepting requests from: " << acceptor->GetAddress() << " port: "
					<< acceptor->GetPort() << " backlog: " << acceptor->GetBacklog() << std::endl;
			SystemLog::WriteToStderr(os.str());
			fReactor->RegisterHandle(acceptor);
		} else {
			return false;
		}
	}
	return true;
}
Ejemplo n.º 14
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Proactor_Scatter_Gather_Test"));

  if (::parse_args (argc, argv) == -1)
    return -1;

  chunk_size = ACE_OS::getpagesize ();

  if (client_only)
    ACE_DEBUG ((LM_INFO,
                ACE_TEXT ("Running as client only, page size %d\n"),
                chunk_size));
  else if (server_only)
    ACE_DEBUG ((LM_INFO,
                ACE_TEXT ("Running as server only, page size %d\n"),
                chunk_size));
  else
    ACE_DEBUG ((LM_INFO,
                ACE_TEXT ("Running as server and client, page size %d\n"),
                chunk_size));

  Acceptor  acceptor;
  Connector connector;
  ACE_INET_Addr addr (port);

  if (!client_only)
    {
      // Simplify, initial read with zero size
      if (-1 == acceptor.open (addr, 0, 1))
        {
          ACE_TEST_ASSERT (0);
          return -1;
        }
    }

  if (!server_only)
    {
      if (-1 == connector.open (1, ACE_Proactor::instance ()))
        {
          ACE_TEST_ASSERT (0);
          return -1;
        }

      // connect to first destination
      if (addr.set (port, host, 1, addr.get_type ()) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), host), -1);
      connector.set_address (addr);
      if (-1 == connector.connect (addr))
        {
          ACE_TEST_ASSERT (0);
          return -1;
        }
    }

  ACE_Proactor::instance ()->run_event_loop ();

  // As Proactor event loop now is inactive it is safe to destroy all
  // senders

  connector.stop ();
  acceptor.stop ();

  ACE_Proactor::instance()->close_singleton ();

  // now compare the files - available only when on same machine

  int success = 0;
  if (!client_only && !server_only)
    {
      ACE_DEBUG ((LM_INFO,
                  ACE_TEXT ("Comparing the input file and the output file...\n")));

      success = -1;
      // map the two files, then perform memcmp
      {
        ACE_Mem_Map original_file (input_file);
        ACE_Mem_Map reconstructed_file (output_file);

        if (original_file.addr () &&
            original_file.addr () != MAP_FAILED &&
            reconstructed_file.addr () &&
            reconstructed_file.addr () != MAP_FAILED)
          {
            // compare lengths
            if ((original_file.size () == reconstructed_file.size ()) &&
                // and if same size, compare file data
                (0 == ACE_OS::memcmp (original_file.addr (),
                                      reconstructed_file.addr (),
                                      original_file.size ())))
              success = 0;
          }
      }

      if (0 == success)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("input file and the output file identical!\n")));
      else
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("input file and the output file are different!\n")));
    }

  if (!client_only)
    ACE_OS::unlink (output_file);

  ACE_END_TEST;

  return success;
}
Ejemplo n.º 15
0
// *************************************************************
//   Configuration helpers
// *************************************************************
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("PSSL_Test"));


  if (cfg.parse_args (argc, argv) < 0)
    return -1;

  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);
  disable_signal (SIGPIPE, SIGPIPE);
  disable_signal (SIGIO, SIGIO);

  //ACE_DEBUG ((LM_DEBUG,
  //            ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"),
  //            FD_SETSIZE,
  //            ACE_FD_SETSIZE));

  ACE_DEBUG ((LM_DEBUG,
             "s_blksize=%u r_blksize=%u win_size=%u\n",
              cfg.s_blksize(),
              cfg.r_blksize(),
              cfg.w_size()));

  ACE_SSL_Context *context = ACE_SSL_Context::instance ();
  // Note - the next two strings are naked on purpose... the arguments to
  // the ACE_SSL_Context methods are const char *, not ACE_TCHAR *.
  context->certificate ("dummy.pem", SSL_FILETYPE_PEM);
  context->private_key ("key.pem", SSL_FILETYPE_PEM);


  {
  int rc = 0;

  ProactorTask task1(cfg);

  RecvFactory r_factory;
  SendFactory s_factory;

  PSessionManager r_manager (task1, r_factory,"R_Manager");
  PSessionManager s_manager (task1, s_factory,"S_Manager");

  Acceptor  acceptor  (r_manager);
  Connector connector (s_manager);

  ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
  ACE_Time_Value time_end = ACE_OS::gettimeofday ();
  ACE_Time_Value time_run;

  if (task1.start () == 0)
    {
      ACE_Time_Value timeout (cfg.timeout(), 0);
      r_manager.set_timeout (timeout);
      s_manager.set_timeout (timeout);

      if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
        {
          // Simplify, initial read with zero size
          if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
            rc = 1;
        }

      if (cfg.both() != 0 || cfg.connections () > 0) // Connector
        {
          ACE_INET_Addr addr;

          addr.set (cfg.connect_port(), cfg.connect_host());

          rc += connector.start (addr, cfg.connections ());
        }

      time_begin = ACE_OS::gettimeofday ();

      if (rc > 0)
        {
          task1.enable_event_loop();
          
          ACE_Time_Value  sleep_time (cfg.seconds());
           
          while ( sleep_time != ACE_Time_Value::zero)
            {
              ACE_Countdown_Time countdown ( & sleep_time );

              ACE_OS::sleep (sleep_time );
            }


          if (cfg.seconds () == 0)
            {
              // comment this later
              char c;
              cout << "Press any key to stop=>" << flush;
              cin.clear ();
              cin >> c;
            }
        }
Ejemplo n.º 16
0
void Minimizer::minimize(Acceptor* pAcceptor)
{
	// Zeiger auf Akzeptor zur Verwendung dereferenzieren
	Acceptor Acceptor = *pAcceptor;
	// Für 0 - Äquivalenzrelation zwei Äquivalenzklassen initialisieren
	EquivalenceClass EQ_1 = EquivalenceClass(0);
	EquivalenceClass EQ_2 = EquivalenceClass(0);
	// Liste der Zustände durchsuchen
	for (int i = 0; i < Acceptor.getNrOfStates(); i++)
	{
		// für aktuellen Zustand Zeile mit dessen Verhaltensinformationen in temporärer Variable speichern
		StateBehaviour temp_row = *(Acceptor.getRow(i));
		// ---------Equivalenzklasse 1 für gefundenen akzeptierenden Zustand bilden und füllen
		if (temp_row.getFavourable())
		{
			if (!(EQ_1.getRepresentantive()))
			{
				EQ_1.setRepresentantive(temp_row.getState());
			}
			// ist der Zustand schon enthalten?
			bool alreadyListed = false;
			// durchsuche die Äquivalenzklasse
			for (int m = 0; m < EQ_1.getNrOfEqualStates(); m++)
			{
				if (EQ_1.getEqualState(m) == temp_row.getState())
				{
					alreadyListed = true;
				}
			}
			// ist der Zustand noch nicht enthalten, füge ihn hinzu
			if (!alreadyListed)
			{
				EQ_1.addEqualState(temp_row.getState());
			}
		}
		// ---------Equivalenzklasse 2 für nicht akzeptierende Zustände bilden und füllen
		else if (!(temp_row.getFavourable()))
		{
			if (!(EQ_2.getRepresentantive()))
			{
				EQ_2.setRepresentantive(temp_row.getState());
			}
			// ist der Zustand schon enthalten?
			bool alreadyListed = false;
			// durchsuche die Äquivalenzklasse
			for (int m = 0; m < EQ_2.getNrOfEqualStates(); m++)
			{
				if (EQ_2.getEqualState(m) == temp_row.getState())
				{
					alreadyListed = true;
				}
			}
			// ist der Zustand noch nicht enthalten, füge ihn hinzu
			if (!alreadyListed)
			{
				EQ_2.addEqualState(temp_row.getState());
			}
		}
		else
			break;
	}
	this->addEqClass(&EQ_1);
	this->addEqClass(&EQ_2);
}
Ejemplo n.º 17
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("W_Test"));


  if (cfg.parse_args (argc, argv) < 0)
    return -1;

  disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX);
  disable_signal (SIGPIPE, SIGPIPE);
  disable_signal (SIGIO, SIGIO);

  //ACE_DEBUG ((LM_DEBUG,
  //            ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"),
  //            FD_SETSIZE,
  //            ACE_FD_SETSIZE));

  ACE_DEBUG ((LM_DEBUG,
             "s_blksize=%u r_blksize=%u win_size=%u\n",
              cfg.s_blksize(),
              cfg.r_blksize(),
              cfg.w_size()));


  ACE_SSL_Context *context = ACE_SSL_Context::instance ();
  // Note - the next two strings are naked on purpose... the arguments to
  // the ACE_SSL_Context methods are const char *, not ACE_TCHAR *.
  context->certificate ("dummy.pem", SSL_FILETYPE_PEM);
  context->private_key ("key.pem", SSL_FILETYPE_PEM);


  {
  int rc = 0;

  ProactorTask task1(cfg);

  RecvFactory    r_factory;
  RecvFactorySSL r_ssl_factory;

  PConnectionManager r_manager     (task1, r_factory,"R_Manager");
  PConnectionManager r_ssl_manager (task1, r_ssl_factory,"R_SSL_Manager");

  Acceptor  acceptor     (r_manager);
  Acceptor  acceptor_ssl (r_ssl_manager);

  ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
  ACE_Time_Value time_end = ACE_OS::gettimeofday ();
  ACE_Time_Value time_run;

  if (task1.start () == 0)
    {
      ACE_Time_Value timeout (cfg.timeout(), 0);
      r_manager.set_timeout (timeout);

      // Simplify, initial read with zero size
      if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
        rc = 1;

      if (acceptor_ssl.start (ACE_INET_Addr (cfg.listen_port()+1)) == 0)
        rc = 1;

      time_begin = ACE_OS::gettimeofday ();

      if (rc > 0)
        {
          task1.enable_event_loop();
          
          char c;
          cout << "Press any key to stop=>" << flush;
          cin.clear ();
          cin >> c;
        }
    }
Acceptor *HandleSet::WaitForEvents(long timeout) {
	StartTrace1(HandleSet.WaitForEvents, "Timeout: " << timeout);
	const long NOFDS = fDemuxTable.GetSize();
#if defined(USE_SELECT)
	fd_set rfds;
	FD_ZERO(&rfds);
	long maxfd = 0;
#else
	pollfd fds[NOFDS];
#endif
	long i = 0L, sz = 0;
	for (i = 0; i < NOFDS; ++i) {
#if !defined(USE_SELECT)
		fds[i].events = POLLIN;
		fds[i].fd = -1;
#endif
		Acceptor *a = (Acceptor *) fDemuxTable[i].AsIFAObject(0);
		if (a) {
			int fd = a->GetFd();
			if (fd >= 0) {
#if defined(USE_SELECT)
				FD_SET(fd, &rfds);
				if (fd > maxfd) {
					maxfd = fd;
				}
#else
				fds[i].fd = fd;
#endif
			}
		}
	}
	if (0 == timeout) {
		timeout = 200;
	}
#if defined(USE_SELECT)
	struct timeval tv;
	tv.tv_sec = timeout / 1000;
	tv.tv_usec = 1000 * (timeout % 1000);
	long retCode = select(maxfd + 1, &rfds, 0, 0, &tv);
#else
	long retCode = poll(fds, NOFDS, timeout);
#endif
	if (0 == retCode) {
		return 0; // timeout, no error
	}
	while (retCode < 0 && coast::system::SyscallWasInterrupted()) {
#if defined(USE_SELECT)
		retCode = select(maxfd + 1, &rfds, 0, 0, &tv);
#else
		retCode = poll(fds, NOFDS, timeout);
#endif
		SYSERROR("select/poll call interrupted. I do a restart. Socket error number: " <<
				(long) SOCKET_ERROR << " return code " << retCode << " LastSyError: " << SystemLog::LastSysError());
	}
	if (retCode > 0) {
		for (i = 0, sz = fDemuxTable.GetSize(); i < sz; ++i) {
			long idx = (fLastAcceptorUsedIndex + 1 + i) % NOFDS;
			Acceptor *a = (Acceptor *) fDemuxTable[idx].AsIFAObject(0);
			if (a) {
#if defined(USE_SELECT)
				int fd = a->GetFd();
				if (fd >= 0 && FD_ISSET(fd, &rfds))
#else
				Assert(a->GetFd() == fds[idx].fd);
				if (fds[idx].revents & POLLIN)
#endif
				{
					fLastAcceptorUsedIndex = idx;
					return a;
				}
			}
		}
	}
	SYSERROR("select/poll call with acceptors failed");
	SYSERROR("Socket error number: " << (long) SOCKET_ERROR << " return code " << retCode <<
			" LastSyError: " << SystemLog::LastSysError());
	return 0;
}
Ejemplo n.º 19
0
THREAD_PROC Acceptor::startThread( void* p )
{
  Acceptor * pAcceptor = static_cast < Acceptor* > ( p );
  pAcceptor->onStart();
  return 0;
}
Ejemplo n.º 20
0
// *************************************************************
//   Configuration helpers
// *************************************************************
int
run (int argc, ACE_TCHAR *argv[])
{
    int rc = 0;

    ProactorTask task1(cfg);

    RecvFactory r_factory;
    SendFactory s_factory;

    PSessionManager r_manager (task1, r_factory,"R_Manager");
    PSessionManager s_manager (task1, s_factory,"S_Manager");

    Acceptor  acceptor  (r_manager);
    Connector connector (s_manager);

    ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
    ACE_Time_Value time_end = ACE_OS::gettimeofday ();
    ACE_Time_Value time_run;

    if (task1.start () == 0)
    {
        task1.enable_event_loop();

        ACE_Time_Value timeout (cfg.timeout(), 0);
        r_manager.set_timeout (timeout);
        s_manager.set_timeout (timeout);

        if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
        {
            if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
                rc = 1;
        }

        if (cfg.both() != 0 || cfg.connections () > 0) // Connector
        {
            ACE_INET_Addr addr;

            addr.set (cfg.connect_port(), cfg.connect_host());

            rc += connector.start (addr, cfg.connections ());
        }
    }

    time_begin = ACE_OS::gettimeofday ();

    if (rc > 0)
    {
        //task1.enable_event_loop();
        
        ACE_Time_Value  sleep_time (cfg.seconds());
        
        while ( sleep_time != ACE_Time_Value::zero)
        {
            ACE_Countdown_Time countdown ( & sleep_time );
            ACE_OS::sleep (sleep_time );
        }

        if (cfg.seconds () == 0)
        {
            bool flgExit = false;
            for (;!flgExit;)
            {
                char c;
                cout << "\nPress Q to stop=>" << flush;
                cin.clear ();
                cin >> c;
                switch (toupper (c))
                {
                case 'Q':
                    flgExit = true;
                    break;
                case 'P':
                    cout << "\n*** Connector: PendingConnects="
                        << connector.get_ref_cnt()
                        << " Senders="
                        << s_manager.get_number_connections ()
                        << "\n*** Acceptor: PendingAccepts="
                        << acceptor.get_ref_cnt()
                        << " Receivers="
                        << r_manager.get_number_connections ();
                break;
                }//switch
            }//for
        }//if cfg.seconds
Ejemplo n.º 21
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("TP_Reactor_Test"));

#if defined(ACE_HAS_THREADS)
  if (::parse_args (argc, argv) == -1)
    return -1;

  ::disable_signal (SIGPIPE, SIGPIPE);

  MyTask    task1;
  Acceptor  acceptor;
  Connector connector;

  if (task1.start (threads) == 0)
    {
      int rc = 0;

      ACE_INET_Addr addr (port);
      if (both != 0 || host == 0) // Acceptor
        rc += acceptor.start (addr);

      if (both != 0 || host != 0)
        {
          if (host == 0)
            host = ACE_LOCALHOST;

          if (addr.set (port, host, 1, addr.get_type ()) == -1)
            ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), host));
          rc += connector.start (addr, senders);

        }

      if (rc > 0)
        ACE_OS::sleep (seconds);
    }

  task1.stop ();

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nNumber of Receivers objects = %d\n")
              ACE_TEXT ("\nNumber of Sender objects = %d\n"),
              acceptor.get_number_sessions (),
              connector.get_number_sessions ()));

  // As Reactor event loop now is inactive it is safe to destroy all
  // senders

  connector.stop ();
  acceptor.stop ();

  //Print statistic
  ACE_TCHAR bufs [256];
  ACE_TCHAR bufr [256];

  ACE_OS::sprintf ( bufs , ACE_TEXT ("%ld(%ld)"),
                    connector.get_total_snd(),
                    connector.get_total_w() );

  ACE_OS::sprintf ( bufr , ACE_TEXT ("%ld(%ld)"),
                    connector.get_total_rcv(),
                    connector.get_total_r() );

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Connector/Senders  total bytes: snd=%s rcv=%s\n"),
              bufs,
              bufr
            ));

  ACE_OS::sprintf ( bufs , ACE_TEXT ("%ld(%ld)"),
                    acceptor.get_total_snd(),
                    acceptor.get_total_w() );

  ACE_OS::sprintf ( bufr , ACE_TEXT ("%ld(%ld)"),
                    acceptor.get_total_rcv(),
                    acceptor.get_total_r() );

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Acceptor/Receivers total bytes: snd=%s rcv=%s\n"),
              bufs,
              bufr
            ));

#else /* ACE_HAS_THREADS */
   ACE_UNUSED_ARG( argc );
   ACE_UNUSED_ARG( argv );
#endif /* ACE_HAS_THREADS */

  ACE_END_TEST;

  return 0;
}
Ejemplo n.º 22
0
// *************************************************************
//   Configuration helpers
// *************************************************************
int
run (int argc, ACE_TCHAR *argv[])
{
    int rc = 0;

    ProactorTask task1(cfg);
    if (task1.start () != 0)
    {
        task1.stop ();
        return -1;
    }
    
    task1.enable_event_loop();
    
    RecvFactory r_factory;
    SendFactory s_factory;

    PConnectionManager r_manager (task1, r_factory,"R_Manager");
    PConnectionManager s_manager (task1, s_factory,"S_Manager");

    Acceptor  acceptor  (r_manager);
    Connector connector (s_manager);

    ACE_Time_Value time_begin = ACE_OS::gettimeofday ();
    ACE_Time_Value time_end = ACE_OS::gettimeofday ();
    ACE_Time_Value time_run;

            
    ACE_Time_Value timeout (cfg.timeout(), 0);
    r_manager.set_timeout (timeout);
    s_manager.set_timeout (timeout);
    
    
    time_begin = ACE_OS::gettimeofday ();
    
    

    if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor
    {
        // Simplify, initial read with zero size
        if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0)
            rc = 1;
    }

    if (cfg.both() != 0 || cfg.connections () > 0) // Connector
    {
        ACE_INET_Addr addr;

        addr.set (cfg.connect_port(), cfg.connect_host());

        rc += connector.start (addr, cfg.connections ());
    }
    

    if (rc > 0)
    {
        //task1.enable_event_loop();
            
        ACE_Time_Value  sleep_time (cfg.seconds());
            
        while ( sleep_time != ACE_Time_Value::zero)
        {
            ACE_Countdown_Time countdown ( & sleep_time );

            ACE_OS::sleep (sleep_time );
        }


        if (cfg.seconds () == 0)
        {
            bool flgExit = false;
            for (;!flgExit;)
            {
                char c;
                cout << "\nEnter:"
                     << "\n1 - stop  connector"
                     << "\n2 - stop  acceptor"
                     << "\n3  -stop  senders"
                     << "\n4  -stop  receivers"
                     << "\nP - statistic"
                     << "\nQ   quit=>" 
                     << flush;
                cin.clear ();
                cin >> c;
                switch (toupper (c))
                {
                case '1':
                    connector.cancel();
                    connector.wait ();
                    break;
                case '2':
                    acceptor.cancel ();
                    acceptor.wait();
                    break;
                case '3':
                    s_manager.cancel ();
                    while (!s_manager.is_safe_to_delete ())
                    {
                       task1.wait_signal ();
                    }
                    break;
                case '4':
                    r_manager.cancel ();
                    while (!r_manager.is_safe_to_delete ())
                    {
                       task1.wait_signal ();
                    }
                    break;
                case 'Q':
                    flgExit = true;
                    break;
                case 'P':
                    break;
                }//switch
                cout << "\n*** Connector: PendingConnects="
                    << connector.get_pending_count ()
                    << " Senders="
                    << s_manager.get_number_connections ()
                    << "\n*** Acceptor: PendingAccepts="
                    << acceptor.get_pending_count ()
                    << " Receivers="
                    << r_manager.get_number_connections ();
            }//for
        }//if cfg.seconds