X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=kvstore%2Fsocket_pool.h;fp=kvstore%2Fsocket_pool.h;h=57faf42af4a42570e81900ad44ed021f7c90a8bb;hb=d9c7ab29f5651da244cac393f446a6c5e823fcd1;hp=0000000000000000000000000000000000000000;hpb=3c2cbef21a11c4d86952922f4da7b830a91423f9;p=bluesky.git diff --git a/kvstore/socket_pool.h b/kvstore/socket_pool.h new file mode 100644 index 0000000..57faf42 --- /dev/null +++ b/kvstore/socket_pool.h @@ -0,0 +1,52 @@ +#ifndef _SOCKET_POOL_H_ +#define _SOCKET_POOL_H_ 1 + +#include +#include +#include +#include +#include + +#include "util.h" + +using namespace std; +using namespace boost; + + +class SocketPool +{ +public: + SocketPool(int max_streams, + asio::io_service &io_svc); + void setEndpoint(const tcp::endpoint &endpoint); + void cancelAndClear(); + shared_ptr getSocket(); + void putSocket(shared_ptr socket); +private: + int _issued; + int _max_sockets; + mutex _sockets_lock; + condition_variable _sockets_non_empty; + asio::io_service &_io_service; + tcp::endpoint _endpoint; + queue > _queue; + set > _set; +}; + +class SocketCheckout +{ +public: + SocketCheckout(SocketPool *pool); + ~SocketCheckout(); + + tcp::socket& operator*(); + tcp::socket* operator->(); + + shared_ptr& socket(); + +private: + shared_ptr _socket; + SocketPool *_pool; +}; + +#endif