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()); } } } } }
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; }
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; } } }
void DCCChatConnection::process() { std::vector<Message> received_messages; std::unique_lock<std::mutex> lock(mutex); received_messages.swap(receive_queue); lock.unlock(); for (size_t i = 0; i < received_messages.size(); i++) { switch (received_messages[i].type) { case Message::type_system: sig_system_text(received_messages[i].text); break; case Message::type_text: { IRCRawString text = received_messages[i].text; if (text.length() >= 2 && text.substr(text.length() - 2, 2) == "\r\n") text = text.substr(0, text.length() - 2); else if (text.length() >= 1 && text[text.length() - 1] == '\n') text = text.substr(0, text.length() - 1); sig_text_line(IRCText::from_raw(text)); } break; case Message::type_disconnect: sig_disconnected(received_messages[i].text); break; } } }
void IRCSession::on_unknown_message(const IRCMessage &message) { IRCRawString s = IRCMessage::create_line(message.get_prefix().to_raw(), message.get_command(), message.get_params()); cb_system_text(IRCText::from_raw(s.substr(0, s.length()-2))); }