Changeset a01ed7c


Ignore:
Timestamp:
Oct 27, 2009, 2:15:08 PM (12 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7ca5d3e
Parents:
e7f5970 (diff), f1a2736 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge branch 'io_dispatch_rewrite'
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • global.c

    r23fddad r6fc40a7  
    112112
    113113  owl_message_init_fmtext_cache();
    114   owl_list_create(&(g->dispatchlist));
     114  owl_list_create(&(g->io_dispatch_list));
    115115  owl_list_create(&(g->psa_list));
    116116  g->timerlist = NULL;
     
    940940}
    941941
    942 owl_list *owl_global_get_dispatchlist(owl_global *g)
    943 {
    944   return &(g->dispatchlist);
     942owl_list *owl_global_get_io_dispatch_list(owl_global *g)
     943{
     944  return &(g->io_dispatch_list);
    945945}
    946946
  • owl.c

    r23fddad r18fdd5f9  
    315315}
    316316
    317 void owl_process_input(owl_dispatch *d)
     317void owl_process_input(const owl_io_dispatch *d, void *data)
    318318{
    319319  owl_input j;
     
    444444
    445445/* Sends stderr (read from rfd) messages to the error console */
    446 void stderr_redirect_handler(owl_dispatch *d)
     446void stderr_redirect_handler(const owl_io_dispatch *d, void *data)
    447447{
    448448  int navail, bread;
     
    521521  owl_global_set_haveaim(&g);
    522522
    523   /* prepare stdin dispatch */
    524   {
    525     owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
    526     d->fd = STDIN;
    527     d->cfunc = &owl_process_input;
    528     d->destroy = NULL;
    529     owl_select_add_dispatch(d);
    530   }
    531 
     523  /* register STDIN dispatch; throw away return, we won't need it */
     524  owl_select_add_io_dispatch(STDIN, OWL_IO_READ, &owl_process_input, NULL, NULL);
    532525  owl_zephyr_initialize();
    533526
    534527#if OWL_STDERR_REDIR
    535528  /* Do this only after we've started curses up... */
    536   {
    537     owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
    538     owl_function_debugmsg("startup: doing stderr redirection");
    539     d->fd = stderr_replace();
    540     d->cfunc = stderr_redirect_handler;
    541     d->destroy = NULL;
    542     owl_select_add_dispatch(d);
    543   }
     529  owl_function_debugmsg("startup: doing stderr redirection");
     530  owl_select_add_io_dispatch(stderr_replace(), OWL_IO_READ, &stderr_redirect_handler, NULL, NULL);
    544531#endif
    545532
  • owl.h

    r68c572a ra01ed7c  
    107107#define OWL_MESSAGE_DIRECTION_OUT   2
    108108
    109 #define OWL_MUX_READ   1
    110 #define OWL_MUX_WRITE  2
    111 #define OWL_MUX_EXCEPT 4
     109#define OWL_IO_READ   1
     110#define OWL_IO_WRITE  2
     111#define OWL_IO_EXCEPT 4
    112112
    113113#define OWL_DIRECTION_NONE      0
     
    503503} owl_obarray;
    504504
    505 typedef struct _owl_dispatch {
    506   int fd;                                 /* FD to watch for dispatch. */
     505typedef struct _owl_io_dispatch {
     506  int fd;                                     /* FD to watch for dispatch. */
     507  int mode;
    507508  int needs_gc;
    508   void (*cfunc)(struct _owl_dispatch*);  /* C function to dispatch to. */
    509   void (*destroy)(struct _owl_dispatch*); /* Destructor */
     509  void (*callback)(const struct _owl_io_dispatch *, void *); /* C function to dispatch to. */
     510  void (*destroy)(const struct _owl_io_dispatch *); /* Destructor */
    510511  void *data;
    511 } owl_dispatch;
     512} owl_io_dispatch;
    512513
    513514typedef struct _owl_ps_action {
     
    523524  int winactive;
    524525  pid_t pid;                    /* or 0 if it has terminated */
    525   owl_dispatch dispatch;
     526  const owl_io_dispatch *dispatch;
    526527} owl_popexec;
    527528
     
    596597  struct termios startup_tio;
    597598  owl_obarray obarray;
    598   owl_list dispatchlist;
     599  owl_list io_dispatch_list;
    599600  owl_list psa_list;
    600601  GList *timerlist;
  • perl/lib/BarnOwl.pm

    r3c428d4 rffc4df6  
    1313                    error debug
    1414                    create_style getnumcolors wordwrap
    15                     add_dispath remove_dispatch
     15                    add_dispatch remove_dispatch
     16                    add_io_dispatch remove_io_dispatch
    1617                    new_command
    1718                    new_variable_int new_variable_bool new_variable_string
     
    6263Returns the current message as a C<BarnOwl::Message> subclass, or
    6364undef if there is no message selected
    64 
    6565=head2 getnumcols
    6666
     
    160160read from C<FD>.
    161161
     162C<add_dispatch> has been deprecated in favor of C<add_io_dispatch>,
     163and is now a wrapper for it called with C<mode> set to C<'r'>.
     164
     165=cut
     166
     167sub add_dispatch {
     168    my $fd = shift;
     169    my $cb = shift;
     170    add_io_dispatch($fd, 'r', $cb);
     171}
     172
    162173=head2 remove_dispatch FD
    163174
    164175Remove a file descriptor previously registered via C<add_dispatch>
     176
     177C<remove_dispatch> has been deprecated in favor of
     178C<remove_io_dispatch>.
     179
     180=cut
     181
     182*remove_dispatch = \&remove_io_dispatch;
     183
     184=head2 add_io_dispatch FD MODE CB
     185
     186Adds a file descriptor to C<BarnOwl>'s internal C<select()>
     187loop. <MODE> can be 'r', 'w', or 'rw'. C<CALLBACK> will be invoked
     188whenever C<FD> becomes ready, as specified by <MODE>.
     189
     190Only one callback can be registered per FD. If a new callback is
     191registered, the old one is removed.
     192
     193=cut
     194
     195sub add_io_dispatch {
     196    my $fd = shift;
     197    my $modeStr = shift;
     198    my $cb = shift;
     199    my $mode = 0;
     200
     201    $mode |= 0x1 if ($modeStr =~ /r/i); # Read
     202    $mode |= 0x2 if ($modeStr =~ /w/i); # Write
     203    if ($mode) {
     204        $mode |= 0x4;                  # Exceptional
     205        BarnOwl::Internal::add_io_dispatch($fd, $mode, $cb);
     206    } else {
     207        die("Invalid I/O Dispatch mode: $modeStr");
     208    }
     209}
     210
     211=head2 remove_io_dispatch FD
     212
     213Remove a file descriptor previously registered via C<add_io_dispatch>
    165214
    166215=head2 create_style NAME OBJECT
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    rda554da rf1a2736  
    381381        $ircnets{$alias} = $conn;
    382382        my $fd = $conn->getSocket()->fileno();
    383         BarnOwl::add_dispatch($fd, \&OwlProcess);
     383        BarnOwl::add_io_dispatch($fd, 'r', \&OwlProcess);
    384384        $conn->{FD} = $fd;
    385385    } else {
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r7cfb1df rf1a2736  
    210210        }
    211211    }
    212     BarnOwl::remove_dispatch($self->{FD});
     212    BarnOwl::remove_io_dispatch($self->{FD});
    213213    BarnOwl::admin_message('IRC',
    214214                           "[" . $self->alias . "] Disconnected from server");
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    rf3678c3 rf1a2736  
    471471                $conn->renameConnection($jidStr, $fullJid);
    472472                queue_admin_msg("Connected to jabber as $fullJid");
    473                 # The remove_dispatch() method is called from the
     473                # The remove_io_dispatch() method is called from the
    474474                # ConnectionManager's removeConnection() method.
    475475                $client->{fileno} = $client->getSocket()->fileno();
    476476                #queue_admin_msg("Connected to jabber as $fullJid ($client->{fileno})");
    477                 BarnOwl::add_dispatch($client->{fileno}, sub { $client->OwlProcess($fullJid) });
     477                BarnOwl::add_io_dispatch($client->{fileno}, 'r', sub { $client->OwlProcess($fullJid) });
    478478
    479479                # populate completion from roster.
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm

    r8590774 rf1a2736  
    3737    return 0 unless exists $self->{$jidStr};
    3838
    39     BarnOwl::remove_dispatch($self->{$jidStr}->{Client}->{fileno}) if $self->{$jidStr}->{Client}->{fileno};
     39    BarnOwl::remove_io_dispatch($self->{$jidStr}->{Client}->{fileno}) if $self->{$jidStr}->{Client}->{fileno};
    4040    $self->{$jidStr}->{Client}->Disconnect()
    4141      if $self->{$jidStr}->{Client};
     
    5555    }
    5656
    57     BarnOwl::remove_dispatch($self->{$jidStr}->{Client}->{fileno}) if $self->{$jidStr}->{Client}->{fileno};
     57    BarnOwl::remove_io_dispatch($self->{$jidStr}->{Client}->{fileno}) if $self->{$jidStr}->{Client}->{fileno};
    5858    $self->{$jidStr}->{Client}->Disconnect()
    5959      if $self->{$jidStr}->{Client};
  • perlconfig.c

    re7f5970 ra01ed7c  
    542542}
    543543
    544 void owl_perlconfig_dispatch_free(owl_dispatch *d)
     544void owl_perlconfig_io_dispatch_destroy(const owl_io_dispatch *d)
    545545{
    546546  SvREFCNT_dec(d->data);
    547   owl_free(d);
    548547}
    549548
     
    593592}
    594593
    595 void owl_perlconfig_dispatch(owl_dispatch *d)
    596 {
    597   SV *cb = d->data;
     594void owl_perlconfig_io_dispatch(const owl_io_dispatch *d, void *data)
     595{
     596  SV *cb = data;
    598597  dSP;
    599598  if(cb == NULL) {
     
    607606  PUSHMARK(SP);
    608607  PUTBACK;
    609  
     608
    610609  call_sv(cb, G_DISCARD|G_KEEPERR|G_EVAL);
    611610
  • perlglue.xs

    rfe7616e ra01ed7c  
    318318
    319319void
    320 add_dispatch(fd, cb)
     320remove_io_dispatch(fd)
    321321        int fd
    322         SV * cb
    323         CODE:
    324         owl_select_add_perl_dispatch(fd, SvREFCNT_inc(cb));
    325 
    326 void
    327 remove_dispatch(fd)
    328         int fd
    329         CODE:
    330         owl_select_remove_perl_dispatch(fd);
    331 
     322        CODE:
     323        owl_select_remove_perl_io_dispatch(fd);
    332324
    333325AV*
     
    504496                                      ival);
    505497
     498void
     499add_io_dispatch(fd, mode, cb)
     500        int fd
     501        int mode
     502        SV * cb
     503        CODE:
     504        owl_select_add_perl_io_dispatch(fd, mode, SvREFCNT_inc(cb));
     505
    506506IV
    507507add_timer(after, interval, cb)
  • popexec.c

    r0e5afa2 r18fdd5f9  
    5353    pe->pid=pid;
    5454    pe->winactive=1;
    55     pe->dispatch.fd = parent_read_fd;
    56     pe->dispatch.cfunc = owl_popexec_inputhandler;
    57     pe->dispatch.destroy = owl_popexec_free_dispatch;
    58     pe->dispatch.data = pe;
    59     owl_select_add_dispatch(&pe->dispatch);
     55    pe->dispatch = owl_select_add_io_dispatch(parent_read_fd, OWL_IO_READ|OWL_IO_EXCEPT, &owl_popexec_inputhandler, &owl_popexec_delete_dispatch, pe);
    6056    pe->refcount++;
    6157  } else {
     
    7874}
    7975
    80 void owl_popexec_inputhandler(owl_dispatch *d)
     76void owl_popexec_inputhandler(const owl_io_dispatch *d, void *data)
    8177{
    82   owl_popexec *pe = d->data;
     78  owl_popexec *pe = data;
    8379  int navail, bread, rv_navail;
    8480  char *buf;
     
    9995  /* the viewwin has closed */
    10096  if (!pe->pid && !pe->winactive) {
    101     owl_select_remove_dispatch(d->fd);
     97    owl_select_remove_io_dispatch(d);
    10298    return;
    10399  }
     
    116112      owl_viewwin_redisplay(pe->vwin, 1);
    117113    }
    118     owl_select_remove_dispatch(d->fd);
     114    owl_select_remove_io_dispatch(d);
    119115    return;
    120116  }
     
    146142}
    147143
    148 void owl_popexec_free_dispatch(owl_dispatch *d)
     144void owl_popexec_delete_dispatch(const owl_io_dispatch *d)
    149145{
    150146  owl_popexec *pe = d->data;
     
    159155
    160156  pe->winactive = 0;
    161   if (pe->dispatch.fd>0) {
    162     owl_select_remove_dispatch(pe->dispatch.fd);
     157  if (pe->dispatch->fd > 0) {
     158    owl_select_remove_io_dispatch(pe->dispatch);
    163159  }
    164160  if (pe->pid) {
  • select.c

    r4f2166b r6fc40a7  
    8181}
    8282
    83 /* Returns the index of the dispatch for the file descriptor. */
    84 int owl_select_find_dispatch(int fd)
     83static const owl_io_dispatch *owl_select_find_io_dispatch_by_fd(const int fd)
    8584{
    8685  int i, len;
    8786  const owl_list *dl;
    88   const owl_dispatch *d;
    89  
    90   dl = owl_global_get_dispatchlist(&g);
     87  owl_io_dispatch *d;
     88  dl = owl_global_get_io_dispatch_list(&g);
    9189  len = owl_list_get_size(dl);
    9290  for(i = 0; i < len; i++) {
    9391    d = owl_list_get_element(dl, i);
    94     if (d->fd == fd) return i;
     92    if (d->fd == fd) return d;
     93  }
     94  return NULL;
     95}
     96
     97static int owl_select_find_io_dispatch(const owl_io_dispatch *in)
     98{
     99  int i, len;
     100  const owl_list *dl;
     101
     102  if (in != NULL) {
     103    dl = owl_global_get_io_dispatch_list(&g);
     104    len = owl_list_get_size(dl);
     105    for(i = 0; i < len; i++) {
     106      const owl_io_dispatch *d = owl_list_get_element(dl, i);
     107      if (d == in) return i;
     108    }
    95109  }
    96110  return -1;
    97111}
    98112
    99 void owl_select_remove_dispatch_at(int elt) /* noproto */
    100 {
    101   owl_list *dl;
    102   owl_dispatch *d;
    103 
    104   dl = owl_global_get_dispatchlist(&g);
    105   d = owl_list_get_element(dl, elt);
    106   owl_list_remove_element(dl, elt);
    107   if (d->destroy) {
    108     d->destroy(d);
    109   }
    110 }
    111 
    112 /* Adds a new owl_dispatch to the list, replacing existing ones if needed. */
    113 void owl_select_add_dispatch(owl_dispatch *d)
     113void owl_select_remove_io_dispatch(const owl_io_dispatch *in)
    114114{
    115115  int elt;
    116   owl_list *dl;
    117 
    118   d->needs_gc = 0;
    119 
    120   elt = owl_select_find_dispatch(d->fd);
    121   dl = owl_global_get_dispatchlist(&g);
    122  
    123   if (elt != -1) {  /* If we have a dispatch for this FD */
    124     owl_dispatch *d_old;
    125     d_old = owl_list_get_element(dl, elt);
    126     /* Ignore if we're adding the same dispatch again.  Otherwise
    127        replace the old dispatch. */
    128     if (d_old != d) {
    129       owl_select_remove_dispatch_at(elt);
    130     }
    131   }
    132   owl_list_append_element(dl, d);
    133 }
    134 
    135 /* Removes an owl_dispatch to the list, based on it's file descriptor. */
    136 void owl_select_remove_dispatch(int fd)
    137 {
    138   int elt;
    139   owl_list *dl;
    140   owl_dispatch *d;
    141 
    142   elt = owl_select_find_dispatch(fd);
    143   if(elt == -1) {
    144     return;
    145   } else if(dispatch_active) {
    146     /* Defer the removal until dispatch is done walking the list */
    147     dl = owl_global_get_dispatchlist(&g);
    148     d = owl_list_get_element(dl, elt);
    149     d->needs_gc = 1;
    150   } else {
    151     owl_select_remove_dispatch_at(elt);
    152   }
    153 }
    154 
    155 int owl_select_dispatch_count(void)
    156 {
    157   return owl_list_get_size(owl_global_get_dispatchlist(&g));
    158 }
    159 
    160 int owl_select_add_perl_dispatch(int fd, SV *cb)
    161 {
    162   int elt;
    163   owl_dispatch *d;
    164   elt = owl_select_find_dispatch(fd);
    165   if (elt != -1) {
    166     d = owl_list_get_element(owl_global_get_dispatchlist(&g), elt);
    167     if (d->cfunc != owl_perlconfig_dispatch) {
    168       /* don't mess with non-perl dispatch functions from here. */
    169       return 1;
    170     }
    171   }
    172 
    173   d = owl_malloc(sizeof(owl_dispatch));
    174   d->fd = fd;
    175   d->cfunc = owl_perlconfig_dispatch;
    176   d->destroy = owl_perlconfig_dispatch_free;
    177   d->data = cb;
    178   owl_select_add_dispatch(d);
    179   return 0;
    180 }
    181 
    182 int owl_select_remove_perl_dispatch(int fd)
    183 {
    184   int elt;
    185   owl_dispatch *d;
    186  
    187   elt = owl_select_find_dispatch(fd);
    188   if (elt != -1) {
    189     d = owl_list_get_element(owl_global_get_dispatchlist(&g), elt);
    190     if (d->cfunc == owl_perlconfig_dispatch) {
    191       owl_select_remove_dispatch_at(elt);
    192       return 0;
    193     }
    194   }
    195   return 1;
    196 }
    197 
    198 int owl_select_dispatch_prepare_fd_sets(fd_set *r, fd_set *e)
    199 {
    200   int i, len, max_fd;
    201   owl_dispatch *d;
    202   const owl_list *dl;
    203 
    204   dl = owl_global_get_dispatchlist(&g);
    205   FD_ZERO(r);
    206   FD_ZERO(e);
    207   max_fd = 0;
    208   len = owl_select_dispatch_count();
    209   for(i = 0; i < len; i++) {
    210     d = owl_list_get_element(dl, i);
    211     FD_SET(d->fd, r);
    212     FD_SET(d->fd, e);
    213     if (max_fd < d->fd) max_fd = d->fd;
    214   }
    215   return max_fd + 1;
    216 }
    217 
    218 void owl_select_gc(void)
     116  if (in != NULL) {
     117    elt = owl_select_find_io_dispatch(in);
     118    if (elt != -1) {
     119      owl_list *dl = owl_global_get_io_dispatch_list(&g);
     120      owl_io_dispatch *d = owl_list_get_element(dl, elt);
     121      if (dispatch_active)
     122        d->needs_gc = 1;
     123      else {
     124        owl_list_remove_element(dl, elt);
     125        if (d->destroy)
     126          d->destroy(d);
     127        owl_free(d);
     128      }
     129    }
     130  }
     131}
     132
     133void owl_select_io_dispatch_gc(void)
    219134{
    220135  int i;
    221136  owl_list *dl;
    222137
    223   dl = owl_global_get_dispatchlist(&g);
     138  dl = owl_global_get_io_dispatch_list(&g);
    224139  /*
    225140   * Count down so we aren't set off by removing items from the list
     
    227142   */
    228143  for(i = owl_list_get_size(dl) - 1; i >= 0; i--) {
    229     const owl_dispatch *d = owl_list_get_element(dl, i);
     144    owl_io_dispatch *d = owl_list_get_element(dl, i);
    230145    if(d->needs_gc) {
    231       owl_select_remove_dispatch_at(i);
    232     }
    233   }
    234 }
    235 
    236 void owl_select_dispatch(fd_set *fds, int max_fd)
     146      owl_select_remove_io_dispatch(d);
     147    }
     148  }
     149}
     150
     151/* Each FD may have at most one dispatcher.
     152 * If a new dispatch is added for an FD, the old one is removed.
     153 * mode determines what types of events are watched for, and may be any combination of:
     154 * OWL_IO_READ, OWL_IO_WRITE, OWL_IO_EXCEPT
     155 */
     156const owl_io_dispatch *owl_select_add_io_dispatch(int fd, int mode, void (*cb)(const owl_io_dispatch *, void *), void (*destroy)(const owl_io_dispatch *), void *data)
     157{
     158  owl_io_dispatch *d = owl_malloc(sizeof(owl_io_dispatch));
     159  owl_list *dl = owl_global_get_io_dispatch_list(&g);
     160
     161  d->fd = fd;
     162  d->needs_gc = 0;
     163  d->mode = mode;
     164  d->callback = cb;
     165  d->destroy = destroy;
     166  d->data = data;
     167
     168  owl_select_remove_io_dispatch(owl_select_find_io_dispatch_by_fd(fd));
     169  owl_list_append_element(dl, d);
     170
     171  return d;
     172}
     173
     174int owl_select_prepare_io_dispatch_fd_sets(fd_set *rfds, fd_set *wfds, fd_set *efds) {
     175  int i, len, max_fd;
     176  owl_io_dispatch *d;
     177  owl_list *dl = owl_global_get_io_dispatch_list(&g);
     178
     179  max_fd = 0;
     180  len = owl_list_get_size(dl);
     181  for (i = 0; i < len; i++) {
     182    d = owl_list_get_element(dl, i);
     183    if (d->mode & (OWL_IO_READ | OWL_IO_WRITE | OWL_IO_EXCEPT)) {
     184      if (max_fd < d->fd) max_fd = d->fd;
     185      if (d->mode & OWL_IO_READ) FD_SET(d->fd, rfds);
     186      if (d->mode & OWL_IO_WRITE) FD_SET(d->fd, wfds);
     187      if (d->mode & OWL_IO_EXCEPT) FD_SET(d->fd, efds);
     188    }
     189  }
     190  return max_fd + 1;
     191}
     192
     193void owl_select_io_dispatch(const fd_set *rfds, const fd_set *wfds, const fd_set *efds, const int max_fd)
    237194{
    238195  int i, len;
    239   owl_dispatch *d;
    240   const owl_list *dl;
    241 
    242   dl = owl_global_get_dispatchlist(&g);
    243   len = owl_select_dispatch_count();
     196  owl_io_dispatch *d;
     197  owl_list *dl = owl_global_get_io_dispatch_list(&g);
    244198
    245199  dispatch_active = 1;
    246 
    247   for(i = 0; i < len; i++) {
     200  len = owl_list_get_size(dl);
     201  for (i = 0; i < len; i++) {
    248202    d = owl_list_get_element(dl, i);
    249     /* While d shouldn't normally be null, the list may be altered by
    250      * functions we dispatch to. */
    251     if (d != NULL && !d->needs_gc && FD_ISSET(d->fd, fds)) {
    252       if (d->cfunc != NULL) {
    253         d->cfunc(d);
    254       }
    255     }
    256   }
    257 
     203    if (d->fd < max_fd && d->callback != NULL &&
     204        ((d->mode & OWL_IO_READ && FD_ISSET(d->fd, rfds)) ||
     205         (d->mode & OWL_IO_WRITE && FD_ISSET(d->fd, wfds)) ||
     206         (d->mode & OWL_IO_EXCEPT && FD_ISSET(d->fd, efds)))) {
     207      d->callback(d, d->data);
     208    }
     209  }
    258210  dispatch_active = 0;
    259   owl_select_gc();
     211  owl_select_io_dispatch_gc();
     212}
     213
     214int owl_select_add_perl_io_dispatch(int fd, int mode, SV *cb)
     215{
     216  const owl_io_dispatch *d = owl_select_find_io_dispatch_by_fd(fd);
     217  if (d != NULL && d->callback != owl_perlconfig_io_dispatch) {
     218    /* Don't mess with non-perl dispatch functions from here. */
     219    return 1;
     220  }
     221  owl_select_add_io_dispatch(fd, mode, owl_perlconfig_io_dispatch, owl_perlconfig_io_dispatch_destroy, cb);
     222  return 0;
     223}
     224
     225int owl_select_remove_perl_io_dispatch(int fd)
     226{
     227  const owl_io_dispatch *d = owl_select_find_io_dispatch_by_fd(fd);
     228  if (d != NULL && d->callback == owl_perlconfig_io_dispatch) {
     229    /* Only remove perl io dispatchers from here. */
     230    owl_select_remove_io_dispatch(d);
     231    return 0;
     232  }
     233  return 1;
    260234}
    261235
     
    266240  int max_fd;
    267241
    268   FD_ZERO(rfds);
    269   FD_ZERO(wfds);
    270242  max_fd = 0;
    271243  sess = owl_global_get_aimsess(&g);
     
    414386void owl_select(void)
    415387{
    416   int i, max_fd, aim_max_fd, aim_done, ret;
     388  int i, max_fd, max_fd2, aim_done, ret;
    417389  fd_set r;
     390  fd_set w;
    418391  fd_set e;
    419392  fd_set aim_rfds, aim_wfds;
     
    430403    return;
    431404  }
    432 
    433   max_fd = owl_select_dispatch_prepare_fd_sets(&r, &e);
     405  FD_ZERO(&r);
     406  FD_ZERO(&w);
     407  FD_ZERO(&e);
     408
     409  max_fd = owl_select_prepare_io_dispatch_fd_sets(&r, &w, &e);
    434410
    435411  /* AIM HACK:
     
    448424  if (owl_global_is_doaimevents(&g)) {
    449425    aim_done = 0;
    450     aim_max_fd = owl_select_aim_hack(&aim_rfds, &aim_wfds);
    451     if (max_fd < aim_max_fd) max_fd = aim_max_fd;
    452     for(i = 0; i <= aim_max_fd; i++) {
     426    max_fd2 = owl_select_aim_hack(&aim_rfds, &aim_wfds);
     427    if (max_fd < max_fd2) max_fd = max_fd2;
     428    for(i = 0; i <= max_fd2; i++) {
    453429      if (FD_ISSET(i, &aim_rfds)) {
    454430        FD_SET(i, &r);
    455431        FD_SET(i, &e);
    456432      }
     433      if (FD_ISSET(i, &aim_wfds)) {
     434        FD_SET(i, &w);
     435        FD_SET(i, &e);
     436      }
    457437    }
    458438  }
     
    464444  }
    465445
    466   ret = pselect(max_fd+1, &r, &aim_wfds, &e, &timeout, &mask);
     446  ret = pselect(max_fd+1, &r, &w, &e, &timeout, &mask);
    467447
    468448  if(ret < 0 && errno == EINTR) {
     
    482462      /* Merge all interesting FDs into one set, since we have a
    483463         single dispatch per FD. */
    484       if (FD_ISSET(i, &r) || FD_ISSET(i, &aim_wfds) || FD_ISSET(i, &e)) {
     464      if (FD_ISSET(i, &r) || FD_ISSET(i, &w) || FD_ISSET(i, &e)) {
    485465        /* AIM HACK: no separate dispatch, just process here if
    486466           needed, and only once per run through. */
     
    496476    /* NOTE: the same dispatch function is called for both exceptional
    497477       and read ready FDs. */
    498     owl_select_dispatch(&r, max_fd);
    499   }
    500 }
     478    owl_select_io_dispatch(&r, &w, &e, max_fd);
     479  }
     480}
  • zephyr.c

    r12e291a r18fdd5f9  
    3636  ZNotice_t req;
    3737  Code_t code;
    38   owl_dispatch *dispatch;
    3938
    4039  /*
     
    8079  }
    8180
    82   dispatch = owl_malloc(sizeof(*dispatch));
    83   dispatch->fd = ZGetFD();
    84   dispatch->cfunc = owl_zephyr_finish_initialization;
    85   dispatch->destroy = (void(*)(owl_dispatch*))owl_free;
    86 
    87   owl_select_add_dispatch(dispatch);
    88 }
    89 
    90 void owl_zephyr_finish_initialization(owl_dispatch *d) {
     81  owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_finish_initialization, NULL, NULL);
     82}
     83
     84void owl_zephyr_finish_initialization(const owl_io_dispatch *d, void *data) {
    9185  Code_t code;
    9286  char *perl;
    9387
    94   owl_select_remove_dispatch(d->fd);
     88  owl_select_remove_io_dispatch(d);
    9589
    9690  ZClosePort();
     
    106100  }
    107101
    108   d = owl_malloc(sizeof(owl_dispatch));
    109   d->fd = ZGetFD();
    110   d->cfunc = &owl_zephyr_process_events;
    111   d->destroy = NULL;
    112   owl_select_add_dispatch(d);
     102  owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_process_events, NULL, NULL);
     103
    113104  owl_global_set_havezephyr(&g);
    114105
     
    13501341}
    13511342
    1352 void owl_zephyr_process_events(owl_dispatch *d)
     1343void owl_zephyr_process_events(const owl_io_dispatch *d, void *data)
    13531344{
    13541345  _owl_zephyr_process_events();
  • filter.c

    r23fddad r3cc4bfc  
    164164}
    165165
     166SV *owl_filter_to_sv(const owl_filter *f)
     167{
     168  return owl_new_sv(owl_filter_get_name(f));
     169}
     170
    166171void owl_filter_set_fgcolor(owl_filter *f, int color)
    167172{
  • fmtext.c

    r6c171f1 r1ee5c79  
    686686          /* set it as the current color */
    687687          curcolor=owl_util_string_to_color(buff);
    688           if (curcolor==-1) curcolor=OWL_COLOR_DEFAULT;
     688          if (curcolor == OWL_COLOR_INVALID)
     689              curcolor = OWL_COLOR_DEFAULT;
    689690          owl_free(buff);
    690691          txtptr=tmpptr+1;
  • perl/lib/BarnOwl/Complete/Client.pm

    ra3a9eb7 r02a72bf  
    2424    commands    => undef,
    2525    command     => \&complete_command,
     26    errors      => undef,
    2627    filters     => undef,
    2728    filter      => \&complete_filter_name,
    2829    license     => undef,
     30    keymaps     => undef,
     31    keymap      => \&complete_keymap,
    2932    quickstart  => undef,
    3033    startup     => undef,
     
    4548sub complete_variable    { return @{BarnOwl::all_variables()}; }
    4649sub complete_style       { return @{BarnOwl::all_styles()}; }
     50sub complete_keymap      { return @{BarnOwl::all_keymaps()}; }
    4751
    4852sub complete_help {
  • scripts/locker-build

    r130633c r2b6622a6  
    8080    echo "Building BarnOwl version $VERS"
    8181
     82    opt_rpath="-Wl,-R"
     83    [ $(uname) = "SunOS" ] && opt_rpath="-R"
     84
    8285    BARNOWL="/afs/sipb.mit.edu/project/barnowl/arch/$ATHENA_SYS"
    8386    export PKG_CONFIG_PATH="$BARNOWL/lib/pkgconfig"
    8487
    8588    CFLAGS="-I$BARNOWL/include" \
    86         LDFLAGS="-L$BARNOWL/lib -Wl,-R$BARNOWL/lib" \
     89        LDFLAGS="-L$BARNOWL/lib $opt_rpath$BARNOWL/lib" \
    8790        ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \
    8891        --prefix="/mit/barnowl/builds/barnowl-$VERS" --mandir=/mit/barnowl/man \
  • util.c

    r0697f09 r1b9d3cc  
    407407}
    408408
     409/* These are in order of their value in owl.h */
     410static const struct {
     411  int number;
     412  const char *name;
     413} color_map[] = {
     414  {OWL_COLOR_INVALID, "invalid"},
     415  {OWL_COLOR_DEFAULT, "default"},
     416  {OWL_COLOR_BLACK, "black"},
     417  {OWL_COLOR_RED, "red"},
     418  {OWL_COLOR_GREEN, "green"},
     419  {OWL_COLOR_YELLOW,"yellow"},
     420  {OWL_COLOR_BLUE, "blue"},
     421  {OWL_COLOR_MAGENTA, "magenta"},
     422  {OWL_COLOR_CYAN, "cyan"},
     423  {OWL_COLOR_WHITE, "white"},
     424};
    409425
    410426/* Return the owl color associated with the named color.  Return -1
     
    413429int owl_util_string_to_color(const char *color)
    414430{
    415   int c;
    416   if (!strcasecmp(color, "black")) {
    417     return(OWL_COLOR_BLACK);
    418   } else if (!strcasecmp(color, "red")) {
    419     return(OWL_COLOR_RED);
    420   } else if (!strcasecmp(color, "green")) {
    421     return(OWL_COLOR_GREEN);
    422   } else if (!strcasecmp(color, "yellow")) {
    423     return(OWL_COLOR_YELLOW);
    424   } else if (!strcasecmp(color, "blue")) {
    425     return(OWL_COLOR_BLUE);
    426   } else if (!strcasecmp(color, "magenta")) {
    427     return(OWL_COLOR_MAGENTA);
    428   } else if (!strcasecmp(color, "cyan")) {
    429     return(OWL_COLOR_CYAN);
    430   } else if (!strcasecmp(color, "white")) {
    431     return(OWL_COLOR_WHITE);
    432   } else if (!strcasecmp(color, "default")) {
    433     return(OWL_COLOR_DEFAULT);
    434   }
    435   c = atoi(color);
    436   if (c >= -1 && c < COLORS) {
     431  int c, i;
     432  char *p;
     433
     434  for (i = 0; i < (sizeof(color_map)/sizeof(color_map[0])); i++)
     435    if (strcasecmp(color, color_map[i].name) == 0)
     436      return color_map[i].number;
     437
     438  c = strtol(color, &p, 10);
     439  if (p != color && c >= -1 && c < COLORS) {
    437440    return(c);
    438441  }
     
    443446const char *owl_util_color_to_string(int color)
    444447{
    445   if (color==OWL_COLOR_BLACK)   return("black");
    446   if (color==OWL_COLOR_RED)     return("red");
    447   if (color==OWL_COLOR_GREEN)   return("green");
    448   if (color==OWL_COLOR_YELLOW)  return("yellow");
    449   if (color==OWL_COLOR_BLUE)    return("blue");
    450   if (color==OWL_COLOR_MAGENTA) return("magenta");
    451   if (color==OWL_COLOR_CYAN)    return("cyan");
    452   if (color==OWL_COLOR_WHITE)   return("white");
    453   if (color==OWL_COLOR_DEFAULT) return("default");
     448  if (color >= OWL_COLOR_INVALID && color <= OWL_COLOR_WHITE)
     449    return color_map[color - OWL_COLOR_INVALID].name;
    454450  return("Unknown color");
    455451}
Note: See TracChangeset for help on using the changeset viewer.