Changeset 40c6657


Ignore:
Timestamp:
Dec 17, 2008, 5:13:47 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
df7f364
Parents:
cf0cc64
git-author:
Nelson Elhage <nelhage@mit.edu> (12/17/08 17:01:28)
git-committer:
Nelson Elhage <nelhage@mit.edu> (12/17/08 17:13:47)
Message:
Use owl_select instead of owl_muxevents for owl_popexec.
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • owl.h

    r1895c29 r40c6657  
    380380} owl_popwin;
    381381
    382 typedef struct _owl_popexec {
    383   int refcount;
    384   owl_viewwin *vwin;
    385   int winactive;
    386   int pid;                      /* or 0 if it has terminated */
    387   int rfd; 
    388 } owl_popexec;
    389 
    390382typedef struct _owl_messagelist {
    391383  owl_list list;
     
    532524  void *data;
    533525} owl_dispatch;
     526
     527typedef struct _owl_popexec {
     528  int refcount;
     529  owl_viewwin *vwin;
     530  int winactive;
     531  int pid;                      /* or 0 if it has terminated */
     532  owl_dispatch dispatch;
     533} owl_popexec;
    534534
    535535typedef struct _owl_global {
  • popexec.c

    r49a8434 r40c6657  
    5151    return NULL;
    5252  } else if (pid != 0) {
     53    close(child_write_fd);
    5354    /* still in owl */
    54     int muxhandle;
    5555    pe->pid=pid;
    5656    pe->winactive=1;
    57     pe->rfd = parent_read_fd;
    58     close(child_write_fd);
    59     muxhandle = owl_muxevents_add(owl_global_get_muxevents(&g),
    60                                   parent_read_fd, OWL_MUX_READ|OWL_MUX_EXCEPT,
    61                                   owl_popexec_inputhandler, (void*)pe);
     57    pe->dispatch.fd = parent_read_fd;
     58    pe->dispatch.cfunc = owl_popexec_inputhandler;
     59    pe->dispatch.destroy = owl_popexec_free_dispatch;
     60    pe->dispatch.data = pe;
     61    owl_select_add_dispatch(&pe->dispatch);
    6262    pe->refcount++;
    6363  } else {
     
    8585}
    8686
    87 void owl_popexec_inputhandler(int handle, int fd, int eventmask, void *data)
     87void owl_popexec_inputhandler(owl_dispatch *d)
    8888{
    89   owl_popexec *pe = (owl_popexec*)data;
     89  owl_popexec *pe = d->data;
    9090  int navail, bread, rv_navail;
    9191  char *buf;
     
    9696  /* If pe->winactive is 0 then the vwin has closed.
    9797   * If pe->pid is 0 then the child has already been reaped.
    98    * if pe->rfd is -1 then the fd has been closed out.
     98   * if d->fd is -1 then the fd has been closed out.
    9999   * Under these cases we want to get to a state where:
    100100   *   - data read until end if child running
     
    105105
    106106  /* the viewwin has closed */
    107   if (pe->rfd<0 && !pe->pid && !pe->winactive) {
    108     owl_muxevents_remove(owl_global_get_muxevents(&g), handle);
    109     owl_function_debugmsg("unref of %p from input handler at A", pe);
    110     owl_popexec_unref(pe);
     107  if (!pe->pid && !pe->winactive) {
     108    owl_select_remove_dispatch(d->fd);
    111109    return;
    112110  }
    113111
    114   if (0 != (rv_navail = ioctl(fd, FIONREAD, (void*)&navail))) {
     112  if (0 != (rv_navail = ioctl(d->fd, FIONREAD, (void*)&navail))) {
    115113    owl_function_debugmsg("ioctl error");
    116114  }
     
    125123      owl_viewwin_redisplay(pe->vwin, 1);
    126124    }
    127     if (pe->rfd>0) {
    128       close(pe->rfd);
    129       pe->rfd = -1;
    130     }
    131     owl_muxevents_remove(owl_global_get_muxevents(&g), handle);
    132     owl_function_debugmsg("unref of %p from input handler at B", pe);
    133     owl_popexec_unref(pe);
     125    owl_select_remove_dispatch(d->fd);
    134126    return;
    135127  }
    136128
    137   if (pe->rfd<0 || !pe->pid || !pe->winactive || rv_navail) {
     129  if (d->fd<0 || !pe->pid || !pe->winactive || rv_navail) {
    138130    owl_function_error("popexec should not have reached this point");
    139131    return;
     
    143135  if (navail>1024) { navail = 1024; }
    144136  buf = owl_malloc(navail+1);
    145   owl_function_debugmsg("about to read %d\n", navail);
    146   bread = read(fd, buf, navail);
     137  owl_function_debugmsg("about to read %d", navail);
     138  bread = read(d->fd, buf, navail);
    147139  if (bread<0) {
    148140    perror("read");
     
    152144    buf[navail] = '\0';
    153145  }
    154   owl_function_debugmsg("got data:  <%s>\n", buf);
     146  owl_function_debugmsg("got data:  <%s>", buf);
    155147  if (pe->winactive) {
    156148    owl_viewwin_append_text(pe->vwin, buf);
     
    161153}
    162154
     155void owl_popexec_free_dispatch(owl_dispatch *d)
     156{
     157  owl_popexec *pe = d->data;
     158  close(d->fd);
     159  owl_popexec_unref(pe);
     160}
     161
    163162void owl_popexec_viewwin_onclose(owl_viewwin *vwin, void *data)
    164163{
     
    167166
    168167  pe->winactive = 0;
    169   if (pe->rfd>0) {
    170     close(pe->rfd);
    171     pe->rfd = -1;
     168  if (pe->dispatch.fd>0) {
     169    owl_select_remove_dispatch(pe->dispatch.fd);
    172170  }
    173171  if (pe->pid) {
Note: See TracChangeset for help on using the changeset viewer.