Changeset a6a9ddb


Ignore:
Timestamp:
Jun 22, 2011, 12:37:22 AM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
2d04312
Parents:
2244836
git-author:
David Benjamin <davidben@mit.edu> (05/24/11 02:03:16)
git-committer:
David Benjamin <davidben@mit.edu> (06/22/11 00:37:22)
Message:
Replace popexec's io_dispatch with a glib io watch

Again, this code may be simplified with a GIOChannel.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • owl.h

    r074bdaa ra6a9ddb  
    543543  int winactive;
    544544  pid_t pid;                    /* or 0 if it has terminated */
    545   const owl_io_dispatch *dispatch;
     545  guint io_watch;
    546546} owl_popexec;
    547547
  • popexec.c

    r47e0a6a ra6a9ddb  
    1616  int pipefds[2], child_write_fd, parent_read_fd;
    1717  pid_t pid;
     18  GIOChannel *channel;
    1819
    1920  if (owl_global_get_popwin(&g) || owl_global_get_viewwin(&g)) {
     
    5455    pe->pid=pid;
    5556    pe->winactive=1;
    56     pe->dispatch = owl_select_add_io_dispatch(parent_read_fd, OWL_IO_READ|OWL_IO_EXCEPT, &owl_popexec_inputhandler, &owl_popexec_delete_dispatch, pe);
     57    channel = g_io_channel_unix_new(parent_read_fd);
     58    g_io_channel_set_close_on_unref(channel, TRUE);
     59    pe->io_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
     60                                       G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
     61                                       owl_popexec_inputhandler, pe,
     62                                       (GDestroyNotify)owl_popexec_unref);
     63    g_io_channel_unref(channel);
    5764    pe->refcount++;
    5865  } else {
     
    7582}
    7683
    77 void owl_popexec_inputhandler(const owl_io_dispatch *d, void *data)
     84gboolean owl_popexec_inputhandler(GIOChannel *source, GIOCondition condition, void *data)
    7885{
    7986  owl_popexec *pe = data;
     
    8188  char *buf;
    8289  int status;
     90  int fd = g_io_channel_unix_get_fd(source);
    8391
    84   if (!pe) return;
     92  /* TODO: Reading from GIOChannel may be more convenient. */
     93
     94  if (!pe) return FALSE;
    8595
    8696  /* If pe->winactive is 0 then the vwin has closed.
     
    96106  /* the viewwin has closed */
    97107  if (!pe->pid && !pe->winactive) {
    98     owl_select_remove_io_dispatch(d);
    99     pe->dispatch = NULL;
    100     return;
     108    pe->io_watch = 0;
     109    return FALSE;
    101110  }
    102111
    103   if (0 != (rv_navail = ioctl(d->fd, FIONREAD, &navail))) {
     112  if (0 != (rv_navail = ioctl(fd, FIONREAD, &navail))) {
    104113    owl_function_debugmsg("ioctl error");
    105114  }
     
    113122      owl_viewwin_append_text(pe->vwin, "\n");
    114123    }
    115     owl_select_remove_io_dispatch(d);
    116     pe->dispatch = NULL;
    117     return;
     124    pe->io_watch = 0;
     125    return FALSE;
    118126  }
    119127
    120   if (d->fd<0 || !pe->pid || !pe->winactive || rv_navail) {
     128  if (fd<0 || !pe->pid || !pe->winactive || rv_navail) {
    121129    owl_function_error("popexec should not have reached this point");
    122     return;
     130    return FALSE;
    123131  }
    124132
    125   if (navail<=0) return;
     133  if (navail<=0) return TRUE;
    126134  if (navail>1024) { navail = 1024; }
    127135  buf = g_new(char, navail+1);
    128136  owl_function_debugmsg("about to read %d", navail);
    129   bread = read(d->fd, buf, navail);
     137  bread = read(fd, buf, navail);
    130138  if (bread<0) {
    131139    perror("read");
     
    140148  }
    141149  g_free(buf);
    142  
    143 }
    144 
    145 void owl_popexec_delete_dispatch(const owl_io_dispatch *d)
    146 {
    147   owl_popexec *pe = d->data;
    148   close(d->fd);
    149   owl_popexec_unref(pe);
     150  return TRUE;
    150151}
    151152
     
    156157
    157158  pe->winactive = 0;
    158   if (pe->dispatch) {
    159     owl_select_remove_io_dispatch(pe->dispatch);
    160     pe->dispatch = NULL;
     159  if (pe->io_watch) {
     160    g_source_remove(pe->io_watch);
     161    pe->io_watch = 0;
    161162  }
    162163  if (pe->pid) {
Note: See TracChangeset for help on using the changeset viewer.