Background: I have many small c++ programs that all use the same static library. I'm now implementing thrift as a middle layer so that I can run the small c++ programs on a different computer from the static library. I can't change the c++ programs, so I am making a "fake" static library that looks like the original, but is actually a thrift client that calls the real static library.
Issue: How can I make the static library so that the c++ programs will automatically open the socket when it opens the library, and closes the socket when the program exits??
Usually thrift clients use a main method that opens the socket in the beginning and closes it in the end. I can have the library check if the socket is open before every method call, but I don't know how to close the socket. Is there any problem with leaving it open?