博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
小用ACE_Acceptor
阅读量:4843 次
发布时间:2019-06-11

本文共 2849 字,大约阅读时间需要 9 分钟。

Ace_Acceptor是ACE的接收器之一,此次使用涉及了这个类的三个函数:open\accept_svc_handler\activate_svc_handler。

其中open函数的原型之一:

/**   * Open the contained @c PEER_ACCEPTOR object to begin listening, and   * register with the specified reactor for accept events.  An   * acceptor can only listen to one port at a time, so make sure to   * @c close() the acceptor before calling @c open() again.   *   * The @c PEER_ACCEPTOR handle is put into non-blocking mode as a   * safeguard against the race condition that can otherwise occur   * between the time when the passive-mode socket handle is "ready"   * and when the actual @c accept() call is made.  During this   * interval, the client can shutdown the connection, in which case,   * the @c accept() call can hang.   *   * @param local_addr The address to listen at.   * @param reactor    Pointer to the ACE_Reactor instance to register   *                   this object with. The default is the singleton.   * @param flags      Flags to control what mode an accepted socket   *                   will be put into after it is accepted. The only   *                   legal value for this argument is @c ACE_NONBLOCK,   *                   which enables non-blocking mode on the accepted   *                   peer stream object in @c SVC_HANDLER.  The default   *                   is 0.   * @param use_select Affects behavior when called back by the reactor   *                   when a connection can be accepted.  If non-zero,   *                   this object will accept all pending connections,   *                   instead of just the one that triggered the reactor   *                   callback.  Uses ACE_OS::select() internally to   *                   detect any remaining acceptable connections.   *                   The default is 1.   * @param reuse_addr Passed to the @c PEER_ACCEPTOR::open() method with   *                   @p local_addr.  Generally used to request that the   *                   OS allow reuse of the listen port.  The default is 1.   *   * @retval 0  Success   * @retval -1 Failure, @c errno contains an error code.   */  virtual int open (const ACE_PEER_ACCEPTOR_ADDR &local_addr,                    ACE_Reactor *reactor = ACE_Reactor::instance (),                    int flags = 0,                    int use_select = 1,                    int reuse_addr = 1);

其中第一个参数,一般传入ACE_NET_Addr,在通过字符串(ip:port)构造对象后,需要检查对象是否含有效地址。即使传入无效的地址对象,open也不会报错。

第二个参数是反应器,不建议直接传入单体,这个可以传入ACE_Dev_Poll_Reactor\ACE_Select_Reactor构造出来的ACE_Reactor,在reactor激活之后,open之后才会真正的接入链接。

      一旦链接接入,就会触发acceptor的handle_input调用的主要函数就是accept_svc_handler\activate_svc_handler。原生的accept_svc_handler函数中,无超时设置,在多进程接收链接,出现惊群现象时,会导致竞争不到链接的进程卡死在accept,一般情况下需要重写设置一个超时时间。原生的activate_svc_handler会直接在接收线程内触发svc的handle_input,一旦此函数有耗时操作,也会阻塞acceptor,一般会将acceptor抛入异线程再进行接收数据。

 

转载于:https://www.cnblogs.com/longking/p/ace_acceptor01.html

你可能感兴趣的文章
IDEA快捷键
查看>>
【tmos】spring boot项目中处理Schedule定时任务
查看>>
Nginx+certbot 实现泛域名的https证书
查看>>
python实现链表(一)
查看>>
多层下firebird自增长字段的处理
查看>>
JS输入输出等补充
查看>>
转android四种动画
查看>>
初学android:四大组件之contentprovider
查看>>
1289大鱼吃小鱼(STL中栈的应用)
查看>>
POJ3177 Redundant Paths
查看>>
初学树
查看>>
Hibernate延迟加载
查看>>
在子页面使用layer弹出层时只显示遮罩层,不显示弹出框问题
查看>>
<吴恩达老师深度学习笔记一>深度学习概述
查看>>
smarty 模板标签
查看>>
第二阶段团队冲刺(十)
查看>>
001- CreateProcess failed with error 216 (no message available)错误详解
查看>>
菜根谭#205
查看>>
菜根谭#222
查看>>
java-01-java基础知识1
查看>>