Ejemplo n.º 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());
				}
			}
		}
	}
}
Ejemplo n.º 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);
	}
}
Ejemplo n.º 3
0
bool IRCConnection::read_connection_data(uicore::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;
		else 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;
				queues.push_received(read_line);

				uicore::RunLoop::main_thread_async(uicore::bind_member(this, &IRCConnection::process));

				read_line.clear();
			}
		}
		read_line.append(buffer + start_pos, data_read - start_pos);
	}
}
Ejemplo n.º 4
0
void IRCSession::extract_ctcp_command(const IRCText &ctcp_data, IRCRawString &command, IRCRawString &data)
{
	command = ctcp_data.to_raw();
	data = ctcp_data.to_raw();
	IRCRawString::size_type pos = command.find(" ");
	if (pos != IRCRawString::npos)
	{
		command = command.substr(0, pos);
		data = data.substr(pos+1);
	}
	else
	{
		data.clear();
	}
}
Ejemplo n.º 5
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;
}