| Class | ZMQ::Context |
| In: |
lib/ffi-rzmq/context.rb
|
| Parent: | Object |
Recommended to use the default for io_threads since most programs will not saturate I/O.
The rule of thumb is to make io_threads equal to the number gigabits per second that the application will produce.
The io_threads number specifies the size of the thread pool allocated by 0mq for processing incoming/outgoing messages.
Returns a context object when allocation succeeds. It‘s necessary for passing to the Socket constructor when allocating new sockets. All sockets live within a context.
Also, Sockets should only be accessed from the thread where they were first created. Do not pass sockets between threads; pass in the context and allocate a new socket per thread. If you must use threads, then make sure to execute a full memory barrier (e.g. mutex) as you pass a socket from one thread to the next.
To connect sockets between contexts, use inproc or ipc transport and set up a 0mq socket between them. This is also the recommended technique for allowing sockets to communicate between threads.
context = ZMQ::Context.create
if context
socket = context.socket(ZMQ::REQ)
if socket
...
else
STDERR.puts "Socket allocation failed"
end
else
STDERR.puts "Context allocation failed"
end
| context | -> | pointer |
| context | [R] | |
| io_threads | [R] | |
| max_sockets | [R] |