MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / ReadStream

Function ReadStream

Source/Engine/Platform/SDL/SDLPlatform.cpp:340–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338#if PLATFORM_LINUX
339
340bool ReadStream(SDL_IOStream*& stream, char* buffer, int64 bufferLength, int64& bufferPosition, LogType logType, CreateProcessSettings& settings)
341{
342 bool flushBuffer = false;
343 bool success = true;
344 auto read = SDL_ReadIO(stream, buffer + bufferPosition, bufferLength - bufferPosition - 1);
345 if (read == 0)
346 {
347 SDL_IOStatus status = SDL_GetIOStatus(stream);
348 if (status != SDL_IO_STATUS_NOT_READY && status != SDL_IO_STATUS_EOF)
349 success = false;
350 if (status != SDL_IO_STATUS_NOT_READY)
351 {
352 stream = nullptr;
353 flushBuffer = true;
354 }
355 }
356 else
357 {
358 int64 startPosition = bufferPosition;
359 bufferPosition += (int64)read;
360 if (bufferPosition == bufferLength - 1)
361 {
362 flushBuffer = true;
363 buffer[bufferPosition++] = '\n'; // Make sure to flush fully filled buffer
364 }
365 else
366 {
367 for (int64 i = startPosition; i < bufferPosition; ++i)
368 {
369 if (buffer[i] == '\n')
370 {
371 flushBuffer = true;
372 break;
373 }
374 }
375 }
376 }
377
378 if (flushBuffer)
379 {
380 int64 start = 0;
381 for (int64 i = 0; i < bufferPosition; ++i)
382 {
383 if (buffer[i] != '\n')
384 continue;
385
386 String str(&buffer[start], (int32)(i - start + 1));
387#if LOG_ENABLE
388 if (settings.LogOutput)
389 Log::Logger::Write(logType, StringView(str.Get(), str.Length() - 1));
390#endif
391 if (settings.SaveOutput)
392 settings.Output.Add(str.Get(), str.Length());
393 start = i + 1;
394 }
395 int64 length = bufferPosition - start;
396 if (length > 0)
397 {

Callers 1

CreateProcessMethod · 0.70

Calls 5

WriteFunction · 0.50
StringViewClass · 0.50
GetMethod · 0.45
LengthMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected