Re: [Bug-wget] [Win32 Patch] console-close events

2014-10-31 Thread Tim Ruehsen
On Monday 20 October 2014 21:34:07 Ángel González wrote:
 On 20/10/14 03:03, Darshit Shah wrote:
  On 06/17, Gisle Vanem wrote:
  Ángel González keis...@gmail.com wrote:
  PS. The above Sleep() seems to be ignored by WinCon. At least I
  failed to
  make it sleep more than ~500 msec.
  
  There may be a timeout on how long you can stay processing the event.
  
  Why do you need that Sleep() call at all? I would remove  it.
  
  When logging to the console (no '-o log-file' option), the Sleep(500)
  will make
  the final ... cleanup. message stay a tiny bit longer (but barely
  readable).
  Without a Sleep(), the console gets closed with only a message-beep.
  
  Any final reviews / comments on this patch? I haven't tested it out
  for the lack of a Windows system. If there are no objections, maybe we
  can push this patch?
 
 I would expect someone running a console application to have a console
 open. I understand the rationale when it's a beginner learning to
 program and is creating a console application, but don't really see a
 usecase for wget. How are you running wget that you get an autoclosing
 console?

Nobody here except Gisle himself !?

Since the patch is only for src/mswindows.c, I do not have a problem with it.
Why not let the MS Windows Console users test it !?

Tim


signature.asc
Description: This is a digitally signed message part.


Re: [Bug-wget] [Win32 Patch] console-close events

2014-10-27 Thread Tim Ruehsen
On Tuesday 21 October 2014 12:46:29 Gisle Vanem wrote:
 Darit, about the git format-patch. I don't know how.
 
 The src/Changelog entry could simply be:

After you 'git clone' you make your changes (ideally in your own branch).

You commit your changes to your local repo
git commit -a -m description

Now you generate a patchfile with
git format-patch -1
and send the resulting file to this list.
(Others would use  'git am  file.patch' to apply your patch.)

Here is what I do when someone asks me to amend a patch:
1. make the changes
2. commit them (git commit -a m blabla)
3. merge the last two commits into one with interactive 'git rebase':
git rebase -i HEAD~2
Your editor will open with two lines beginning with 'pick'.
Change 'pick' of line with 'blabla' to 'f' and save the file.

Of course there are (quite a few) other ways to achieve the same (e.g. you 
could undo the last commit with 'git reset').

If you are creating an own branch for each patch your are working on, you 
should be pretty clean. You can always checkout master and make a 'git pull' 
to get the latest changes from upstream.

You will find good help and many examples (for special problems one might 
have) in the internet.

Tim


signature.asc
Description: This is a digitally signed message part.


Re: [Bug-wget] [Win32 Patch] console-close events

2014-10-21 Thread Gisle Vanem

Ángel González keis...@gmail.com wrote:


I would expect someone running a console application to have a console open. I 
understand the rationale when it's a beginner
learning to program and is creating a console application, but don't really see 
a usecase for wget. How are you running wget that
you get an autoclosing console?


Easily. When e.g. Windows needs to restart (because of a WinUpdate etc.). It
sends a WM_QUERYENDSESSION to all (?) top-level windows. The
Console handler translates that to a CTRL_SHUTDOWN_EVENT for the
program in that console. Details here:
 
http://blogs.msdn.com/b/ntdebugging/archive/2007/06/09/how-windows-shuts-down.aspx

Darit, about the git format-patch. I don't know how.

The src/Changelog entry could simply be:

2014-10-21  Gisle Vanem gva...@yahoo.no

* mswindows.c (ws_handler): Added handling of
  CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT
  to cleanup before Wget exits. Added function ws_event_name() to retrieve
  the event name.

The diff for mswindows.c is as in my original message.

--gv




Re: [Bug-wget] [Win32 Patch] console-close events

2014-10-20 Thread Ángel González

On 20/10/14 03:03, Darshit Shah wrote:

On 06/17, Gisle Vanem wrote:

Ángel González keis...@gmail.com wrote:
PS. The above Sleep() seems to be ignored by WinCon. At least I 
failed to

make it sleep more than ~500 msec.

There may be a timeout on how long you can stay processing the event.

Why do you need that Sleep() call at all? I would remove  it.


When logging to the console (no '-o log-file' option), the Sleep(500) 
will make
the final ... cleanup. message stay a tiny bit longer (but barely 
readable).

Without a Sleep(), the console gets closed with only a message-beep.



Any final reviews / comments on this patch? I haven't tested it out 
for the lack of a Windows system. If there are no objections, maybe we 
can push this patch?
I would expect someone running a console application to have a console 
open. I understand the rationale when it's a beginner learning to 
program and is creating a console application, but don't really see a 
usecase for wget. How are you running wget that you get an autoclosing 
console?


Cheers




Re: [Bug-wget] [Win32 Patch] console-close events

2014-06-18 Thread Darshit Shah
On Tue, Jun 17, 2014 at 4:36 AM, Gisle Vanem gva...@yahoo.no wrote:
 Ángel González keis...@gmail.com wrote:

 +  event == CTRL_SHUTDOWN_EVENT ? CTRL_SHUTDOWN_EVENT :
 +  ?);

 Better something like UNKNOWN EVENT ?


 Ok. That seems better.


 PS. The above Sleep() seems to be ignored by WinCon. At least I failed to
  make it sleep more than ~500 msec.

 There may be a timeout on how long you can stay processing the event.

 Why do you need that Sleep() call at all? I would remove  it.


 When logging to the console (no '-o log-file' option), the Sleep(500) will
 make
 the final ... cleanup. message stay a tiny bit longer (but barely
 readable).
 Without a Sleep(), the console gets closed with only a message-beep.


 Thanks for sharing your patch!


 Thanks for the interest. Do you build Wget on Win32? Anybody else
 except me build and care about Wget/Win32 here?

Hi Gisle,

I don't really use Windows any more, but I do care to see Wget ported
to as many systems as possible. Some time ago, I did try to build Wget
on a Win32 system, but failed miserably.I just couldn't understand the
build process. The only reason I intend to build Wget on Windows is to
test it out for bugs and other things. If you have some klnd of a
guide one can follow to build Wget on a Windows system, I'll be glad
to have it.

 Revised patch:

 --- mswindows.c.orig  2014-06-12 13:02:44 +
 +++ mswindows.c 2014-06-17 00:58:08 +

 @@ -42,6 +42,7 @@

 #include utils.h
 #include url.h
 +#include init.h

 #ifndef ES_SYSTEM_REQUIRED
 #define ES_SYSTEM_REQUIRED  0x0001
 @@ -337,6 +338,17 @@
   /* If we get here, we're the child.  */
 }

 +/* Return the name for the console-events we might receive. */
 +static const char *ws_event_name (DWORD event)
 +{
 +  return (event == CTRL_C_EVENT ? CTRL_C_EVENT :
 +  event == CTRL_BREAK_EVENT ? CTRL_BREAK_EVENT :
 +  event == CTRL_CLOSE_EVENT ? CTRL_CLOSE_EVENT :
 +  event == CTRL_LOGOFF_EVENT ? CTRL_LOGOFF_EVENT :
 +  event == CTRL_SHUTDOWN_EVENT ? CTRL_SHUTDOWN_EVENT :
 +  UNKNOWN EVENT);
 +}

 +
 static BOOL WINAPI
 ws_handler (DWORD dwEvent)
 {
 @@ -352,6 +364,16 @@
   ws_hangup (CTRL+Break);
   return TRUE;
 #endif
 +case CTRL_CLOSE_EVENT:
 +case CTRL_LOGOFF_EVENT:
 +case CTRL_SHUTDOWN_EVENT:
 +  MessageBeep (MB_OK);
 +  logprintf (LOG_NOTQUIET, _(\nGot %s. Performing cleanup.\n),

 + ws_event_name(dwEvent));
 +  cleanup();
 +  Sleep(500);
 +  return TRUE;
 +
 default:
   return FALSE;
 }

 --

 --gv





-- 
Thanking You,
Darshit Shah



Re: [Bug-wget] [Win32 Patch] console-close events

2014-06-16 Thread Ángel González

On 09/06/14 16:59, Gisle Vanem wrote:
On Windows, when closing the console, logging off or shutting down the 
system, the OS sends the proper events to registered console-handlers.

Wget has a ws_handler() in mswindows.c that can handle these events
to cleanup it's tracks. This patch doesn't do anything other than 
cleanup()
may do. It could be used to delete any possibly truncated files. What 
does
Wget do (if anything) on other platforms? E.g. a ' ^Z' with no 'bg/fg' 
on Unix?
^Z on Unix sends a SIGSTOP, which is not catchable. On both SIGINT and 
SIGTERM,

wget leaves the half-downloaded file (which allows for later resuming)



Here is a simple patch that I use. Feel free to add it:





+/* Return the name for the console-events we might receive. */
+static const char *ws_event_name (DWORD event)
+{
+  return (event == CTRL_C_EVENT ? CTRL_C_EVENT :
+  event == CTRL_BREAK_EVENT ? CTRL_BREAK_EVENT :
+  event == CTRL_CLOSE_EVENT ? CTRL_CLOSE_EVENT :
+  event == CTRL_LOGOFF_EVENT ? CTRL_LOGOFF_EVENT :
+  event == CTRL_SHUTDOWN_EVENT ? CTRL_SHUTDOWN_EVENT :
+  ?);

Better something like UNKNOWN EVENT ?



static BOOL WINAPI
ws_handler (DWORD dwEvent)
{
@@ -352,6 +364,16 @@
  ws_hangup (CTRL+Break);
  return TRUE;
#endif
+case CTRL_CLOSE_EVENT:
+case CTRL_LOGOFF_EVENT:
+case CTRL_SHUTDOWN_EVENT:
+  MessageBeep (MB_OK);
+  logprintf (LOG_NOTQUIET, _(\n%s: Got %s. Performing cleanup.\n),
+ exec_name, ws_event_name(dwEvent));
+  cleanup();
+  Sleep(500);
+  return TRUE;
+




PS. The above Sleep() seems to be ignored by WinCon. At least I failed to
 make it sleep more than ~500 msec.

There may be a timeout on how long you can stay processing the event.

Why do you need that Sleep() call at all? I would remove  it.


Thanks for sharing your patch!




Re: [Bug-wget] [Win32 Patch] console-close events

2014-06-16 Thread Gisle Vanem

Ángel González keis...@gmail.com wrote:


+  event == CTRL_SHUTDOWN_EVENT ? CTRL_SHUTDOWN_EVENT :
+  ?);

Better something like UNKNOWN EVENT ?


Ok. That seems better.


PS. The above Sleep() seems to be ignored by WinCon. At least I failed to
 make it sleep more than ~500 msec.

There may be a timeout on how long you can stay processing the event.

Why do you need that Sleep() call at all? I would remove  it.


When logging to the console (no '-o log-file' option), the Sleep(500) will make
the final ... cleanup. message stay a tiny bit longer (but barely readable).
Without a Sleep(), the console gets closed with only a message-beep.


Thanks for sharing your patch!


Thanks for the interest. Do you build Wget on Win32? Anybody else
except me build and care about Wget/Win32 here?

Revised patch:

--- mswindows.c.orig  2014-06-12 13:02:44 +
+++ mswindows.c 2014-06-17 00:58:08 +
@@ -42,6 +42,7 @@

#include utils.h
#include url.h
+#include init.h

#ifndef ES_SYSTEM_REQUIRED
#define ES_SYSTEM_REQUIRED  0x0001
@@ -337,6 +338,17 @@
  /* If we get here, we're the child.  */
}

+/* Return the name for the console-events we might receive. */
+static const char *ws_event_name (DWORD event)
+{
+  return (event == CTRL_C_EVENT ? CTRL_C_EVENT :
+  event == CTRL_BREAK_EVENT ? CTRL_BREAK_EVENT :
+  event == CTRL_CLOSE_EVENT ? CTRL_CLOSE_EVENT :
+  event == CTRL_LOGOFF_EVENT ? CTRL_LOGOFF_EVENT :
+  event == CTRL_SHUTDOWN_EVENT ? CTRL_SHUTDOWN_EVENT :
+  UNKNOWN EVENT);
+}
+
static BOOL WINAPI
ws_handler (DWORD dwEvent)
{
@@ -352,6 +364,16 @@
  ws_hangup (CTRL+Break);
  return TRUE;
#endif
+case CTRL_CLOSE_EVENT:
+case CTRL_LOGOFF_EVENT:
+case CTRL_SHUTDOWN_EVENT:
+  MessageBeep (MB_OK);
+  logprintf (LOG_NOTQUIET, _(\nGot %s. Performing cleanup.\n),
+ ws_event_name(dwEvent));
+  cleanup();
+  Sleep(500);
+  return TRUE;
+
default:
  return FALSE;
}

--

--gv