Changeset f36cd97


Ignore:
Timestamp:
Dec 17, 2008, 5:12:37 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:
1895c29
Parents:
1631825
git-author:
Nelson Elhage <nelhage@mit.edu> (12/17/08 15:44:15)
git-committer:
Nelson Elhage <nelhage@mit.edu> (12/17/08 17:12:37)
Message:
Add a void* data to owl_dispatch and pass it around.

Add a void* data field for the use of dispatches, and pass around the
owl_dispatch. This allows one dispatch function to be used for
multiple fd's, and lets us eliminate perl-specific code from the
dispatch loop. In addition, we need to add a destructor to
owl_dispatch so that perl dispatches can have their SV* decref'd on
destroy.
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • owl.c

    rc675b39 rf36cd97  
    190190    d->fd = STDIN;
    191191    d->cfunc = &owl_process_input;
    192     d->pfunc = NULL;
     192    d->destroy = NULL;
    193193    owl_select_add_dispatch(d);
    194194  }
     
    201201    d->fd = ZGetFD();
    202202    d->cfunc = &owl_zephyr_process_events;
    203     d->pfunc = NULL;
     203    d->destroy = NULL;
    204204    owl_select_add_dispatch(d);
    205205    owl_global_set_havezephyr(&g);
     
    401401
    402402
    403 #ifdef HAVE_LIBZEPHYR
    404   /* Check for any zephyrs that have come in while we've done init. */
    405   owl_zephyr_process_events();
    406 #endif
    407  
    408403  owl_function_debugmsg("startup: entering main loop");
    409404  /* main loop */
     
    609604}
    610605
    611 void owl_process_input()
     606void owl_process_input(owl_dispatch *d)
    612607{
    613608  int ret;
  • owl.h

    rc675b39 rf36cd97  
    526526
    527527typedef struct _owl_dispatch {
    528   int fd;           /* FD to watch for dispatch. */
    529   void (*cfunc)();  /* C function to dispatch to. */
    530   SV *pfunc;        /* Perl function to dispatch to. */
     528  int fd;                                 /* FD to watch for dispatch. */
     529  void (*cfunc)(struct _owl_dispatch*);   /* C function to dispatch to. */
     530  void (*destroy)(struct _owl_dispatch*); /* Destructor */
     531  void *data;
    531532} owl_dispatch;
    532533
  • perlconfig.c

    r1631825 rf36cd97  
    446446void owl_perlconfig_dispatch_free(owl_dispatch *d)
    447447{
    448   SvREFCNT_dec(d->pfunc);
     448  SvREFCNT_dec(d->data);
    449449}
    450450
     
    494494}
    495495
    496 void owl_perlconfig_do_dispatch(owl_dispatch *d)
    497 {
    498   SV *cb = d->pfunc;
     496void owl_perlconfig_dispatch(owl_dispatch *d)
     497{
     498  SV *cb = d->data;
    499499  dSP;
    500500  if(cb == NULL) {
    501501    owl_function_error("Perl callback is NULL!");
     502    return;
    502503  }
    503504
  • select.c

    rc675b39 rf36cd97  
    133133    d = (owl_dispatch*)owl_list_get_element(dl, elt);
    134134    owl_list_remove_element(dl, elt);
    135     if (d->pfunc) {
    136       owl_perlconfig_dispatch_free(d);
     135    if (d->destroy) {
     136      d->destroy(d);
    137137    }
    138138    owl_free(d);
     
    152152  if (elt != -1) {
    153153    d = (owl_dispatch*)owl_list_get_element(owl_global_get_dispatchlist(&g), elt);
    154     if (d->pfunc == NULL) {
     154    if (d->cfunc != owl_perlconfig_dispatch) {
    155155      /* don't mess with non-perl dispatch functions from here. */
    156156      return 1;
     
    160160  d = malloc(sizeof(owl_dispatch));
    161161  d->fd = fd;
    162   d->cfunc = NULL;
    163   d->pfunc = cb;
     162  d->cfunc = owl_perlconfig_dispatch;
     163  d->destroy = owl_perlconfig_dispatch_free;
     164  d->data = cb;
    164165  owl_select_add_dispatch(d);
    165166  return 0;
     
    174175  if (elt != -1) {
    175176    d = (owl_dispatch*)owl_list_get_element(owl_global_get_dispatchlist(&g), elt);
    176     if (d->pfunc != NULL) {
     177    if (d->cfunc == owl_perlconfig_dispatch) {
    177178      owl_select_remove_dispatch(fd);
    178179      return 0;
     
    216217    if (d != NULL && FD_ISSET(d->fd, fds)) {
    217218      if (d->cfunc != NULL) {
    218         (d->cfunc)();
    219       }
    220       else if (d->pfunc != NULL) {
    221         owl_perlconfig_do_dispatch(d);
     219        d->cfunc(d);
    222220      }
    223221    }
  • zephyr.c

    rb9cb41b rf36cd97  
    12031203
    12041204#ifdef HAVE_LIBZEPHYR
    1205 void owl_zephyr_process_events() {
     1205void owl_zephyr_process_events(owl_dispatch *d) {
    12061206  int zpendcount=0;
    12071207  ZNotice_t notice;
     
    12351235
    12361236#else
    1237 void owl_zephyr_process_events() {
    1238  
    1239 }
    1240 #endif
     1237void owl_zephyr_process_events(owl_dispatch *d) {
     1238 
     1239}
     1240#endif
Note: See TracChangeset for help on using the changeset viewer.