in cppcache/src/TcrConnection.cpp [1060:1181]
std::shared_ptr<CacheableString> TcrConnection::readHandshakeString(
std::chrono::microseconds connectTimeout) {
ConnErrType error = CONN_NOERR;
char cstypeid;
if (receiveData(&cstypeid, 1, connectTimeout) != CONN_NOERR) {
conn_.reset();
if (error & CONN_TIMEOUT) {
LOGFINE("Timeout receiving string typeid");
throwException(
TimeoutException("TcrConnection::TcrConnection: "
"Timeout in handshake reading string type ID"));
} else {
LOGFINE("IO error receiving string typeid");
throwException(
GeodeIOException("TcrConnection::TcrConnection: "
"Handshake failure reading string type ID"));
}
}
LOGDEBUG("Received string typeid as %d", cstypeid);
uint32_t length = 0;
switch (static_cast<DSCode>(cstypeid)) {
case DSCode::CacheableNullString: {
return nullptr;
}
case DSCode::CacheableASCIIString: {
auto lenBytes = readHandshakeData(2, connectTimeout);
auto lenDI = connectionManager_.getCacheImpl()->createDataInput(
reinterpret_cast<const uint8_t*>(lenBytes.data()), lenBytes.size());
length = lenDI.readInt16();
break;
}
case DSCode::FixedIDDefault:
case DSCode::FixedIDByte:
case DSCode::FixedIDInt:
case DSCode::FixedIDNone:
case DSCode::FixedIDShort:
case DSCode::CacheableLinkedList:
case DSCode::Properties:
case DSCode::PdxType:
case DSCode::BooleanArray:
case DSCode::CharArray:
case DSCode::NullObj:
case DSCode::CacheableString:
case DSCode::Class:
case DSCode::JavaSerializable:
case DSCode::DataSerializable:
case DSCode::CacheableBytes:
case DSCode::CacheableInt16Array:
case DSCode::CacheableInt32Array:
case DSCode::CacheableInt64Array:
case DSCode::CacheableFloatArray:
case DSCode::CacheableDoubleArray:
case DSCode::CacheableObjectArray:
case DSCode::CacheableBoolean:
case DSCode::CacheableCharacter:
case DSCode::CacheableByte:
case DSCode::CacheableInt16:
case DSCode::CacheableInt32:
case DSCode::CacheableInt64:
case DSCode::CacheableFloat:
case DSCode::CacheableDouble:
case DSCode::CacheableDate:
case DSCode::CacheableFileName:
case DSCode::CacheableStringArray:
case DSCode::CacheableArrayList:
case DSCode::CacheableHashSet:
case DSCode::CacheableHashMap:
case DSCode::CacheableTimeUnit:
case DSCode::CacheableHashTable:
case DSCode::CacheableVector:
case DSCode::CacheableIdentityHashMap:
case DSCode::CacheableLinkedHashSet:
case DSCode::CacheableStack:
case DSCode::CacheableASCIIStringHuge:
case DSCode::CacheableStringHuge:
case DSCode::CacheableUserData:
case DSCode::CacheableUserData2:
case DSCode::CacheableUserData4:
case DSCode::PDX:
case DSCode::PDX_ENUM: {
conn_.reset();
throwException(
GeodeIOException("TcrConnection::TcrConnection: "
"Handshake failure: Unexpected string type ID"));
}
}
LOGDEBUG(" Received string len %d", length);
if (length == 0) {
return nullptr;
}
std::vector<char> recvMessage(length + 1);
recvMessage[length] = '\0';
if ((error = receiveData(recvMessage.data(), length, connectTimeout)) !=
CONN_NOERR) {
if (error & CONN_TIMEOUT) {
conn_.reset();
LOGFINE("Timeout receiving string data");
throwException(
TimeoutException("TcrConnection::TcrConnection: "
"Timeout in handshake reading string bytes"));
} else {
conn_.reset();
LOGFINE("IO error receiving string data");
throwException(
GeodeIOException("TcrConnection::TcrConnection: "
"Handshake failure reading string bytes"));
}
} else {
LOGDEBUG(" Received string data [%s]", recvMessage.data());
auto retval =
CacheableString::create(std::string(recvMessage.data(), length));
return retval;
}
}