Untitled
unknown
c_cpp
a year ago
1.1 kB
9
Indexable
string PeriodsMgr::ReadFromNamedPipe(string in_pipe, int in_configIndex)
{
ResetLastError();
int handle = FileOpen(in_pipe, FILE_READ | FILE_WRITE | FILE_BIN);
if (handle == INVALID_HANDLE)
{
Print("Failed to connect to the named pipe:", GetLastError());
return "";
}
// Send configIndex to the server
FileWriteInteger(handle, in_configIndex, 4);
FileFlush(handle); // Send right away
Sleep(250); // Allow time for the server to respond
// read data length
int dataLength = FileReadInteger(handle, 4);
if (dataLength <= 0) {
Print("Invalid data length received:", dataLength);
FileClose(handle);
return "";
}
// read the data
char buffer[];
uint bytesRead = FileReadArray(handle, buffer, 0, dataLength);
if (bytesRead != dataLength) {
Print("Mismatch in expected and read bytes.");
FileClose(handle);
return "";
}
// Convert buffer to string assuming ANSI encoding
string configData = CharArrayToString(buffer, 0, -1, CP_ACP);
FileClose(handle);
return configData;
}Editor is loading...
Leave a Comment