本文整理汇总了C++中socket::receive方法的典型用法代码示例。如果您正苦于以下问题:C++ socket::receive方法的具体用法?C++ socket::receive怎么用?C++ socket::receive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socket
的用法示例。
在下文中一共展示了socket::receive方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
void Packet::read(socket& socket) {
std::uint32_t bytes_read = 0;
if (ext_len > 0) {
std::vector<char> extras(ext_len);
while (bytes_read < static_cast<std::uint32_t>(ext_len)) {
bytes_read += socket.receive(boost::asio::buffer(extras));
}
bytes_read = 0;
if (extras.size() > 4) {
char flags_buf[4] = { extras[0], extras[1], extras[2], extras[3] };
flags = readUInt32LE(flags_buf, 0);
}
}
if (key_len > 0) {
key.resize(key_len);
while (bytes_read < key_len) {
bytes_read += socket.receive(boost::asio::buffer(key));
}
bytes_read = 0;
}
if (bod_len > key_len) {
std::uint32_t val_len = bod_len - key_len - ext_len;
val.resize(val_len);
while (bytes_read < val_len) {
bytes_read += socket.receive(boost::asio::buffer(val));
}
}
}
示例2: forward
// TODO: use non-copying private zmq implementation of forward.
// Call from work to forward a message from one socket to another.
bool worker::forward(socket& from, socket& to)
{
message packet;
return !from.receive(packet) && !to.send(packet);
}
示例3: handle_command
void auth::handle_command(socket& pipe) {
// Get the whole message off the pipe in one go
message msg;
pipe.receive(msg);
if(0 == msg.parts())
return; // Interrupted
// authentication command
std::string command = msg.get(0);
if (verbose) {
std::cout <<"auth: API command=" << command << std::endl;
}
if("ALLOW" == command) {
std::string address = msg.get(1);
if(verbose) {
std::cout << "auth: whitelisting ipaddress=" << address << std::endl;
}
whitelist.insert(address);
pipe.send(signal::ok);
} else if("DENY" == command) {
std::string address = msg.get(1);
if(verbose) {
std::cout << "auth: blacklisting ipaddress=" << address << std::endl;
}
blacklist.insert(address);
pipe.send(signal::ok);
} else if("DOMAIN" == command) {
std::string domain = msg.get(1);
if(verbose) {
std::cout << "auth: domain=" << domain << std::endl;
}
this->domain = domain;
pipe.send(signal::ok);
} else if("PLAIN" == command) {
std::string user = msg.get(1);
std::string pass = msg.get(2);
if (verbose) {
std::cout << "auth: configured PLAIN - user:" << user << std::endl;
}
passwords.insert(std::make_pair(user, pass));
pipe.send(signal::ok);
} else if("CURVE" == command) {
// If client_public_key is CURVE_ALLOW_ANY, allow all clients. Otherwise
// treat client_public_key as client public key certificate.
std::string client_public_key = msg.get(1);
if("CURVE_ALLOW_ANY" == client_public_key) {
curve_allow_any = true;
if(verbose) {
std::cout << "auth: configured CURVE - allow ALL clients" << std::endl;
}
} else {
curve_allow_any = false;
client_keys.insert(client_public_key);
if(verbose) {
std::cout << "auth: configured CURVE - allow client with public key:" << client_public_key << std::endl;
}
}
pipe.send(signal::ok);
} else if("GSSAPI" == command) {
// GSSAPI authentication is not yet implemented here
if(verbose) {
std::cout << "auth: configure GSSAPI authentication is not yet implemented here" << std::endl;
}
pipe.send(signal::ok);
} else if("VERBOSE" == command) {
std::string verbose_string = msg.get(1);
verbose = ("true" == verbose_string)? true : false;
pipe.send(signal::ok);
} else if("TERMINATE" == command) {
std::cout << "auth: Shutdown ZAP Authentication Server" << std::endl;
terminated = true;
pipe.send(signal::ok);
} else {
if(verbose) {
std::cout << "auth: Invalid command=" << command << std::endl;
}
assert(false);
}
}