(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:
parent
fdd7679fea
commit
5233f7029f
3 changed files with 15 additions and 0 deletions
|
@ -34,6 +34,8 @@
|
|||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
#include "misc.h"
|
||||
|
||||
|
@ -42,7 +44,11 @@ handleintr(int s)
|
|||
{
|
||||
if (interrupt) {
|
||||
/* tacky, but it works */
|
||||
#if !defined(_WIN32)
|
||||
if (write(s, "\naborted\n", 1 + 7 + 1) <= 0)
|
||||
#else
|
||||
if (send(s, "\naborted\n", 1 + 7 + 1, 0) <= 0)
|
||||
#endif
|
||||
return 0;
|
||||
interrupt = 0;
|
||||
}
|
||||
|
|
|
@ -250,6 +250,11 @@ main(int ac, s_char **av)
|
|||
FD_SET(sock, &readfds);
|
||||
n = select(sock + 1, &readfds, (fd_set *) 0, (fd_set *) 0,
|
||||
(struct timeval *)&tm);
|
||||
if (interrupt) {
|
||||
if (!handleintr(sock))
|
||||
break;
|
||||
errno = 0;
|
||||
}
|
||||
if (n < 0) {
|
||||
if (errno == EINTR) {
|
||||
errno = WSAGetLastError();
|
||||
|
@ -288,6 +293,9 @@ static void
|
|||
intr(int sig)
|
||||
{
|
||||
interrupt++;
|
||||
#ifdef _WIN32
|
||||
signal(SIGINT, intr);
|
||||
#endif
|
||||
#ifdef hpux
|
||||
signal(SIGINT, intr);
|
||||
#endif
|
||||
|
|
|
@ -98,6 +98,7 @@ termio(int fd, int sock, FILE *auxfi)
|
|||
}
|
||||
}
|
||||
FlushConsoleInputBuffer(hStdIn);
|
||||
if (n == 0) return 1;
|
||||
} else {
|
||||
n = read(fd, p, sizeof(buf) - i);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue