diff --git a/src/flora-agent.cc b/src/flora-agent.cc index af18ea1..368a0c5 100644 --- a/src/flora-agent.cc +++ b/src/flora-agent.cc @@ -115,27 +115,9 @@ void Agent::start(bool block) { } } -static void clean_gabages(list >& gabages) { - auto it = gabages.begin(); - while (it != gabages.end()) { - auto cli = *it; - if (cli) { - static_pointer_cast(cli)->close(false); - if (cli.use_count() == 1) { - cli.reset(); - it = gabages.erase(it); - } else - ++it; - } else { - ++it; - } - } -} - void Agent::run() { unique_lock locker(conn_mutex, defer_lock); - shared_ptr cli; - list > gabages; + shared_ptr cli, gabage; flora::ClientOptions cliopts; cliopts.bufsize = options.bufsize; @@ -156,14 +138,13 @@ void Agent::run() { KLOGI(TAG, "flora service %s connected", options.uri.c_str()); init_cli(cli); locker.lock(); - gabages.push_back(cli); flora_cli.swap(cli); start_cond.notify_one(); conn_cond.wait(locker); - flora_cli.reset(); + gabage.swap(flora_cli); } locker.unlock(); - clean_gabages(gabages); + gabage.reset(); } } diff --git a/src/sock-conn.cc b/src/sock-conn.cc index 6060dce..8089a04 100644 --- a/src/sock-conn.cc +++ b/src/sock-conn.cc @@ -104,9 +104,8 @@ bool SocketConn::connect(const std::string &host, int32_t port) { bool SocketConn::send(const void *data, uint32_t size) { lock_guard locker(write_mutex); - if (!sock_ready) { + if (!sock_ready) return false; - } ssize_t c = ::write(sock, data, size); if (c < 0) { KLOGE(TAG, "write to socket failed: %s", strerror(errno));