RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
#include <socket_per_thread.h>
Classes | |
struct | Entry |
Public Member Functions | |
SocketPerThread () | |
SocketPerThread (zmq::context_t &context, int type, const std::string &uri, bool allowForceClose=true) | |
void | init (zmq::context_t &context, int type, const std::string &uri, bool allowForceClose=true) |
void | shutdown () |
zmq::socket_t & | operator() () const |
void | initForThisThread () const |
void | cleanupThisThread () |
Static Public Member Functions | |
static void | cleanupAllForThread () |
Public Attributes | |
zmq::context_t * | context |
Owning zeromq context. | |
int | type |
Type to create. | |
std::string | uri |
URI to connect to. | |
bool | allowForceClose |
Cleanup open sockets on destruction? | |
int | numOpen |
Num of open connections to detect misuse. |
A simple structure that creates on-demand a different zeromq socket per thread that will connect to a given endpoint. Using this you can make sure that you don't share sockets amongst multiple threads.
Note that if you use this from the same thread that will be shutting down the zeromq context, then you need to call cleanupAllForThread() before you try to terminate zeromq, otherwise it will hang on shutdown.
Definition at line 38 of file socket_per_thread.h.
Default constructor. You must call init() before accessing it.
Definition at line 31 of file socket_per_thread.cc.
Datacratic::SocketPerThread::SocketPerThread | ( | zmq::context_t & | context, |
int | type, | ||
const std::string & | uri, | ||
bool | allowForceClose = true |
||
) |
Constructor to create a socket of the given type within the given context that will connect to the given URI on demand.
Definition at line 38 of file socket_per_thread.cc.
void Datacratic::SocketPerThread::cleanupAllForThread | ( | ) | [static] |
Prematurely pretend that this thread has exited for all of the SocketPerThread instances that are open. Commonly called just before shutdown in the main thread.
Definition at line 172 of file socket_per_thread.cc.
Prematurely pretend that this thread has exited for this socket.
Definition at line 164 of file socket_per_thread.cc.
void Datacratic::SocketPerThread::init | ( | zmq::context_t & | context, |
int | type, | ||
const std::string & | uri, | ||
bool | allowForceClose = true |
||
) |
Initialize to create a socket of the given type within the given context that will connect to the given URI on demand.
Definition at line 57 of file socket_per_thread.cc.
void Datacratic::SocketPerThread::initForThisThread | ( | ) | const |
Initialize the socket for this thread.
Definition at line 103 of file socket_per_thread.cc.
zmq::socket_t& Datacratic::SocketPerThread::operator() | ( | ) | const [inline] |
Return (creating if necessary) the socket for this thread.
Definition at line 68 of file socket_per_thread.h.