-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request-reply (Client-Server) support #219
Conversation
4ce5de4
to
d3a4f84
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only first commit reviewed
zeroeq/detail/context.h
Outdated
using ContextPtr = std::shared_ptr<void>; | ||
|
||
/** @return the current ZeroMQ context. Users need to hold onto this context to | ||
* extend its lifetime to all sockets created from the context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This documentation is not precise. The context is created if it doesn't exist.
This function is a bit strange for such a simple name as getContext.
Why storing a weak reference to the context internally? It seems as if you wanted to guarantee that all sockets will share the same context implicitly as long there's one object holding a context and remove the context once the last object using it is destroyed. If that's the intention it should be documented somewhere. I would rename it to getOrCreateSharedContext()
c6b2358
to
2333a50
Compare
tests/reqRep.cpp
Outdated
BOOST_CHECK(handled); | ||
} | ||
|
||
#if 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a better way to skip tests that are not ready with Boost.UnitTest? At least In Python there's a decorator to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's gone now.
tests/reqRep.cpp
Outdated
std::thread thread([&] { runOnce(server, echo); }); | ||
|
||
bool handled = false; | ||
client.get(echo.getTypeIdentifier(), [&](const void* data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any difference between using echo.getTypeIndenitifier() and test::Echo::IDENTIFIER?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first can be called from the object without knowing it's type, and the second one is static and can be called without an instance (but needs the type)
tests/reqRep.cpp
Outdated
zeroeq::Server noServer(client.getSession()); | ||
zeroeq::detail::Sender::getUUID() = | ||
servus::make_UUID(); // different machine | ||
zeroeq::Server server(client.getSession()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this a little better. Rename noServer to notConnected or unreachable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's gone. I started with a c&p from the pubsub tests
tests/reqRep.cpp
Outdated
std::thread thread([&] { runOnce(server, echo); }); | ||
|
||
bool handled = false; | ||
client.get(echo.getTypeIdentifier(), [&](const void* data, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something that was not clearly specified in the feature request. Client get/set methods were mentioned, but only in a example, and the example doesn't match this test. What's the value of this get method over Client::request, because I don't see many differences.
tests/reqRep.cpp
Outdated
received = true; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. Isn't this for request/reply tests? Why Client has a method called publish? Why servers has a subscribe method? This doesn't resemble the feature spec at all.
I think I see. You just copied the test from pubSub and "commented" this part. If the partial commits don't make sense it's a waste of time to look into them, but looking at the full pull request at once is really hard because of its size. What should I expect from the rest of the commits and what can I expect to be less time consuming? I was already feeling this PR was going to be hard to review and this commit hasn't improved that feeling.
31f92ed
to
fa62b74
Compare
zeroeq/client.h
Outdated
* once the servers are available. | ||
* | ||
* A receive on any instance of a shared group will work on all instance | ||
* and call the registered handlers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rephrase this sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
zeroeq/client.h
Outdated
size_t size, ReplyFunc& func); | ||
|
||
/** @return the session name that is used for filtering. */ | ||
ZEROEQ_API const std::string& getSession() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this method be in Receiver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Monitor is a session-less receiver.
zeroeq/client.h
Outdated
ReplyFunc& func); | ||
|
||
/** | ||
* Request the execution of the given data on a connected Server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Request the execution of data", that's a funny sentence
* Request the execution of the given data on a connected Server. | ||
* | ||
* The reply function will be executed during receive(). May block of when | ||
* all servers are overloaded or no server is connected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
block of, remove of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* Request the execution of the given data on a connected Server. | ||
* | ||
* The reply function will be executed during receive(). May block of when | ||
* all servers are overloaded or no server is connected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it true that this function may block (and same for the other overload)? Isn't receive the function that blocks?
If this function can block, then it should accept a timeout parameter or at least there should be a way to interrupt it.
How does zeromq work with REQ/REP sockets anyway? To me it seems a bit odd to make requests to an inexistent resource. I'm also missing a way to know that the client is connected to any server without having to use application level messages for that. It's also not clear to me whether a user may want to have a client which is not connected to anything after the constructors return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's true since the request sending will block. Receive() will block on at least one reception of a reply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a timeout on an as-needed basis. One needs to use ZMQ_DONTWAIT and spin, afaik. In reality I expect this to be a non-issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One can connect to a zeroconf session which will dynamically update the servers as they are available. The Monitor can be used to get notifications.
f41d03d
to
8ea075a
Compare
Retest this please. |
1 similar comment
Retest this please. |
Retest this please. |
ping? |
No description provided.