[zeromq-dev] Can I make sure that contexts are freed and handles released in a fast loop?
Kuba
kubaraczkowski at gmail.com
Thu Feb 23 07:27:00 CET 2012
Hi,
First of all, thanks for the zmq. It looks like a nice "user-friendly"
system; the point I started using it in the first place.
My question is about creating a custom function that would create a
context, exchange small piece of data, destroy the context, do it all over
again.
I am currently experiencing the problem of using all available file
handles, therefore this email.
Let me give some context.
I am trying to create a client-server application that could be used from
within MATLAB.
Matlab user would only communicate with the client, which would take a
string and quickly send it to the server.
The server is a standalone application, which purpose is to open a link to
a hardware device and wait for messages to be written to it (via zmq).
As you can guess, the whole point is that opening the link to the hardware
device is slow, so once it's done we want to keep the link open.
Moreover, Matlab will generate data in small packets, therefore the client
connection should be created fast and destroyed fast.
The problem is that I don't want the client library to be "persistent".
It should work more as a separate app, which is launched, process data, and
exits.
The user should be able to clear the whole matlab session, without
experiencing problems due to clearing the (open) client app.
In fact, this client application can be approximated by a function that is
launched in a loop of a master program.
The function creates a context and a socket, connects to the server, sends
a message, receives a message, closes the socket, terminates the context
.... and starts over again.
This works very well and very fast, though the actual socket handles (or
file handles) never get released, which causes the program to crash after
some (thousands) iterations.
I know that your answer to this problem will probably be: "keep the context
and the socket open as long as possible", but not doing that is exactly the
point of my client.
Therefore, the question: is it possible to make sure, within a program,
that all contexts/sockets/files/handles are properly closed, so that they
can safely be relaunched ?
This all is on Windows, I tried zmq v2.1 and 3.1, C, C++, java,
visual-studio and gcc (mingw) compilers (well I thought at first it's some
weird matlab problem, that's why I tried all these flavors).
Thank you for your suggestions,
Kuba
p.s. what does work very well (of course) is launching a real external
application from matlab (system("client")). This, however, is about 3-4x
slower than making a mex (dll) library to be used within matlab.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120223/77c619b5/attachment.htm>
More information about the zeromq-dev
mailing list