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


C++ socket::receive方法代码示例

本文整理汇总了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));
    }
  }
}
开发者ID:nickdesaulniers,项目名称:cpp11-memcached,代码行数:32,代码来源:packet.cpp

示例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);
}
开发者ID:evoskuil,项目名称:libbitcoin-protocol,代码行数:7,代码来源:worker.cpp

示例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);
    }
}
开发者ID:jbreams,项目名称:mqexec-tng,代码行数:97,代码来源:auth.cpp


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