From 7fc9094d8ea1c2d28d003c499016f0755b73063d Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 3 Nov 2017 22:40:26 -0400 Subject: More fixes to RethinkDB. --- ext/librethinkdbxx/src/connection.cc | 5 ++++- ext/librethinkdbxx/src/cursor.cc | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'ext') diff --git a/ext/librethinkdbxx/src/connection.cc b/ext/librethinkdbxx/src/connection.cc index 62f6efee..53d106ec 100644 --- a/ext/librethinkdbxx/src/connection.cc +++ b/ext/librethinkdbxx/src/connection.cc @@ -101,6 +101,8 @@ std::unique_ptr connect(std::string host, int port, std::string auth Connection::Connection(ConnectionPrivate *dd) : d(dd) { } Connection::~Connection() { // close(); + if (d->guarded_sockfd >= 0) + ::close(d->guarded_sockfd); } size_t ReadLock::recv_some(char* buf, size_t size, double wait) { @@ -128,7 +130,7 @@ size_t ReadLock::recv_some(char* buf, size_t size, double wait) { } ssize_t numbytes = ::recv(conn->guarded_sockfd, buf, size, 0); - if (numbytes == -1) throw Error::from_errno("recv"); + if (numbytes <= 0) throw Error::from_errno("recv"); if (debug_net > 1) { fprintf(stderr, "<< %s\n", write_datum(std::string(buf, numbytes)).c_str()); } @@ -190,6 +192,7 @@ void Connection::close() { if (ret == -1) { throw Error::from_errno("close"); } + d->guarded_sockfd = -1; } Response ConnectionPrivate::wait_for_response(uint64_t token_want, double wait) { diff --git a/ext/librethinkdbxx/src/cursor.cc b/ext/librethinkdbxx/src/cursor.cc index 987c4dba..df0621eb 100644 --- a/ext/librethinkdbxx/src/cursor.cc +++ b/ext/librethinkdbxx/src/cursor.cc @@ -21,9 +21,11 @@ CursorPrivate::CursorPrivate(uint64_t token_, Connection *conn_, Datum&& datum) Cursor::Cursor(CursorPrivate *dd) : d(dd) {} Cursor::~Cursor() { - if (d && d->conn) { - close(); - } + try { + if (d && d->conn) { + close(); + } + } catch ( ... ) {} } Datum& Cursor::next(double wait) const { -- cgit v1.2.3