Cleanup CURL impl
This commit is contained in:
+5
-3
@@ -130,9 +130,11 @@ DN_API void DN_OS_Init(DN_OSCore *os, DN_OSInitArgs *args)
|
||||
InitializeCriticalSection(&w32->sync_primitive_free_list_mutex);
|
||||
|
||||
QueryPerformanceFrequency(&w32->qpc_frequency);
|
||||
HMODULE module = LoadLibraryA("kernel32.dll");
|
||||
w32->set_thread_description = DN_Cast(DN_W32SetThreadDescriptionFunc *) GetProcAddress(module, "SetThreadDescription");
|
||||
FreeLibrary(module);
|
||||
HMODULE module = LoadLibraryA("kernel32.dll");
|
||||
if (module) {
|
||||
w32->set_thread_description = DN_Cast(DN_W32SetThreadDescriptionFunc *) GetProcAddress(module, "SetThreadDescription");
|
||||
FreeLibrary(module);
|
||||
}
|
||||
|
||||
// NOTE: win32 bcrypt
|
||||
wchar_t const BCRYPT_ALGORITHM[] = L"RNG";
|
||||
|
||||
+33
-22
@@ -688,11 +688,11 @@ DN_API void DN_OS_Exit(int32_t exit_code)
|
||||
|
||||
DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
char *stdout_buffer,
|
||||
size_t *stdout_size,
|
||||
DN_USize *stdout_size,
|
||||
char *stderr_buffer,
|
||||
size_t *stderr_size,
|
||||
DN_U32 timeout_ms,
|
||||
DN_OSErrSink *err)
|
||||
DN_USize *stderr_size,
|
||||
DN_U32 timeout_ms,
|
||||
DN_OSErrSink *err)
|
||||
{
|
||||
DN_OSExecResult result = {};
|
||||
size_t stdout_buffer_size = 0;
|
||||
@@ -736,24 +736,27 @@ DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
result.os_error_code = win_error.code;
|
||||
DN_OS_ErrSinkAppendF(err, result.os_error_code, "Executed command failed to terminate: %.*s", DN_Str8PrintFmt(win_error.msg));
|
||||
} else if (DN_Check(exec_result == WAIT_TIMEOUT || exec_result == WAIT_OBJECT_0)) {
|
||||
// NOTE: Read stdout from process //////////////////////////////////////////////////////
|
||||
// NOTE: Read stdout from process
|
||||
// If the pipes are full, the process will block. We periodically
|
||||
// flush the pipes to make sure this doesn't happen
|
||||
char sink[DN_Kilobytes(8)];
|
||||
stdout_bytes_available = 0;
|
||||
if (PeekNamedPipe(handle.stdout_read, nullptr, 0, nullptr, &stdout_bytes_available, nullptr)) {
|
||||
if (stdout_bytes_available) {
|
||||
DWORD bytes_read = 0;
|
||||
char *dest_buffer = handle.stdout_write && stdout_buffer ? stdout_buffer : sink;
|
||||
size_t dest_size = handle.stdout_write && stdout_buffer ? stdout_buffer_size : DN_ArrayCountU(sink);
|
||||
BOOL success = ReadFile(handle.stdout_read, dest_buffer, DN_Cast(DWORD) dest_size, &bytes_read, NULL);
|
||||
(void)success; // TODO:
|
||||
if (stdout_size)
|
||||
*stdout_size = bytes_read;
|
||||
DWORD bytes_read = 0;
|
||||
char *dest_buffer = handle.stdout_write && stdout_buffer ? stdout_buffer : sink;
|
||||
DN_USize dest_size = handle.stdout_write && stdout_buffer ? stdout_buffer_size : DN_ArrayCountU(sink);
|
||||
BOOL success = ReadFile(handle.stdout_read, dest_buffer, DN_Cast(DWORD) dest_size, &bytes_read, NULL);
|
||||
if (success) {
|
||||
if (stdout_size)
|
||||
*stdout_size = bytes_read;
|
||||
} else {
|
||||
DN_OS_ErrSinkAppendF(err, 1, "Failed to read bytes from stdout");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Read stderr from process //////////////////////////////////////////////////////
|
||||
// NOTE: Read stderr from process
|
||||
stderr_bytes_available = 0;
|
||||
if (PeekNamedPipe(handle.stderr_read, nullptr, 0, nullptr, &stderr_bytes_available, nullptr)) {
|
||||
if (stderr_bytes_available) {
|
||||
@@ -761,9 +764,12 @@ DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
size_t dest_size = handle.stderr_write && stderr_buffer ? stderr_buffer_size : DN_ArrayCountU(sink);
|
||||
DWORD bytes_read = 0;
|
||||
BOOL success = ReadFile(handle.stderr_read, dest_buffer, DN_Cast(DWORD) dest_size, &bytes_read, NULL);
|
||||
(void)success; // TODO:
|
||||
if (stderr_size)
|
||||
*stderr_size = bytes_read;
|
||||
if (success) {
|
||||
if (stderr_size)
|
||||
*stderr_size = bytes_read;
|
||||
} else {
|
||||
DN_OS_ErrSinkAppendF(err, 1, "Failed to read bytes from stderr");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -782,12 +788,17 @@ DN_API DN_OSExecResult DN_OS_ExecPump(DN_OSExecAsyncHandle handle,
|
||||
DN_Str8PrintFmt(win_error.msg));
|
||||
}
|
||||
|
||||
// NOTE: Cleanup ///////////////////////////////////////////////////////////////////////////////
|
||||
CloseHandle(handle.stdout_write);
|
||||
CloseHandle(handle.stderr_write);
|
||||
CloseHandle(handle.stdout_read);
|
||||
CloseHandle(handle.stderr_read);
|
||||
CloseHandle(handle.process);
|
||||
// NOTE: Cleanup
|
||||
if (handle.stdout_write)
|
||||
CloseHandle(handle.stdout_write);
|
||||
if (handle.stderr_write)
|
||||
CloseHandle(handle.stderr_write);
|
||||
if (handle.stdout_read)
|
||||
CloseHandle(handle.stdout_read);
|
||||
if (handle.stderr_read)
|
||||
CloseHandle(handle.stderr_read);
|
||||
if (handle.process)
|
||||
CloseHandle(handle.process);
|
||||
}
|
||||
|
||||
result.stdout_text = DN_Str8FromPtr(stdout_buffer, stdout_size ? *stdout_size : 0);
|
||||
|
||||
Reference in New Issue
Block a user