#include <io.h>
#include <winsock.h>
#include <process.h>
+#include <errno.h>
/*
* Internal state maintained by the IO manager.
len = write(work->workData.ioData.fd,
work->workData.ioData.buf,
work->workData.ioData.len);
- if (len == -1) { errCode = errno; }
+ if (len == -1) {
+ errCode = errno;
+ // write() gets errno wrong for
+ // ERROR_NO_DATA, we have to fix it here:
+ if (errCode == EINVAL &&
+ GetLastError() == ERROR_NO_DATA) {
+ errCode = EPIPE;
+ }
+ }
}
complData = work->workData.ioData.buf;
fd = work->workData.ioData.fd;
return depositWorkItem(reqID, wItem);
}
-void ShutdownIOManager ( void )
+void ShutdownIOManager ( rtsBool wait_threads )
{
int num;
SetEvent(ioMan->hExitEvent);
- /* Wait for all worker threads to die. */
- for (;;) {
- EnterCriticalSection(&ioMan->manLock);
- num = ioMan->numWorkers;
- LeaveCriticalSection(&ioMan->manLock);
- if (num == 0)
- break;
- Sleep(10);
+ if (wait_threads) {
+ /* Wait for all worker threads to die. */
+ for (;;) {
+ EnterCriticalSection(&ioMan->manLock);
+ num = ioMan->numWorkers;
+ LeaveCriticalSection(&ioMan->manLock);
+ if (num == 0)
+ break;
+ Sleep(10);
+ }
+ FreeWorkQueue(ioMan->workQueue);
+ CloseHandle(ioMan->hExitEvent);
+ DeleteCriticalSection(&ioMan->active_work_lock);
+ DeleteCriticalSection(&ioMan->manLock);
+ free(ioMan);
+ ioMan = NULL;
}
- FreeWorkQueue(ioMan->workQueue);
- CloseHandle(ioMan->hExitEvent);
- free(ioMan);
- ioMan = NULL;
}
/* Keep track of WorkItems currently being serviced. */