Changeset 3a84694 for select.c


Ignore:
Timestamp:
May 4, 2009, 9:55:17 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
bf66f4e
Parents:
d6bd3f1
git-author:
Nelson Elhage <nelhage@mit.edu> (05/04/09 20:24:31)
git-committer:
Nelson Elhage <nelhage@mit.edu> (05/04/09 21:55:17)
Message:
Turn unhandled SIGINTs into fake keystrokes.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • select.c

    radee9cc r3a84694  
    4141}
    4242
    43 void owl_select_process_timers(struct timeval *timeout)
     43void owl_select_process_timers(struct timespec *timeout)
    4444{
    4545  time_t now = time(NULL);
     
    7979  }
    8080
    81   timeout->tv_usec = 0;
     81  timeout->tv_nsec = 0;
    8282}
    8383
     
    287287}
    288288
     289void owl_select_handle_intr()
     290{
     291  owl_input in;
     292  in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR];
     293  owl_process_input_char(in);
     294}
     295
    289296void owl_select()
    290297{
    291   int i, max_fd, aim_max_fd, aim_done;
     298  int i, max_fd, aim_max_fd, aim_done, ret;
    292299  fd_set r;
    293300  fd_set e;
    294301  fd_set aim_rfds, aim_wfds;
    295   struct timeval timeout;
     302  struct timespec timeout;
     303  sigset_t mask, intr;
     304
     305  sigemptyset(&intr);
     306  sigaddset(&intr, SIGINT);
    296307
    297308  owl_select_process_timers(&timeout);
     309
     310  sigprocmask(SIG_BLOCK, &intr, &mask);
     311  if(owl_global_is_interrupted(&g)) {
     312     owl_select_handle_intr();
     313    return;
     314  }
    298315
    299316  max_fd = owl_select_dispatch_prepare_fd_sets(&r, &e);
     
    325342  /* END AIM HACK */
    326343
    327   if ( select(max_fd+1, &r, &aim_wfds, &e, &timeout) ) {
    328     owl_global_unset_interrupted(&g);
     344
     345  ret = pselect(max_fd+1, &r, &aim_wfds, &e, &timeout, &mask);
     346
     347  if(ret < 0 && errno == EINTR) {
     348    if(owl_global_is_interrupted(&g)) {
     349      owl_select_handle_intr();
     350    }
     351    return;
     352  }
     353
     354  sigprocmask(SIG_UNBLOCK, &intr, NULL);
     355
     356  if(ret > 0) {
    329357    /* Merge fd_sets and clear AIM FDs. */
    330358    for(i = 0; i <= max_fd; i++) {
Note: See TracChangeset for help on using the changeset viewer.