Changeset dc1edbd


Ignore:
Timestamp:
May 23, 2011, 8:57:46 PM (13 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.8, release-1.9
Children:
117b2ba
Parents:
08e9842
git-author:
David Benjamin <davidben@mit.edu> (02/26/11 16:32:51)
git-committer:
David Benjamin <davidben@mit.edu> (05/23/11 20:57:46)
Message:
Add a GSource for AIM events

The AIM file descriptor hack is somewhat less of a hack now. Remove code
related to the old AIM implementation now that it's been superceded.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • aim.c

    r3472845 rdc1edbd  
    446446}
    447447
    448 int owl_aim_process_events(void)
    449 {
    450   aim_session_t *aimsess;
     448int owl_aim_process_events(aim_session_t *aimsess)
     449{
    451450  aim_conn_t *waitingconn = NULL;
    452451  struct timeval tv;
     
    454453  struct owlfaim_priv *priv;
    455454
    456   aimsess=owl_global_get_aimsess(&g);
    457455  priv = aimsess->aux_data;
    458456
     
    17951793}
    17961794
    1797 void owl_process_aim(void)
    1798 {
    1799   if (owl_global_is_doaimevents(&g)) {
    1800     owl_aim_process_events();
    1801   }
    1802 }
     1795typedef struct _owl_aim_event_source { /*noproto*/
     1796  GSource source;
     1797  aim_session_t *sess;
     1798  GPtrArray *fds;
     1799} owl_aim_event_source;
     1800
     1801static void truncate_pollfd_list(owl_aim_event_source *event_source, int len)
     1802{
     1803  GPollFD *fd;
     1804  int i;
     1805  if (len < event_source->fds->len)
     1806    owl_function_debugmsg("Truncating AIM PollFDs to %d, was %d", len, event_source->fds->len);
     1807  for (i = len; i < event_source->fds->len; i++) {
     1808    fd = event_source->fds->pdata[i];
     1809    g_source_remove_poll(&event_source->source, fd);
     1810    g_free(fd);
     1811  }
     1812  g_ptr_array_remove_range(event_source->fds, len, event_source->fds->len - len);
     1813}
     1814
     1815static gboolean owl_aim_event_source_prepare(GSource *source, int *timeout)
     1816{
     1817  owl_aim_event_source *event_source = (owl_aim_event_source*)source;
     1818  aim_conn_t *cur;
     1819  GPollFD *fd;
     1820  int i;
     1821
     1822  /* AIM HACK:
     1823   *
     1824   *  The problem - I'm not sure where to hook into the owl/faim
     1825   *  interface to keep track of when the AIM socket(s) open and
     1826   *  close. In particular, the bosconn thing throws me off. So,
     1827   *  rather than register particular dispatchers for AIM, I look up
     1828   *  the relevant FDs and add them to select's watch lists, then
     1829   *  check for them individually before moving on to the other
     1830   *  dispatchers. --asedeno
     1831   */
     1832  i = 0;
     1833  for (cur = event_source->sess->connlist; cur; cur = cur->next) {
     1834    if (cur->fd != -1) {
     1835      /* Add new GPollFDs as necessary. */
     1836      if (i == event_source->fds->len) {
     1837        fd = g_new0(GPollFD, 1);
     1838        g_ptr_array_add(event_source->fds, fd);
     1839        g_source_add_poll(source, fd);
     1840        owl_function_debugmsg("Allocated new AIM PollFD, len = %d", event_source->fds->len);
     1841      }
     1842      fd = event_source->fds->pdata[i];
     1843      fd->fd = cur->fd;
     1844      fd->events |= G_IO_IN | G_IO_HUP | G_IO_ERR;
     1845      if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
     1846        /* Yes, we're checking writable sockets here. Without it, AIM
     1847           login is really slow. */
     1848        fd->events |= G_IO_OUT;
     1849      }
     1850      i++;
     1851    }
     1852  }
     1853  /* If the number of GPollFDs went down, clean up. */
     1854  truncate_pollfd_list(event_source, i);
     1855
     1856  *timeout = -1;
     1857  return FALSE;
     1858}
     1859
     1860static gboolean owl_aim_event_source_check(GSource *source)
     1861{
     1862  owl_aim_event_source *event_source = (owl_aim_event_source*)source;
     1863  int i;
     1864
     1865  for (i = 0; i < event_source->fds->len; i++) {
     1866    GPollFD *fd = event_source->fds->pdata[i];
     1867    if (fd->revents & fd->events)
     1868      return TRUE;
     1869  }
     1870  return FALSE;
     1871}
     1872
     1873static gboolean owl_aim_event_source_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
     1874{
     1875  owl_aim_event_source *event_source = (owl_aim_event_source*)source;
     1876  owl_aim_process_events(event_source->sess);
     1877  return TRUE;
     1878}
     1879
     1880static void owl_aim_event_source_finalize(GSource *source)
     1881{
     1882  owl_aim_event_source *event_source = (owl_aim_event_source*)source;
     1883  truncate_pollfd_list(event_source, 0);
     1884  g_ptr_array_free(event_source->fds, TRUE);
     1885}
     1886
     1887static GSourceFuncs aim_event_funcs = {
     1888  owl_aim_event_source_prepare,
     1889  owl_aim_event_source_check,
     1890  owl_aim_event_source_dispatch,
     1891  owl_aim_event_source_finalize,
     1892};
     1893
     1894GSource *owl_aim_event_source_new(aim_session_t *sess)
     1895{
     1896  GSource *source;
     1897  owl_aim_event_source *event_source;
     1898
     1899  source = g_source_new(&aim_event_funcs, sizeof(owl_aim_event_source));
     1900  event_source = (owl_aim_event_source *)source;
     1901  event_source->sess = sess;
     1902  /* TODO: When we depend on glib 2.22+, use g_ptr_array_new_with_free_func. */
     1903  event_source->fds = g_ptr_array_new();
     1904  return source;
     1905}
  • global.c

    r47128d9 rdc1edbd  
    696696}
    697697
    698 int owl_global_is_doaimevents(const owl_global *g)
    699 {
    700   if (g->aim_doprocessing) return(1);
    701   return(0);
     698bool owl_global_is_doaimevents(const owl_global *g)
     699{
     700  return g->aim_event_source != NULL;
    702701}
    703702
    704703void owl_global_set_doaimevents(owl_global *g)
    705704{
    706   g->aim_doprocessing=1;
     705  if (g->aim_event_source)
     706    return;
     707  g->aim_event_source = owl_aim_event_source_new(owl_global_get_aimsess(g));
     708  g_source_attach(g->aim_event_source, NULL);
    707709}
    708710
    709711void owl_global_set_no_doaimevents(owl_global *g)
    710712{
    711   g->aim_doprocessing=0;
     713  if (!g->aim_event_source)
     714    return;
     715  g_source_destroy(g->aim_event_source);
     716  g_source_unref(g->aim_event_source);
     717  g->aim_event_source = NULL;
    712718}
    713719
  • owl.h

    r47128d9 rdc1edbd  
    610610  aim_conn_t bosconn;
    611611  int aim_loggedin;         /* true if currently logged into AIM */
    612   int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
     612  GSource *aim_event_source; /* where we get our AIM events from */
    613613  char *aim_screenname;     /* currently logged in AIM screen name */
    614614  char *aim_screenname_for_filters;     /* currently logged in AIM screen name */
  • select.c

    r257b9c4 rdc1edbd  
    296296}
    297297
    298 int owl_select_aim_hack(fd_set *rfds, fd_set *wfds)
    299 {
    300   aim_conn_t *cur;
    301   aim_session_t *sess;
    302   int max_fd;
    303 
    304   max_fd = 0;
    305   sess = owl_global_get_aimsess(&g);
    306   for (cur = sess->connlist; cur; cur = cur->next) {
    307     if (cur->fd != -1) {
    308       FD_SET(cur->fd, rfds);
    309       if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
    310         /* Yes, we're checking writable sockets here. Without it, AIM
    311            login is really slow. */
    312         FD_SET(cur->fd, wfds);
    313       }
    314      
    315       if (cur->fd > max_fd)
    316         max_fd = cur->fd;
    317     }
    318   }
    319   return max_fd;
    320 }
    321 
    322298void owl_process_input_char(owl_input j)
    323299{
     
    331307}
    332308
    333 #if 0
    334 /* FIXME: Reimplement the AIM hack and handle AIM events. */
    335 void owl_select(void)
    336 {
    337   int i, max_fd, max_fd2, aim_done, ret;
    338   fd_set r;
    339   fd_set w;
    340   fd_set e;
    341   fd_set aim_rfds, aim_wfds;
    342   struct timespec timeout;
    343   sigset_t mask;
    344 
    345   owl_select_process_timers(&timeout);
    346 
    347   owl_select_mask_signals(&mask);
    348 
    349   if(owl_global_is_interrupted(&g)) {
    350     owl_select_handle_intr(&mask);
    351     return;
    352   }
    353   FD_ZERO(&r);
    354   FD_ZERO(&w);
    355   FD_ZERO(&e);
    356 
    357   max_fd = owl_select_prepare_io_dispatch_fd_sets(&r, &w, &e);
    358 
    359   /* AIM HACK:
    360    *
    361    *  The problem - I'm not sure where to hook into the owl/faim
    362    *  interface to keep track of when the AIM socket(s) open and
    363    *  close. In particular, the bosconn thing throws me off. So,
    364    *  rather than register particular dispatchers for AIM, I look up
    365    *  the relevant FDs and add them to select's watch lists, then
    366    *  check for them individually before moving on to the other
    367    *  dispatchers. --asedeno
    368    */
    369   aim_done = 1;
    370   FD_ZERO(&aim_rfds);
    371   FD_ZERO(&aim_wfds);
    372   if (owl_global_is_doaimevents(&g)) {
    373     aim_done = 0;
    374     max_fd2 = owl_select_aim_hack(&aim_rfds, &aim_wfds);
    375     if (max_fd < max_fd2) max_fd = max_fd2;
    376     for(i = 0; i <= max_fd2; i++) {
    377       if (FD_ISSET(i, &aim_rfds)) {
    378         FD_SET(i, &r);
    379         FD_SET(i, &e);
    380       }
    381       if (FD_ISSET(i, &aim_wfds)) {
    382         FD_SET(i, &w);
    383         FD_SET(i, &e);
    384       }
    385     }
    386   }
    387   /* END AIM HACK */
    388 
    389   if (owl_select_do_pre_select_actions()) {
    390     timeout.tv_sec = 0;
    391     timeout.tv_nsec = 0;
    392   }
    393 
    394   ret = pselect(max_fd+1, &r, &w, &e, &timeout, &mask);
    395 
    396   if(ret < 0 && errno == EINTR) {
    397     if(owl_global_is_interrupted(&g)) {
    398       owl_select_handle_intr(NULL);
    399     }
    400     sigprocmask(SIG_SETMASK, &mask, NULL);
    401     return;
    402   }
    403 
    404   sigprocmask(SIG_SETMASK, &mask, NULL);
    405 
    406   if(ret > 0) {
    407     /* AIM HACK: process all AIM events at once. */
    408     for(i = 0; !aim_done && i <= max_fd; i++) {
    409       if (FD_ISSET(i, &r) || FD_ISSET(i, &w) || FD_ISSET(i, &e)) {
    410         if (FD_ISSET(i, &aim_rfds) || FD_ISSET(i, &aim_wfds)) {
    411           owl_process_aim();
    412           aim_done = 1;
    413         }
    414       }
    415     }
    416     owl_select_io_dispatch(&r, &w, &e, max_fd);
    417   }
    418 }
    419 #endif
    420 
    421309void owl_select_init(void)
    422310{
Note: See TracChangeset for help on using the changeset viewer.