void redis_connection::tcp_client_disconnection_handler() { __CPP_REDIS_LOG(debug, "cpp_redis::network::redis_connection has been disconnected"); /** * clear buffer */ m_buffer.clear(); /** * clear builder */ m_builder.reset(); /** * call disconnection handler */ call_disconnection_handler(); }
void tcp_client::on_write_available(fd_t) { __TACOPIE_LOG(info, "write available"); write_result result; auto callback = process_write(result); if (!result.success) { __TACOPIE_LOG(warn, "write operation failure"); disconnect(); } if (callback) { callback(result); } if (!result.success) { call_disconnection_handler(); } }
void redis_connection::tcp_client_receive_handler(const tcp_client_iface::read_result &result) { if (!result.success) { return; } try { __CPP_REDIS_LOG(debug, "cpp_redis::network::redis_connection receives packet, attempts to build reply"); m_builder << std::string(result.buffer.begin(), result.buffer.end()); } catch (const redis_error &) { __CPP_REDIS_LOG(error, "cpp_redis::network::redis_connection could not build reply (invalid format), disconnecting"); call_disconnection_handler(); return; } while (m_builder.reply_available()) { __CPP_REDIS_LOG(debug, "cpp_redis::network::redis_connection reply fully built"); auto reply = m_builder.get_front(); m_builder.pop_front(); if (m_reply_callback) { __CPP_REDIS_LOG(debug, "cpp_redis::network::redis_connection executes reply callback"); m_reply_callback(*this, reply); } } try { tcp_client_iface::read_request request = {__CPP_REDIS_READ_SIZE, std::bind(&redis_connection::tcp_client_receive_handler, this, std::placeholders::_1)}; m_client->async_read(request); } catch (const std::exception &) { /** * Client disconnected in the meantime */ } }