Skip to content

Commit 6f8f5fb

Browse files
committed
Fix #292, added JobObject to tie httpmonitor lifetime to debugview++
also prevent multiple httpmonitor instances
1 parent 589ec46 commit 6f8f5fb

File tree

7 files changed

+108
-45
lines changed

7 files changed

+108
-45
lines changed

DebugView++/MainFrame.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,19 @@ void CMainFrame::OnDropped(const std::wstring uri)
554554
std::wstring httpmonitor = wstringbuilder() << Win32::GetExecutionPath() << "\\debugview++plugins\\HttpMonitor.exe";
555555
if (std::experimental::filesystem::exists(httpmonitor))
556556
{
557+
if (m_httpMonitorHandle)
558+
{
559+
::TerminateProcess(m_httpMonitorHandle.get(), 0);
560+
}
561+
557562
Win32::Process process(httpmonitor, uri);
563+
m_httpMonitorHandle = Win32::DuplicateHandle(process.GetProcessHandle());
564+
m_jobs.AddProcessByHandle(m_httpMonitorHandle.get());
565+
}
566+
else
567+
{
568+
m_logSources.AddMessage(stringbuilder() << httpmonitor << " missing, dropped url ignored\n");
558569
}
559-
else
560-
{
561-
m_logSources.AddMessage(stringbuilder() << httpmonitor << " missing, dropped url ignored\n");
562-
}
563570
}
564571
}
565572

DebugView++/MainFrame.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ class CMainFrame : public CTabbedFrameImpl<CMainFrame, CDotNetTabCtrl<SelectedTa
245245
std::vector<SourceInfo> m_sourceInfos;
246246
std::unique_ptr<GuiExecutorClient> m_GuiExecutorClient;
247247
LogSources m_logSources;
248+
Win32::JobObject m_jobs;
249+
Win32::Handle m_httpMonitorHandle;
248250
};
249251

250252
} // namespace debugviewpp

DebugView++/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#define VERSION 1,8,0,3
2-
#define VERSION_STR "1.8.0.3"
1+
#define VERSION 1,8,0,4
2+
#define VERSION_STR "1.8.0.4"

DebugView++/version.wxi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<?define ProductVersion.Major="1" ?>
44
<?define ProductVersion.Minor="8" ?>
55
<?define ProductVersion.Revision="0" ?>
6-
<?define ProductVersion.Build="3" ?>
7-
<?define ProductVersion="1.8.0.3" ?>
6+
<?define ProductVersion.Build="4" ?>
7+
<?define ProductVersion="1.8.0.4" ?>
88
</Include>

GDIGraphicsPOC/MainFrame.cpp

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,52 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR szCmdLine, int nC
2929
return msg.wParam;
3030
}
3131

32-
LRESULT fusion::CMainFrame::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
32+
namespace fusion
3333
{
34-
DestroyWindow();
35-
return 0;
36-
}
3734

38-
LRESULT fusion::CMainFrame::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
39-
{
40-
PostQuitMessage(0);
41-
return 0;
42-
}
35+
LRESULT CMainFrame::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
36+
{
37+
DestroyWindow();
38+
return 0;
39+
}
4340

44-
LRESULT fusion::CMainFrame::OnSize(UINT nType, CSize Extent)
45-
{
46-
cdbg << "OnSize:: " << Extent.cx << ", " << Extent.cy << "\n";
47-
UpdateLayout();
48-
return 1;
49-
}
41+
LRESULT CMainFrame::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
42+
{
43+
PostQuitMessage(0);
44+
return 0;
45+
}
5046

51-
void fusion::CMainFrame::AddTab(const std::wstring name)
52-
{
53-
auto lvi = std::make_shared<CLogViewTabItem2>();
54-
m_tabitems.push_back(lvi);
55-
lvi->SetText(name.c_str());
56-
lvi->Create(*this);
57-
58-
int newIndex = GetTabCtrl().GetItemCount();
59-
GetTabCtrl().InsertItem(newIndex, lvi.get());
60-
GetTabCtrl().SetCurSel(newIndex);
61-
}
47+
LRESULT CMainFrame::OnSize(UINT nType, CSize Extent)
48+
{
49+
cdbg << "OnSize:: " << Extent.cx << ", " << Extent.cy << "\n";
50+
UpdateLayout();
51+
return 1;
52+
}
6253

63-
LRESULT fusion::CMainFrame::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
64-
{
65-
auto rect = RECT();
66-
GetClientRect(&rect);
54+
void CMainFrame::AddTab(const std::wstring name)
55+
{
56+
auto lvi = std::make_shared<CLogViewTabItem2>();
57+
m_tabitems.push_back(lvi);
58+
lvi->SetText(name.c_str());
59+
lvi->Create(*this);
6760

68-
// block 2
69-
CreateTabWindow(*this, rect, CTCS_CLOSEBUTTON | CTCS_DRAGREARRANGE);
70-
AddTab(L"Tab1");
71-
AddTab(L"Tab2");
61+
int newIndex = GetTabCtrl().GetItemCount();
62+
GetTabCtrl().InsertItem(newIndex, lvi.get());
63+
GetTabCtrl().SetCurSel(newIndex);
64+
}
7265

73-
ShowTabControl();
74-
return 0;
75-
}
66+
LRESULT CMainFrame::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
67+
{
68+
auto rect = RECT();
69+
GetClientRect(&rect);
70+
71+
// block 2
72+
CreateTabWindow(*this, rect, CTCS_CLOSEBUTTON | CTCS_DRAGREARRANGE);
73+
AddTab(L"Tab1");
74+
AddTab(L"Tab2");
75+
76+
ShowTabControl();
77+
return 0;
78+
}
79+
80+
}

Win32Lib/Win32Lib.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,41 @@ std::wstring GetHresultDescription(HRESULT hr)
566566
return name + L", " + msg;
567567
}
568568

569+
JobObject::JobObject()
570+
: m_jobHandle(::CreateJobObject(nullptr, nullptr))
571+
{
572+
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
573+
574+
jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
575+
if (0 == ::SetInformationJobObject(m_jobHandle.get(), JobObjectExtendedLimitInformation, &jeli, sizeof(jeli)))
576+
{
577+
ThrowLastError("SetInformationJobObject");
578+
}
579+
}
580+
581+
HANDLE JobObject::get() const
582+
{
583+
return m_jobHandle.get();
584+
}
585+
586+
void JobObject::AddProcessById(DWORD pid) const
587+
{
588+
Handle processHandle(OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid));
589+
::AssignProcessToJobObject(m_jobHandle.get(), processHandle.get());
590+
}
591+
592+
void JobObject::AddProcessByHandle(HANDLE processHandle) const
593+
{
594+
::AssignProcessToJobObject(m_jobHandle.get(), processHandle);
595+
}
596+
597+
Handle DuplicateHandle(HANDLE handle)
598+
{
599+
HANDLE result;
600+
::DuplicateHandle(GetCurrentProcess(), handle, GetCurrentProcess(), &result, 0, FALSE, DUPLICATE_SAME_ACCESS);
601+
return Handle(result);
602+
}
603+
569604
} // namespace Win32
570605

571606
bool operator==(const FILETIME& ft1, const FILETIME& ft2)

include/Win32/Win32Lib.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,20 @@ std::wstring GetHresultMessage(HRESULT hr);
302302
std::wstring GetHresultName(HRESULT hr);
303303
std::wstring GetHresultDescription(HRESULT hr);
304304

305+
class JobObject
306+
{
307+
public:
308+
JobObject();
309+
HANDLE get() const;
310+
void AddProcessById(DWORD processId) const;
311+
void AddProcessByHandle(HANDLE processHandle) const;
312+
313+
private:
314+
Handle m_jobHandle;
315+
};
316+
317+
Handle DuplicateHandle(HANDLE handle);
318+
305319
} // namespace Win32
306320

307321
bool operator==(const FILETIME& ft1, const FILETIME& ft2);

0 commit comments

Comments
 (0)