static NAN_METHOD()

in src/win/conpty.cc [420:453]


static NAN_METHOD(PtyKill) {
  Nan::HandleScope scope;

  if (info.Length() != 1 ||
      !info[0]->IsNumber()) {
    Nan::ThrowError("Usage: pty.kill(id)");
    return;
  }

  int id = info[0]->Int32Value(Nan::GetCurrentContext()).FromJust();

  const pty_baton* handle = get_pty_baton(id);

  if (handle != nullptr) {
    HANDLE hLibrary = LoadLibraryExW(L"kernel32.dll", 0, 0);
    bool fLoadedDll = hLibrary != nullptr;
    if (fLoadedDll)
    {
      PFNCLOSEPSEUDOCONSOLE const pfnClosePseudoConsole = (PFNCLOSEPSEUDOCONSOLE)GetProcAddress((HMODULE)hLibrary, "ClosePseudoConsole");
      if (pfnClosePseudoConsole)
      {
        pfnClosePseudoConsole(handle->hpc);
      }
    }

    DisconnectNamedPipe(handle->hIn);
    DisconnectNamedPipe(handle->hOut);
    CloseHandle(handle->hIn);
    CloseHandle(handle->hOut);
    CloseHandle(handle->hShell);
  }

  return info.GetReturnValue().SetUndefined();
}