summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/librethinkdbxx/src/connection.cc5
-rw-r--r--ext/librethinkdbxx/src/cursor.cc8
2 files changed, 9 insertions, 4 deletions
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<Connection> 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 {