本文整理汇总了C++中OutputBuffer::writeTerm方法的典型用法代码示例。如果您正苦于以下问题:C++ OutputBuffer::writeTerm方法的具体用法?C++ OutputBuffer::writeTerm怎么用?C++ OutputBuffer::writeTerm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputBuffer
的用法示例。
在下文中一共展示了OutputBuffer::writeTerm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_accept
bool test_accept(LocalNode &node)
throw (EpiException)
{
node.publishPort();
std::auto_ptr<Connection> connection(node.accept());
std::auto_ptr<MailBox> mailbox(node.createMailBox(connection.get()));
connection->start();
std::auto_ptr<ErlangMessage> msg;
ErlTerm* received_term;
OutputBuffer *buffer = mailbox->newOutputBuffer();
bool loop = true;
while (loop) {
msg.reset(mailbox->receiveMsg());
if (!(msg->messageType() == ERL_MSG_SEND ||
msg->messageType() == ERL_MSG_REG_SEND)) {
std::cout << "Message is not SEND type\n";
return false;
}
received_term = msg->getMsg();
if (msg->messageType() == ERL_MSG_REG_SEND) {
std::cout << "Received to " << ((RegSendMessage *) msg.get())->getRecipientName() <<
": " << received_term->toString() << "\n";
} else {
std::cout << "Received to " << ((SendMessage *) msg.get())->getRecipientPid()->toString() <<
": " << received_term->toString() << "\n";
}
if (received_term->instanceOf(ERL_TUPLE)) {
ErlTuple *tuple = (ErlTuple *) received_term;
if (tuple->arity() == 2) {
ErlTerm* term1 = tuple->elementAt(0);
ErlTerm* term2 = tuple->elementAt(1);
if (term1->instanceOf(ERL_PID)) {
std::cout << "Sending " << term2->toString() <<
" to " << term1->toString() << "\n";
buffer->reset();
buffer->writeTerm(term2);
mailbox->sendBuf((ErlPid *) term1, buffer);
std::cout << "Sent.\n";
}
}
}
if (received_term->instanceOf(ERL_ATOM)) {
if (((ErlAtom *) received_term)->atomValue() == "exit") {
loop = false;
}
}
}
return true;
}
示例2: send_reply_server
// Test send and receive with a reply server.
bool send_reply_server(ErlTerm *t, MailBox *mailbox)
throw(EpiException)
{
std::cout << "Sending term: " << t->toString() << "\n";
OutputBuffer *buffer = mailbox->newOutputBuffer();
// Create tuple with pid
ErlPid *pid = mailbox->self();
ErlTermPtr<ErlTuple> tuple(new ErlTuple(pid, t));
buffer->writeTerm(tuple.get());
mailbox->sendBuf("reply_server", buffer);
std::cout << "Sent. Receiving response:\n";
std::auto_ptr<EpiMessage> msg(mailbox->receiveMsg());
if (msg->messageType() != ERL_MSG_SEND) {
std::cout << "Message is not SEND type\n";
return false;
}
ErlTerm* t2 = ((ErlangMessage *) msg.get())->getMsg();
std::cout << "Got term: " << t2->toString() << "\n";
bool equals = t->equals(*t2);
if (equals) {
std::cout << "Equals, ok" << "\n";
} else {
std::cout << "Not equals, error!" << "\n";
}
return equals;
}