c++ - Does boost::shared_ptr<TTransport> close connection once destroyed? -


i have small code snippet uses thrift network communications.

int main() {   while (true) {     boost::shared_ptr<ttransport> socket(new tsocket("localhost", 9090));     boost::shared_ptr<ttransport> transport(new tbufferedtransport(socket));     boost::shared_ptr<tprotocol> protocol(new tbinaryprotocol(transport));      calculatorclient client(protocol);      try {       transport->open();        client.ping();       cout << "ping()" << endl;        // following line commented out intentionally       //transport->close();     } catch (texception& tx) {       cout << "error: " << tx.what() << endl;     }   } } 

my question is: boost::shared_ptr close connection once destroyed? if yes, transport->close(); can commented out without problems, right?

looking @ the source, don't see ttransport doing in destructor. however, destructor of tsocket (src), call it's close() function.

since shared_ptr created in scope of main function , no 1 else has asked pointer object in care of shared_ptr, 'socket' destruct after goes out of scope.

tbufferedtransport not appear explictly declare destructor, however, own tsocket, got out of scope when tbufferedtransport destructs, tsocket's destructor gets called.

tbufferedtransport::[rbuf_/wbuf_] scoped_arrays don't think need worry either.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -