示例#1
0
// ICI l'id du client correspond a l'id du client auquel on veut envoyer les bails
void		TCPWinServSocket::SendData(CircularBuff &circbuff, Selector &sel)
{
	std::vector<Message>		&to_send = circbuff.get_data();
	DWORD						sentbytes;
	WSABUF						databuf[3];
	char						first_buff[4];
	char						second_buff[4];
	char						third_buff[256];

	databuf[0].len = 4;
	databuf[0].buf = first_buff;
	databuf[1].len = 4;
	databuf[1].buf = second_buff;
	databuf[2].len = 256;
	databuf[2].buf = third_buff;

	//pour tous les messages
	for (size_t i = 0; i < to_send.size(); i++)
	if (sel.Is_writable(to_send.at(i).get_client().get_socket()))
	{
		//reset des buffers
		memset(&first_buff, '\0', 4);
		memset(&second_buff, '\0', 4);
		memset(&third_buff, '\0', 256);

		// on crée des variables parce qu'on a besoin d'une adresse pour memcpy (donc juste des getters ca suffit pas)
		int		rq_type = to_send.at(i).get_rq_type();
		int		data_length = to_send.at(i).get_data_length();

		//on rempli nos 3 buffers
		memcpy(&first_buff, (char *)&(rq_type), 4);
		memcpy(&second_buff, (char *)&(data_length), 4);
		memcpy(&third_buff, to_send.at(i).get_packet(), data_length);

		// et on les envoi
		WSASend(to_send.at(i).get_client().get_socket(), databuf, 3, &sentbytes, 0, NULL, NULL);
		delete[]	to_send.at(i).get_packet();
	}
	else
		std::cerr << "Corruption possible (1)" << std::endl;
	to_send.clear();
}
示例#2
0
// ICI l'id du client correspond a l'id du client auquel on veut envoyer les bails
void		TCPLinServSocket::SendData(CircularBuff &circbuff, Selector &sel)
{
	std::vector<Message>		&to_send = circbuff.get_data();
	struct iovec				databuf[3];
	char						first_buff[4];
	char						second_buff[4];
	char						third_buff[256];
	int							sentbytes = 0;
		
	databuf[0].iov_len = 4;
	databuf[0].iov_base = first_buff;
	databuf[1].iov_len = 4;
	databuf[1].iov_base = second_buff;
	databuf[2].iov_len = 256;
	databuf[2].iov_base = third_buff;

	//pour tous les messages
	for (size_t i = 0; i < to_send.size(); i++)
		if (sel.Is_writable(to_send.at(i).get_client().get_socket()))
		{
			//reset des buffers
			memset(&first_buff, '\0', 4);
			memset(&second_buff, '\0', 4);
			memset(&third_buff, '\0', 256);

			// on crée des variables parce qu'on a besoin d'une
			//adresse pour memcpy (donc juste des getters ca suffit pas)
			int		rq_type = to_send.at(i).get_rq_type();
			int		data_length = to_send.at(i).get_data_length();

			//on rempli nos 3 buffers
			memcpy(&first_buff, (char *)&(rq_type), 4);
			memcpy(&second_buff, (char *)&(data_length), 4);
			memcpy(&third_buff, to_send.at(i).get_packet(), data_length);

			// et on les envoi
			sentbytes = writev(to_send.at(i).get_client().get_socket(), databuf, 3);
			delete[]	to_send.at(i).get_packet();
		}
	to_send.clear();
}