Kevin Clark writes:
> Almost identical question:
> http://mail-archives.apache.org/mod_mbox/incubator-thrift-user/200905.mbox/browser
>
> The "game network protocol" thread in march and april:
> http://mail-archives.apache.org/mod_mbox/incubator-thrift-user/200904.mbox/browser
> http://mail-archives.apache.org/mod_mbox/incubator-thrift-user/200903.mbox/browser
>
> I've been hearing about this use case a lot lately. We may want to
> consider providing support for it in the core lib . I'd personally be
> happy to see patches towards that once people have an idea of how they
> think it should work.
We do this now by just passing marshalled structures back and forth
across the wire; it gives us asynchronous send/reply in both
directions. Somewhat simplified, the code looks like the below, it's not
clear exactly what we would include in a patch to thrift since it's built
outside and interacts with the event loop tha twe have.
-Eric
uint32_t Message::write(facebook::thrift::protocol::TProtocol &oprot) const {
uint32_t bytes = 0;
bytes += oprot.writeMessageBegin(getType(),
facebook::thrift::protocol::T_CALL,
getSeqno());
bytes += data->write(&oprot);
bytes += oprot.writeMessageEnd();
return bytes;
}
MessageData *
MessageData::deMarshal(const std::string &from_name,
facebook::thrift::protocol::TProtocol &from,
int32_t &seqno, int64_t &path) {
MessageData *ret = NULL;
try {
string name;
facebook::thrift::protocol::TMessageType mtype;
from.readMessageBegin(name, mtype, seqno);
SINVARIANT(mtype == facebook::thrift::protocol::T_CALL);
MessageData::Reader *reader = getMap().lookup(name);
INVARIANT(reader != NULL, format("can not find reader for %s from %s")
% name % from_name);
ret = (*reader)(&from);
from.readMessageEnd();
} catch (...) {
...;
}
return ret;
}
void mainloop() {
while(true) {
(far_side, protocol) = getReadyFd();
uint32_t seqno = 0;
int64_t path = 0;
data = MessageData::deMarshal(far_side->getName(),
*binary_protocol, seqno, path);
Message::Ptr msg = Message::make(EventQueue::EQ().getMe(), data,
seqno, path);
EventQueue::recvMessage(msg);
}
}