Changeset 2f69081 for select.c


Ignore:
Timestamp:
Feb 19, 2008, 1:22:48 AM (13 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
18108b1e, 61abb18
Parents:
9d2f010
Message:
Fixing AIM post select()
File:
1 edited

Legend:

Unmodified
Added
Removed
  • select.c

    r6b580b0 r2f69081  
    105105}
    106106
    107 int owl_select_dispatch_prepare_fd_sets(fd_set *r, fd_set *w, fd_set *e)
     107int owl_select_dispatch_prepare_fd_sets(fd_set *r, fd_set *e)
    108108{
    109109  int i, len, max_fd;
     
    119119    d = (owl_dispatch*)owl_list_get_element(dl, i);
    120120    FD_SET(d->fd, r);
    121     FD_SET(d->fd, w);
    122121    FD_SET(d->fd, e);
    123122    if (max_fd < d->fd) max_fd = d->fd;
     
    149148}
    150149
    151 int owl_select_aim_hack(fd_set *fds)
     150int owl_select_aim_hack(fd_set *rfds, fd_set *wfds)
    152151{
    153152  aim_conn_t *cur;
     
    155154  int max_fd;
    156155
    157   FD_ZERO(fds);
     156  FD_ZERO(rfds);
     157  FD_ZERO(wfds);
    158158  max_fd = 0;
    159159  sess = owl_global_get_aimsess(&g);
    160160  for (cur = sess->connlist, max_fd = 0; cur; cur = cur->next) {
    161161    if (cur->fd != -1) {
    162       FD_SET(cur->fd, fds);
     162      FD_SET(cur->fd, rfds);
     163      if (cur->status & AIM_CONN_STATUS_INPROGRESS) {
     164        /* Yes, we're checking writable sockets here. Without it, AIM
     165           login is really slow. */
     166        FD_SET(cur->fd, wfds);
     167      }
     168     
    163169      if (cur->fd > max_fd)
    164170        max_fd = cur->fd;
    165171    }
    166172  }
    167   cur = owl_global_get_bosconn(&g);
    168   if (cur->fd != -1) {
    169     FD_SET(cur->fd, fds);
    170     if (cur->fd > max_fd)
    171       max_fd = cur->fd;
    172   }
    173  
    174173  return max_fd;
    175174}
     
    179178  int i, max_fd, aim_max_fd, aim_done;
    180179  fd_set r;
    181   fd_set w;
    182180  fd_set e;
    183   fd_set aim_fds;
     181  fd_set aim_rfds, aim_wfds;
    184182  struct timeval timeout;
    185183
     
    187185  timeout.tv_usec = 0;
    188186
    189   max_fd = owl_select_dispatch_prepare_fd_sets(&r, &w, &e);
     187  max_fd = owl_select_dispatch_prepare_fd_sets(&r, &e);
    190188
    191189  /* AIM HACK:
     
    200198   */
    201199  aim_done = 1;
    202   FD_ZERO(&aim_fds);
    203   FD_ZERO(&w);
     200  FD_ZERO(&aim_rfds);
     201  FD_ZERO(&aim_wfds);
    204202  if (owl_global_is_doaimevents(&g)) {
    205203    aim_done = 0;
    206     aim_max_fd = owl_select_aim_hack(&aim_fds);
     204    aim_max_fd = owl_select_aim_hack(&aim_rfds, &aim_wfds);
    207205    if (max_fd < aim_max_fd) max_fd = aim_max_fd;
    208206    for(i = 0; i <= aim_max_fd; i++) {
    209       if (FD_ISSET(i, &aim_fds)) {
     207      if (FD_ISSET(i, &aim_rfds)) {
    210208        FD_SET(i, &r);
    211         FD_SET(i, &w); /* Yes, we're checking writable sockets
    212                           here. Without it, AIM login is really
    213                           slow. */
    214209        FD_SET(i, &e);
    215210      }
     
    217212  }
    218213  /* END AIM HACK */
    219  
    220   if ( select(max_fd, &r, &w, &e, &timeout) ) {
     214
     215  if ( select(max_fd+1, &r, &aim_wfds, &e, &timeout) ) {
    221216    /* Merge fd_sets and clear AIM FDs. */
    222217    for(i = 0; i <= max_fd; i++) {
    223218      /* Merge all interesting FDs into one set, since we have a
    224219         single dispatch per FD. */
    225       if (FD_ISSET(i, &r) || FD_ISSET(i, &w) || FD_ISSET(i, &e)) {
     220      if (FD_ISSET(i, &r) || FD_ISSET(i, &aim_wfds) || FD_ISSET(i, &e)) {
    226221        /* AIM HACK: no separate dispatch, just process here if
    227222           needed, and only once per run through. */
    228         if (!aim_done && FD_ISSET(i, &aim_fds)) {
     223        if (!aim_done && (FD_ISSET(i, &aim_rfds) || FD_ISSET(i, &aim_wfds))) {
    229224          owl_process_aim();
    230225          aim_done = 1;
     
    235230      }
    236231    }
    237 
    238232    /* NOTE: the same dispatch function is called for both exceptional
    239233       and read ready FDs. */
Note: See TracChangeset for help on using the changeset viewer.