本文整理汇总了C++中ConnectionWriter::appendString方法的典型用法代码示例。如果您正苦于以下问题:C++ ConnectionWriter::appendString方法的具体用法?C++ ConnectionWriter::appendString怎么用?C++ ConnectionWriter::appendString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionWriter
的用法示例。
在下文中一共展示了ConnectionWriter::appendString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
bool BottleImpl::write(ConnectionWriter& writer) {
// could simplify this if knew lengths of blocks up front
if (writer.isTextMode()) {
//writer.appendLine(toString());
writer.appendString(toString().c_str(),'\n');
} else {
#ifdef USE_YARP1_PREFIX
if (!nested) {
String name = "YARP2";
writer.appendInt(name.length()+1);
writer.appendString(name.c_str(),'\0');
}
#endif
synch();
/*
if (!nested) {
// No byte count any more, to facilitate nesting
//YMSG(("bottle byte count %d\n",byteCount()));
//writer.appendInt(byteCount()+sizeof(NetInt32));
writer.appendInt(StoreList::code + speciality);
}
*/
//writer.appendBlockCopy(Bytes((char*)getBytes(),byteCount()));
writer.appendBlock((char*)getBytes(),byteCount());
}
return !writer.isError();
}
示例2: write
bool PortCommand::write(ConnectionWriter& writer) {
//ACE_DEBUG((LM_DEBUG,"PortCommand::writeBlock"));
//ACE_OS::printf("Writing port command, text mode %d\n", writer.isTextMode());
if (!writer.isTextMode()) {
int len = 0;
if (ch=='\0') {
len = (int)str.length()+1;
}
yAssert(header.length()==8);
char *base = header.get();
Bytes b(base,4);
NetType::netInt(len,b);
base[4] = '~';
base[5] = ch;
base[6] = 0;
base[7] = 1;
writer.appendBlock(header.bytes().get(),header.bytes().length());
if (ch=='\0') {
writer.appendBlock(str.c_str(),str.length()+1);
}
} else {
if (ch!='\0') {
char buf[] = "X";
buf[0] = ch;
writer.appendString(ConstString(buf).c_str(),'\n');
} else {
writer.appendString(str.c_str(),'\n');
}
}
return !writer.isError();
}
示例3: read
virtual bool read(ConnectionReader& reader) {
YTRACE("NameServer::read start");
ConstString ref = "NAME_SERVER ";
bool ok = true;
ConstString msg = "?";
bool haveMessage = false;
if (ok) {
if (reader.isTextMode()) {
msg = reader.expectText().c_str();
} else {
// migrate to binary mode support, eventually optimize
Bottle b;
b.read(reader);
msg = b.toString().c_str();
}
haveMessage = (msg!="");
msg = ref + msg;
}
if (reader.isActive()&&haveMessage) {
YARP_DEBUG(Logger::get(),ConstString("name server got message ") + msg);
size_t index = msg.find("NAME_SERVER");
if (index==0) {
Contact remote = reader.getRemoteContact();
YARP_DEBUG(Logger::get(),
ConstString("name server receiving from ") +
remote.toURI());
YARP_DEBUG(Logger::get(),
ConstString("name server request is ") + msg);
ConstString result = server->apply(msg,remote);
ConnectionWriter *os = reader.getWriter();
if (os!=YARP_NULLPTR) {
if (result=="") {
result = ns_terminate(ConstString("unknown command ") +
msg + "\n");
}
// This change is just to make Microsoft Telnet happy
ConstString tmp;
for (unsigned int i=0; i<result.length(); i++) {
if (result[i]=='\n') {
tmp += '\r';
}
tmp += result[i];
}
tmp += '\r';
os->appendString(tmp.c_str(),'\n');
YARP_DEBUG(Logger::get(),
ConstString("name server reply is ") + result);
ConstString resultSparse = result;
size_t end = resultSparse.find("\n*** end of message");
if (end!=ConstString::npos) {
resultSparse[end] = '\0';
}
YARP_INFO(Logger::get(),resultSparse);
}
} else {
YARP_INFO(Logger::get(),
ConstString("Name server ignoring unknown command: ")+msg);
ConnectionWriter *os = reader.getWriter();
if (os!=YARP_NULLPTR) {
// this result is necessary for YARP1 support
os->appendString("???????????????????????????????????????",'\n');
//os->flush();
//os->close();
}
}
}
YTRACE("NameServer::read stop");
return true;
}