Example #1
0
void IRCConnection::process()
{
	while (true)
	{
		std::unique_lock<std::mutex> lock(mutex);

		IRCRawString line = queues.pop_received();
		if (line.empty())
			break;

		lock.unlock();

		IRCMessage message = IRCMessage::parse_line(line);

		// * This is broken - We do not know if the IRC server resets the ping interval when it either recieves or sends any command successfully *
		//if (message.get_type() == IRCMessage::type_ping)
		//	calculate_ping_interval();

		if (cb_message_received)
			cb_message_received(message);
	}

	std::unique_lock<std::mutex> lock(mutex);
	std::string reason;
	bool was_disconnected = queues.pop_disconnected(reason);
	lock.unlock();

	if (was_disconnected && cb_disconnected)
	{
		ping_timeout_timer->stop();
		cb_disconnected(reason);
	}
}
Example #2
0
void IRCConnection::send_join(const IRCChannel &channel, const IRCRawString &password)
{
	std::vector<IRCRawString> params;
	params.push_back(channel.to_raw());
	if (!password.empty())
		params.push_back(password);
	send_command("JOIN", params);
}
Example #3
0
void IRCConnection::send_pong(const IRCRawString &daemon1, const IRCRawString &daemon2)
{
	std::vector<IRCRawString> params;
	params.push_back(daemon1);
	if (!daemon2.empty())
		params.push_back(daemon2);
	send_command("PONG", params);
}
Example #4
0
void IRCConnection::process()
{
	while (true)
	{
		IRCRawString line = queues.pop_received();
		if (line.empty())
			break;

		IRCMessage message = IRCMessage::parse_line(line);
		if (cb_message_received)
			cb_message_received(message);
	}

	std::string reason;
	bool was_disconnected = queues.pop_disconnected(reason);
	if (was_disconnected && cb_disconnected)
		cb_disconnected(reason);
}
Example #5
0
void IRCConnection::write_connection_data(IRCRawString &write_line, IRCRawString::size_type &write_pos, uicore::TCPConnection &connection)
{
	while (true)
	{
		if (write_line.length() != write_pos)
		{
			int result = connection.write(write_line.data() + write_pos, (int)(write_line.length() - write_pos));
			if (result == -1)
				break;
			write_pos += result;
		}
		else
		{
			write_line = queues.pop_send();
			write_pos = 0;

			if (write_line.empty())
				break;
		}
	}
}