Пример #1
0
bool DCCChatConnection::write_connection_data(IRCRawString &write_line, IRCRawString::size_type &write_pos, clan::TCPConnection &connection)
{
	while (true)
	{
		if (write_line.length() != write_pos)
		{
			int bytes_written = connection.write(write_line.data() + write_pos, write_line.length() - write_pos);
			if (bytes_written == -1)
				return true;
			write_pos += bytes_written;
		}
		else
		{
			write_line.clear();
			write_pos = 0;
			if (!send_queue.empty())
			{
				if (send_queue.front().type == Message::type_disconnect)
				{
					send_queue.erase(send_queue.begin());
					return false;
				}
				else
				{
					write_line = send_queue.front().text + "\r\n";
					send_queue.erase(send_queue.begin());
				}
			}
		}
	}
}
Пример #2
0
bool DCCChatConnection::read_connection_data(clan::TCPConnection &connection, IRCRawString &read_line)
{
	while (true)
	{
		char buffer[16 * 1024];
		int data_read = connection.read(buffer, 16 * 1024);
		if (data_read == -1)
			return true;
		if (data_read == 0) // EOF from server
			return false;

		int start_pos = 0;
		for (int i = 0; i<data_read; i++)
		{
			if (buffer[i] == '\n')
			{
				read_line.append(buffer + start_pos, i - start_pos + 1);
				start_pos = i + 1;
				queue_line(read_line);
				read_line.clear();
			}
		}
		read_line.append(buffer + start_pos, data_read - start_pos);
	}
}
Пример #3
0
bool IRCConnection::write_connection_data(IRCRawString &write_line, IRCRawString::size_type &write_pos, clan::TCPConnection &connection)
{
	if (write_line.length() != write_pos)
	{
		//int old_pos = write_pos;
		write_pos += connection.write(write_line.data()+write_pos, write_line.length()-write_pos);
		//clan::Console::write_line(std::string8(write_line.data()+old_pos, write_pos-old_pos, false));
	}
	else
	{
		write_line = queues.pop_send();
		write_pos = 0;
	}
	return true;
}
Пример #4
0
bool IRCConnection::read_connection_data(clan::TCPConnection &connection, IRCRawString &read_line)
{
	char buffer[16*1024];
	int data_read = connection.read(buffer, 16*1024, false);
	if (data_read == 0) // EOF from server
	{
		connection.disconnect_graceful();
		return false;
	}
	int start_pos = 0;
	for (int i=0; i<data_read; i++)
	{
		if (buffer[i] == '\n')
		{
			read_line.append(buffer+start_pos, i-start_pos+1);
			start_pos = i+1;
			queues.push_received(read_line);
			set_wakeup_event();
			read_line.clear();
		}
	}
	read_line.append(buffer+start_pos, data_read-start_pos);
	return true;
}