本文整理汇总了C++中Address::addr方法的典型用法代码示例。如果您正苦于以下问题:C++ Address::addr方法的具体用法?C++ Address::addr怎么用?C++ Address::addr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::addr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connect
static void connect(uv_tcp_t* handle, const Address& address, void* data,
Callback cb) {
Connector* connector = new Connector(address, data, cb);
int rc = 0;
#if UV_VERSION_MAJOR == 0
if (address.family() == AF_INET) {
rc = uv_tcp_connect(&connector->req_, handle, *address.addr_in(),
on_connect);
} else {
rc = uv_tcp_connect6(&connector->req_, handle, *address.addr_in6(),
on_connect);
}
#else
rc = uv_tcp_connect(&connector->req_, handle, address.addr(),
on_connect);
#endif
if (rc != 0) {
connector->status_ = -1;
connector->cb_(connector);
delete connector;
}
}
示例2: send
int UDPSocket::send(const char* data, std::size_t len,
const Address& peerAddress, int /* flags */)
{
TraceS(this) << "Send: " << len << ": " << peerAddress << endl;
assert(Thread::currentID() == tid());
// assert(len <= net::MAX_UDP_PACKET_SIZE);
if (_peer.valid() && _peer != peerAddress) {
ErrorS(this) << "Peer not authorized: " << peerAddress << endl;
return -1;
}
if (!peerAddress.valid()) {
ErrorS(this) << "Peer not valid: " << peerAddress << endl;
return -1;
}
int r;
auto sr = new internal::SendRequest;
sr->buf = uv_buf_init((char*)data, len); // TODO: memcpy data?
r = uv_udp_send(&sr->req, ptr<uv_udp_t>(), &sr->buf, 1, peerAddress.addr(),
UDPSocket::afterSend);
#if 0
switch (peerAddress.af()) {
case AF_INET:
r = uv_udp_send(&sr->req, ptr<uv_udp_t>(), &sr->buf, 1, peerAddress.addr(), UDPSocket::afterSend);
break;
case AF_INET6:
r = uv_udp_send6(&sr->req, ptr<uv_udp_t>(), &sr->buf, 1,
*reinterpret_cast<const sockaddr_in6*>(peerAddress.addr()), UDPSocket::afterSend);
break;
default:
throw std::runtime_error("Unexpected address family");
}
#endif
if (r) {
ErrorS(this) << "Send failed: " << uv_err_name(r) << endl;
setUVError("Invalid UDP socket", r);
}
// R is -1 on error, otherwise return len
return r ? r : len;
}
示例3: bind
void UDPSocket::bind(const Address& address, unsigned flags)
{
TraceS(this) << "Binding on " << address << endl;
int r;
switch (address.af()) {
case AF_INET:
r = uv_udp_bind(ptr<uv_udp_t>(), address.addr(), flags);
break;
//case AF_INET6:
// r = uv_udp_bind6(ptr<uv_udp_t>(), address.addr(), flags);
// break;
default:
throw std::runtime_error("Unexpected address family");
}
// Throw and exception of error
if (r)
setAndThrowError("Cannot bind UDP socket", r);
// Open the receiver channel
recvStart();
}
示例4: sendto
ssize_t Socket::sendto(const void *const buffer, const size_t length, const Address &dest, int flags)
{
return ::sendto(m_fd, buffer, length, 0, dest.addr(), dest.addrLength());
}
示例5: connect
bool Socket::connect(const Address &addr)
{
if(m_fd < 0) return false;
return ::connect(m_fd, addr.addr(), addr.addrLength()) == 0;
}