(main, intr, handleintr, termio): Do the right thing for Windows so ^C

aborts to the current command, as it should.  From Ron Koenderink.
This commit is contained in:
Markus Armbruster 2004-02-22 07:27:08 +00:00
parent fdd7679fea
commit 5233f7029f
3 changed files with 15 additions and 0 deletions

View file

@ -34,6 +34,8 @@
#if !defined(_WIN32) #if !defined(_WIN32)
#include <unistd.h> #include <unistd.h>
#else
#include <winsock.h>
#endif #endif
#include "misc.h" #include "misc.h"
@ -42,7 +44,11 @@ handleintr(int s)
{ {
if (interrupt) { if (interrupt) {
/* tacky, but it works */ /* tacky, but it works */
#if !defined(_WIN32)
if (write(s, "\naborted\n", 1 + 7 + 1) <= 0) if (write(s, "\naborted\n", 1 + 7 + 1) <= 0)
#else
if (send(s, "\naborted\n", 1 + 7 + 1, 0) <= 0)
#endif
return 0; return 0;
interrupt = 0; interrupt = 0;
} }

View file

@ -250,6 +250,11 @@ main(int ac, s_char **av)
FD_SET(sock, &readfds); FD_SET(sock, &readfds);
n = select(sock + 1, &readfds, (fd_set *) 0, (fd_set *) 0, n = select(sock + 1, &readfds, (fd_set *) 0, (fd_set *) 0,
(struct timeval *)&tm); (struct timeval *)&tm);
if (interrupt) {
if (!handleintr(sock))
break;
errno = 0;
}
if (n < 0) { if (n < 0) {
if (errno == EINTR) { if (errno == EINTR) {
errno = WSAGetLastError(); errno = WSAGetLastError();
@ -288,6 +293,9 @@ static void
intr(int sig) intr(int sig)
{ {
interrupt++; interrupt++;
#ifdef _WIN32
signal(SIGINT, intr);
#endif
#ifdef hpux #ifdef hpux
signal(SIGINT, intr); signal(SIGINT, intr);
#endif #endif

View file

@ -98,6 +98,7 @@ termio(int fd, int sock, FILE *auxfi)
} }
} }
FlushConsoleInputBuffer(hStdIn); FlushConsoleInputBuffer(hStdIn);
if (n == 0) return 1;
} else { } else {
n = read(fd, p, sizeof(buf) - i); n = read(fd, p, sizeof(buf) - i);
} }