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

📄 console_input.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
字号:
// Console_Input.cpp,v 4.3 2003/11/05 09:36:08 jwillemsen Exp

// ============================================================================
//
// = LIBRARY
//    examples
//
// = FILENAME
//    Console_Input.cpp
//
// = DESCRIPTION
//
//    This application tests the working of WFMO_Reactor when users
//    are interested in console input.
//
// = AUTHOR
//    Irfan Pyarali <irfan@cs.wustl.edu>
//
// ============================================================================

#include "ace/Reactor.h"
#include "ace/OS_NS_unistd.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_main.h"

ACE_RCSID(WFMO_Reactor, Console_Input, "Console_Input.cpp,v 4.3 2003/11/05 09:36:08 jwillemsen Exp")

class Event_Handler : public ACE_Event_Handler
{
public:
  Event_Handler (ACE_Reactor &reactor);
  int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0);
  int handle_close (ACE_HANDLE handle,
                    ACE_Reactor_Mask close_mask);
};

Event_Handler::Event_Handler (ACE_Reactor &reactor)
{
  this->reactor (&reactor);

  if (this->reactor ()->register_handler (this,
                                          ACE_STDIN) != 0)
    ACE_ERROR ((LM_ERROR,
                "Registration with Reactor could not be done\n"));
}

int
Event_Handler::handle_signal (int, siginfo_t *, ucontext_t *)
{
  ACE_TCHAR buffer[BUFSIZ];
  int result = ACE_OS::read (ACE_STDIN, buffer, sizeof buffer);
  buffer[result] = '\0';

  if (result <= 0)
    {
      this->reactor ()->close ();
      ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_OS::read"), -1);
    }

  if (ACE_OS::strcmp (ACE_TEXT("quit\r\n"), buffer) == 0)
    this->reactor ()->close ();

  ACE_DEBUG ((LM_DEBUG, "User input: %s", buffer));

  return 0;
}

int
Event_Handler::handle_close (ACE_HANDLE,
                             ACE_Reactor_Mask)
{
  ACE_DEBUG ((LM_DEBUG, "Event_Handler removed from Reactor\n"));
  return 0;
}

int
ACE_TMAIN (int, ACE_TCHAR *[])
{
  ACE_Reactor reactor;
  Event_Handler handler (reactor);

  int result = 0;
  while (result != -1)
    result = reactor.handle_events ();

  return 0;
}

⌨️ 快捷键说明

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