Skip to content

Commit

Permalink
trial to fix winipc crash
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Jul 21, 2024
1 parent d6c9c11 commit 9c1dcab
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/platform/windows/win_ipcconn.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ typedef struct ipc_conn {
int send_rv;
int conn_rv;
bool closed;
bool sending;
bool recving;
nni_mtx mtx;
nni_cv cv;
nni_reap_node reap;
Expand Down Expand Up @@ -76,9 +78,11 @@ ipc_recv_start(ipc_conn *c)
len = 0x1000000;
}

c->recving = true;
if ((!ReadFile(c->f, buf, len, NULL, &c->recv_io.olpd)) &&
((rv = GetLastError()) != ERROR_IO_PENDING)) {
// Synchronous failure.
c->recving = false;
nni_aio_list_remove(aio);
nni_aio_finish_error(aio, nni_win_error(rv));
} else {
Expand All @@ -104,6 +108,7 @@ ipc_recv_cb(nni_win_io *io, int rv, size_t num)
// A zero byte receive is a remote close from the peer.
rv = NNG_ECONNSHUT;
}
c->recving = false;
nni_aio_list_remove(aio);
ipc_recv_start(c);
nni_mtx_unlock(&c->mtx);
Expand Down Expand Up @@ -196,9 +201,11 @@ ipc_send_start(ipc_conn *c)
len = 0x1000000;
}

c->sending = true;
if ((!WriteFile(c->f, buf, len, NULL, &c->send_io.olpd)) &&
((rv = GetLastError()) != ERROR_IO_PENDING)) {
// Synchronous failure.
c->sending = false;
nni_aio_list_remove(aio);
nni_aio_finish_error(aio, nni_win_error(rv));
} else {
Expand All @@ -217,6 +224,7 @@ ipc_send_cb(nni_win_io *io, int rv, size_t num)
aio = nni_list_first(&c->send_aios);
NNI_ASSERT(aio != NULL);
nni_aio_list_remove(aio);
c->sending = false;
if (c->send_rv != 0) {
rv = c->send_rv;
c->send_rv = 0;
Expand Down Expand Up @@ -279,13 +287,21 @@ ipc_close(void *arg)
if (!c->closed) {
HANDLE f = c->f;
c->closed = true;
c->f = INVALID_HANDLE_VALUE;

c->f = INVALID_HANDLE_VALUE;

if (f != INVALID_HANDLE_VALUE) {
CancelIoEx(f, &c->send_io.olpd);
CancelIoEx(f, &c->recv_io.olpd);
DisconnectNamedPipe(f);
CloseHandle(f);
}
}
while (c->recving || c->sending) {
nni_mtx_unlock(&c->mtx);
nni_msleep(1);
nni_mtx_lock(&c->mtx);
}
nni_mtx_unlock(&c->mtx);
}

Expand Down

0 comments on commit 9c1dcab

Please sign in to comment.