当前位置: 首页>>代码示例>>C++>>正文


C++ TCPStream::getRemotePort方法代码示例

本文整理汇总了C++中TCPStream::getRemotePort方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPStream::getRemotePort方法的具体用法?C++ TCPStream::getRemotePort怎么用?C++ TCPStream::getRemotePort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TCPStream的用法示例。


在下文中一共展示了TCPStream::getRemotePort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: doaccept

int mbed_socket::doaccept(struct sockaddr *addr, socklen_t *addrlen) {
  void* impl;

  impl = incomming_pop();
  if (impl == NULL) {
    set_errno(EINVAL);
    TDLOG(".. doaccept error: incomming null");
    return -1;
  }

  TCPListener* listener = get_listener();
  if (listener == NULL) {
    set_errno(EOPNOTSUPP);
    TDLOG(".. doaccept error: no listener");
    return -1;
  }

  mbed_socket* socli;
  socli = new mbed_socket(domain_, type_, protocol_);
  if (socli == NULL) {
    set_errno(ENOMEM);
    TDLOG(".. doaccept error: out of memory");
    return -1;
  }
  if (socli->get_sock_fd() < 0) {
    delete socli;
    TDLOG(".. doaccept error: out of fd");
    set_errno(ENOMEM);
    return -1;
  }

  TCPStream* stream;
  stream = listener->accept(impl);
  if (stream == NULL) {
    TDLOG(".. doaccept error: accept failed");
    delete socli;
    set_errno(ENOMEM);
    return -1;
  }

  // it's already connected. there will be no "on_connected" cb called
  socli->set_stream(stream, true);

  stream->setOnError(on_error_t(socli, &mbed_socket::on_error));
  stream->setOnReadable(on_readable_t(socli, &mbed_socket::on_readable));
  stream->setOnSent(on_sent_t(socli, &mbed_socket::on_sent));
  stream->setOnDisconnect(on_disconnect_t(socli, &mbed_socket::on_disconnect));

  //
  if (addr && addrlen) {
    memset(addr, 0, *addrlen);

    struct sockaddr_in* inaddr = (struct sockaddr_in*)addr;

    SocketAddr sockaddr;
    uint16_t sockport;
    stream->getRemoteAddr(&sockaddr);
    stream->getRemotePort(&sockport);
    assert(sockaddr.is_v4());

    inaddr = (struct sockaddr_in*)addr;

    inaddr->sin_family = AF_INET;
    inaddr->sin_addr.s_addr = socket_addr_get_ipv4_addr(sockaddr.getAddr());
    inaddr->sin_port = sockport;

    *addrlen = sizeof(struct sockaddr_in);
  }

  return socli->get_sock_fd();
}
开发者ID:esevan,项目名称:libtuv,代码行数:71,代码来源:tuv_mbed_port_socket.cpp


注:本文中的TCPStream::getRemotePort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。