Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows build doesn't exit cleanly when terminated externaly #2

Closed
avih opened this issue Aug 16, 2012 · 8 comments
Closed

Windows build doesn't exit cleanly when terminated externaly #2

avih opened this issue Aug 16, 2012 · 8 comments

Comments

@avih
Copy link

avih commented Aug 16, 2012

When using taskkill or sending the WM_CLOSE message:

  1. WinMain doesn't always exit properly (GetMessage can return -1 on error).
  2. No cleanups are performed.

Here's a patch which fixes both issues:

--- valenok-mongoose-375950f/main.c Wed Aug 15 16:05:46 2012
+++ valenok-mongoose-375950f/main.c Thu Aug 16 15:28:36 2012
@@ -438,14 +438,19 @@
           SetForegroundWindow(hWnd);
           TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hWnd, NULL);
           PostMessage(hWnd, WM_NULL, 0, 0);
           DestroyMenu(hMenu);
           break;
       }
       break;
+    case WM_CLOSE:
+      mg_stop(ctx);
+      Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
+      PostQuitMessage(0);
+      return 0; // We've just sent our own quit message, with proper hwnd.
   }
 
   return DefWindowProc(hWnd, msg, wParam, lParam);
 }
 
 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show) {
   WNDCLASS cls;
@@ -469,18 +474,19 @@
   TrayIcon.hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_ICON),
                              IMAGE_ICON, 16, 16, 0);
   TrayIcon.hWnd = hWnd;
   snprintf(TrayIcon.szTip, sizeof(TrayIcon.szTip), "%s", server_name);
   TrayIcon.uCallbackMessage = WM_USER;
   Shell_NotifyIcon(NIM_ADD, &TrayIcon);
 
-  while (GetMessage(&msg, hWnd, 0, 0)) {
+  while (GetMessage(&msg, hWnd, 0, 0) > 0) {
     TranslateMessage(&msg);
     DispatchMessage(&msg);
   }
+  return msg.wParam;
 }
 #else
 int main(int argc, char *argv[]) {
   init_server_name();
   start_mongoose(argc, argv);
   printf("%s started on port(s) %s with web root [%s]\n",
          server_name, mg_get_option(ctx, "listening_ports"),

@cpq
Copy link
Member

cpq commented Aug 16, 2012

Submitted b68b0e3, thank you.

@cpq cpq closed this as completed Aug 16, 2012
@avih
Copy link
Author

avih commented Aug 17, 2012

Should reopen.

The patch was applied incorrectly (and cleanup indeed isn't performed). The WM_CLOSE case should be at the same level as the WM_USER case, not inside it (it's msg, not lParam).

@cpq
Copy link
Member

cpq commented Aug 17, 2012

Ouch, facepalm. Sorry, I wasn't attentive enough. Pushed 0c5c3b1, please verify.

@avih
Copy link
Author

avih commented Aug 17, 2012

Yeah, that works, thanks :)

Also, I hope it's OK to ask here about compilation:

  1. Using latest msys and mingw (gcc 4.6.2), when running make mingw I get a lot of warnings (more than 30 probably), is that normal?
  2. How should I build without SSL? Tried make mingw -DNO_SSL and few other options which didn't work. make mingw CFLAGS="-DNO_SSL" did compile, but the exe still refused to run without ssleay32.dll and libeay32.dll. Eventually I edited the makefile and ripped out all SSL compiles/links, which worked, but I prefer not modifying the makefile...
  3. What's _mongoose.dll? mongoose.exe seems to work fine without it, but it might need it for some stuff?

Thanks in advance for your replies, and for mongoose itself :)

@cpq
Copy link
Member

cpq commented Aug 17, 2012

  1. Not good, but I don't have resources to fix that.
  2. Looks like some conditionals are broken, I'll fix that
  3. .dll is for windows people who want to embed mongoose but don't want to build it (and build SSL stuff, etc.). The DLL has everything, including SSL, built in.

@avih
Copy link
Author

avih commented Aug 17, 2012

OK, thank for the quick replies.

For future reference, here's the output of 'make mingw' on my system:
http://pastebin.com/n0P0XAAN

GerHobbelt added a commit to GerHobbelt/mongoose-vanilla that referenced this issue Aug 18, 2012
GerHobbelt added a commit to GerHobbelt/mongoose-vanilla that referenced this issue Aug 18, 2012
…lete (mg_read() --> 0); also enlarge the tail header set for the chunked transfer I/O tests in an attempt to increase the chances to trigger edge case cesanta#2 (buffer overflow detect while fetching tail headers)
@avih
Copy link
Author

avih commented Aug 19, 2012

Just wanted to note that with the WM_CLOSE issue fixed, I've included mongoose in portable-quassel-backlog-search here: http://bugs.quassel-irc.org/projects/1/wiki/Quassel_Logging#Windows-Portable-quasselsuche . Thanks again :)

@cpq
Copy link
Member

cpq commented Aug 19, 2012

Cool, thank you!

On Sun, Aug 19, 2012 at 6:14 PM, avih notifications@github.com wrote:

Just wanted to note that with the WM_CLOSE issue fixed, I've included
mongoose in portable-quassel-backlog-search here:
http://bugs.quassel-irc.org/projects/1/wiki/Quassel_Logging#Windows-Portable-quasselsuche. Thanks again :)


Reply to this email directly or view it on GitHubhttps://github.com//issues/2#issuecomment-7854852.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants