1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-02-08 20:50:09 +00:00

1. Set upperbound on number of Windows WaitHandles

2. Fixed Windows_IPC to DisconnectNamedPipe() on connected handled when 'end' is called
3. Fixed Windispatch to terminate on when close is emitted
This commit is contained in:
Bryan Roe
2020-05-19 01:14:18 -07:00
parent f115066e68
commit eba7419fc9
5 changed files with 33 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@@ -990,7 +990,11 @@ void ILibDuktape_net_server_IPC_EndSink(ILibDuktape_DuplexStream *stream, void *
if (!ILibMemory_CanaryOK(user)) { return; }
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
if (winIPC->mPipeHandle != NULL) { CloseHandle(winIPC->mPipeHandle); winIPC->mPipeHandle = NULL; }
if (winIPC->mPipeHandle != NULL)
{
if (winIPC->mServer != NULL) { DisconnectNamedPipe(winIPC->mPipeHandle); }
CloseHandle(winIPC->mPipeHandle); winIPC->mPipeHandle = NULL;
}
if (winIPC->read_overlapped.hEvent != NULL) { CloseHandle(winIPC->read_overlapped.hEvent); winIPC->read_overlapped.hEvent = NULL; }
if (winIPC->write_overlapped.hEvent != NULL) { CloseHandle(winIPC->write_overlapped.hEvent); winIPC->write_overlapped.hEvent = NULL; }

View File

@@ -2167,23 +2167,26 @@ void ILibChain_SetupWindowsWaitObject(HANDLE* waitList, int *waitListCount, stru
continue;
}
}
i = x++;
if (waitList[i] != NULL && waitList[ILibChain_HandleInfoIndex(i)] == NULL)
if (i + 1 < FD_SETSIZE)
{
WSACloseEvent(waitList[i]);
}
waitList[i] = (HANDLE)ILibLinkedList_GetDataFromNode(node);
waitList[ILibChain_HandleInfoIndex(i)] = (HANDLE)ILibMemory_Extra(node);
if (((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration.tv_sec != 0 || ((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration.tv_usec != 0)
{
// Timeout was specified
if (tv2LTtv1(&expirationTime, &(((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration)))
i = x++;
if (waitList[i] != NULL && waitList[ILibChain_HandleInfoIndex(i)] == NULL)
{
expirationTime.tv_sec = ((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration.tv_sec;
expirationTime.tv_usec = ((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration.tv_usec;
WSACloseEvent(waitList[i]);
}
waitList[i] = (HANDLE)ILibLinkedList_GetDataFromNode(node);
waitList[ILibChain_HandleInfoIndex(i)] = (HANDLE)ILibMemory_Extra(node);
if (((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration.tv_sec != 0 || ((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration.tv_usec != 0)
{
// Timeout was specified
if (tv2LTtv1(&expirationTime, &(((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration)))
{
expirationTime.tv_sec = ((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration.tv_sec;
expirationTime.tv_usec = ((ILibChain_WaitHandleInfo*)ILibMemory_Extra(node))->expiration.tv_usec;
// If the expiration happens in the past, we need to set the timeout to zero
if (tv2LTtv1(&expirationTime, &currentTime)) { expirationTime.tv_sec = currentTime.tv_sec; expirationTime.tv_usec = currentTime.tv_usec; }
// If the expiration happens in the past, we need to set the timeout to zero
if (tv2LTtv1(&expirationTime, &currentTime)) { expirationTime.tv_sec = currentTime.tv_sec; expirationTime.tv_usec = currentTime.tv_usec; }
}
}
}
node = ILibLinkedList_GetNextNode(node);

View File

@@ -160,6 +160,12 @@ function Promise(promiseFunc)
refTable[this._internal._hashCode()] = this._internal;
this._internal.once('settled', function () { refTable[this._hashCode()] = null; });
}
Object.defineProperty(this, "completed", {
get: function ()
{
return (this._internal.completed);
}
});
}
Promise.resolve = function resolve()

View File

@@ -137,6 +137,7 @@ function connect(ipc)
});
global.ipcClient = require('net').createConnection({ path: ipcPath }, function ()
{
this.on('close', function () { process.exit(); });
this.on('data', function (c)
{
var cLen = c.readUInt32LE(0);
@@ -165,6 +166,8 @@ function connect(ipc)
if (cLen < c.length) { this.unshift(c.slice(cLen)); }
});
});
global.ipcClient.on('error', function () { process.exit(); });
global.ipc2Client.on('error', function () { process.exit(); });
}
module.exports = { dispatch: dispatch, connect: connect };