本文整理汇总了C++中SockAddr::getAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ SockAddr::getAddr方法的具体用法?C++ SockAddr::getAddr怎么用?C++ SockAddr::getAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SockAddr
的用法示例。
在下文中一共展示了SockAddr::getAddr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doSaslStep
Status doSaslStep(const ClientBasic* client,
SaslAuthenticationSession* session,
const BSONObj& cmdObj,
BSONObjBuilder* result) {
std::string payload;
BSONType type = EOO;
Status status = saslExtractPayload(cmdObj, &payload, &type);
if (!status.isOK())
return status;
std::string responsePayload;
// Passing in a payload and extracting a responsePayload
status = session->step(payload, &responsePayload);
if (!status.isOK()) {
const SockAddr clientAddr = client->port()->localAddr();
log() << session->getMechanism() << " authentication failed for " <<
session->getPrincipalId() << " on " <<
session->getAuthenticationDatabase() << " from client " << clientAddr.getAddr() <<
" ; " << status.toString() << std::endl;
// All the client needs to know is that authentication has failed.
return Status(ErrorCodes::AuthenticationFailed, "Authentication failed.");
}
status = buildResponse(session, responsePayload, type, result);
if (!status.isOK())
return status;
if (session->isDone()) {
UserName userName(session->getPrincipalId(), session->getAuthenticationDatabase());
status = session->getAuthorizationSession()->addAndAuthorizeUser(
session->getOpCtxt(), userName);
if (!status.isOK()) {
return status;
}
if (!serverGlobalParams.quiet) {
log() << "Successfully authenticated as principal " << session->getPrincipalId()
<< " on " << session->getAuthenticationDatabase();
}
}
return Status::OK();
}
示例2: open
bool UdpConnector::open(const SockAddr& sockaddr, boost::shared_ptr<Handler>* spout, ErrorCode* ec)
{
if (!sp_creator_stg_.get())
RETURN_ERROR_WITH(ec, E_NET_CREATE_NEW_HANDLER_FAILED, "addr=" << sockaddr, false);
struct sockaddr_in address;
bzero(&address,sizeof(address));
address.sin_family=AF_INET;
address.sin_addr.s_addr=inet_addr(sockaddr.getAddr().data());
unsigned short port = sockaddr.getPort();
address.sin_port=htons(port);
int fd = ::socket(sockaddr.getType(), SOCK_DGRAM, 0);
if (-1 == fd)
RETURN_NET_ERROR_WITH(ec, errno, "addr=" << sockaddr, false);
ScopedFD spfd(fd);
SocketHelper::setNonBlocking(fd, ec);
SocketHelper::setReusable(fd, ec);
boost::shared_ptr<Handler> spnewhandler;
sp_creator_stg_->create(fd, sockaddr, sp_reactor_impl_, spnewhandler);
if (!spnewhandler)
RETURN_ERROR_WITH(ec, E_NET_CREATE_NEW_HANDLER_FAILED, "addr=" << sockaddr, false);
HandlerScoper<Handler> handler_scoper(spnewhandler);
spfd.release();
if (sp_filter_stg_.get())
spnewhandler->setFilter(auto_ptr<Filter>(sp_filter_stg_->create(true, spnewhandler.get())));
if (!sp_reactor_impl_->registerHandler(spnewhandler, MASK_CONNECT|MASK_READ|MASK_WRITE, ec))
RETURN_IF_ERROR_WITH(ec, false);
handler_scoper.release();
if (spout)
*spout = spnewhandler;
return true;
}
示例3: HostAndPort
MessagingPort::MessagingPort(std::shared_ptr<Socket> sock)
: _x509SubjectName(), _connectionId(), _tag(), _psock(std::move(sock)) {
SockAddr sa = _psock->remoteAddr();
_remoteParsed = HostAndPort(sa.getAddr(), sa.getPort());
}