Mercurial > ~astiob > upreckon > hgweb
comparison upreckon/_unixmodule.cpp @ 218:65b5c9390010
With _unix, Escape presses now cancel test data unarchiving
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Mon, 22 Aug 2011 22:34:09 +0300 |
parents | 8c4e92fb32d8 |
children | d06e57b182a9 |
comparison
equal
deleted
inserted
replaced
217:ce1285728952 | 218:65b5c9390010 |
---|---|
1 // Copyright (c) 2011 Chortos-2 <chortos@inbox.lv> | 1 // Copyright (c) 2011 Chortos-2 <chortos@inbox.lv> |
2 | 2 |
3 #include <Python.h> | 3 #include <Python.h> |
4 #include <structmember.h> | 4 #include <structmember.h> |
5 #include <stdio.h> | |
6 | 5 |
7 #ifdef HAVE_SYS_TYPES_H | 6 #ifdef HAVE_SYS_TYPES_H |
8 #include <sys/types.h> | 7 #include <sys/types.h> |
9 #endif | 8 #endif |
10 | 9 |
153 #endif | 152 #endif |
154 | 153 |
155 #ifdef HAVE_TERMIOS_H | 154 #ifdef HAVE_TERMIOS_H |
156 static bool catch_escape = false; | 155 static bool catch_escape = false; |
157 static struct termios orig_termios; | 156 static struct termios orig_termios; |
157 #ifdef O_ASYNC | |
158 static int orig_stdout_fl; | |
159 #endif | |
158 #endif | 160 #endif |
159 | 161 |
160 typedef struct | 162 typedef struct |
161 { | 163 { |
162 PyObject_HEAD | 164 PyObject_HEAD |
403 #ifdef SIGXFZ | 405 #ifdef SIGXFZ |
404 signal(SIGXFZ, SIG_DFL); | 406 signal(SIGXFZ, SIG_DFL); |
405 #endif | 407 #endif |
406 #endif | 408 #endif |
407 | 409 |
410 #if defined HAVE_TERMIOS_H && defined O_ASYNC | |
411 signal(SIGIO, SIG_DFL); | |
412 #endif | |
413 | |
408 if (c2ppipe[1] < 3) | 414 if (c2ppipe[1] < 3) |
409 { | 415 { |
410 int newfd; | 416 int newfd; |
411 #ifdef F_DUPFD_CLOEXEC | 417 #ifdef F_DUPFD_CLOEXEC |
412 newfd = fcntl(c2ppipe[1], F_DUPFD_CLOEXEC, 3); | 418 newfd = fcntl(c2ppipe[1], F_DUPFD_CLOEXEC, 3); |
1273 static PyObject *_unix_pause(PyObject *self) | 1279 static PyObject *_unix_pause(PyObject *self) |
1274 { | 1280 { |
1275 #ifdef HAVE_TERMIOS_H | 1281 #ifdef HAVE_TERMIOS_H |
1276 if (catch_escape) | 1282 if (catch_escape) |
1277 { | 1283 { |
1284 #ifdef O_ASYNC | |
1285 signal(SIGIO, SIG_DFL); | |
1286 #endif | |
1278 char c; | 1287 char c; |
1279 while (read(0, &c, 1) == -1 && errno == EINTR) | 1288 while (read(0, &c, 1) == -1 && errno == EINTR) |
1280 { | 1289 { |
1281 if (PyErr_CheckSignals() == -1) | 1290 if (PyErr_CheckSignals() == -1) |
1282 { | 1291 { |
1307 | 1316 |
1308 #ifdef HAVE_TERMIOS_H | 1317 #ifdef HAVE_TERMIOS_H |
1309 static void restore_termios(void) | 1318 static void restore_termios(void) |
1310 { | 1319 { |
1311 tcsetattr(0, TCSAFLUSH, &orig_termios); | 1320 tcsetattr(0, TCSAFLUSH, &orig_termios); |
1321 #ifdef O_ASYNC | |
1322 fcntl(0, F_SETFL, orig_stdout_fl); | |
1323 #endif | |
1312 #ifdef USE_WAKEUP_FD | 1324 #ifdef USE_WAKEUP_FD |
1313 close_intpipe(); | 1325 close_intpipe(); |
1314 #endif | 1326 #endif |
1315 } | 1327 } |
1316 #endif | 1328 #endif |
1441 new_termios.c_cc[VMIN] = 1; | 1453 new_termios.c_cc[VMIN] = 1; |
1442 new_termios.c_cc[VTIME] = 0; | 1454 new_termios.c_cc[VTIME] = 0; |
1443 if (!Py_AtExit(restore_termios) && !tcsetattr(0, TCSAFLUSH, &new_termios)) | 1455 if (!Py_AtExit(restore_termios) && !tcsetattr(0, TCSAFLUSH, &new_termios)) |
1444 { | 1456 { |
1445 catch_escape = true; | 1457 catch_escape = true; |
1458 #ifdef O_ASYNC | |
1459 orig_stdout_fl = fcntl(0, F_GETFL); | |
1460 fcntl(0, F_SETFL, orig_stdout_fl | O_ASYNC); | |
1461 #endif | |
1446 } | 1462 } |
1447 } | 1463 } |
1448 #ifdef USE_WAKEUP_FD | 1464 #ifdef USE_WAKEUP_FD |
1449 else | 1465 else |
1450 { | 1466 { |