本文整理汇总了C++中TCPStream::getRemoteAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ TCPStream::getRemoteAddr方法的具体用法?C++ TCPStream::getRemoteAddr怎么用?C++ TCPStream::getRemoteAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TCPStream
的用法示例。
在下文中一共展示了TCPStream::getRemoteAddr方法的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();
}