bool Protocol::write(SizedWriter& writer) { // End any current write. writer.stopWrite(); // Skip if this connection is not active (e.g. when there are several // logical mcast connections but only one write is actually needed). if (!getConnection().isActive()) return false; this->writer = &writer; bool replied = false; yAssert(delegate != nullptr); getStreams().beginPacket(); // Message begins. bool ok = delegate->write(*this, writer); getStreams().endPacket(); // Message ends. PortReader* reply = writer.getReplyHandler(); if (reply != nullptr) { if (!delegate->supportReply()) { // We are expected to get a reply, but cannot. YARP_INFO(log, std::string("connection ") + getRoute().toString() + " does not support replies (try \"tcp\" or \"text_ack\")"); } if (ok) { // Read reply. reader.reset(is(), &getStreams(), getRoute(), messageLen, delegate->isTextMode(), delegate->isBareMode()); replied = reply->read(reader); } } expectAck(); // Expect acknowledgement (carrier-specific). this->writer = nullptr; return replied; }
void Protocol::reply(SizedWriter& writer) { writer.stopWrite(); delegate->reply(*this, writer); pendingReply = false; }