Ejemplo n.º 1
0
static int
process_connection(int fd, struct xmpp *xmpp)
{
    struct timeval tv;
    fd_set fds;
    int max_fd, ret = 0;

    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
    while (1) {
        FD_ZERO(&fds);
        FD_SET(fd, &fds);
        FD_SET(0, &fds);
        max_fd = fd;
        tv.tv_sec = keep_alive_ms / 1000;
        tv.tv_usec = (keep_alive_ms % 1000) * 1000;
        ret = select(max_fd + 1, &fds, 0, 0, (keep_alive_ms > 0) ? &tv : 0);
        if (ret < 0)
            break;
        if (ret > 0) {
            if (FD_ISSET(fd, &fds))
                if (process_server_input(fd, xmpp))
                    break;
            if (FD_ISSET(0, &fds))
                if (process_input(0, xmpp))
                    break;
        } else if ((!use_tls || in_tls) && io_send(1, " ", &fd) < 1)
            break;
    }
    return 0;
}
Ejemplo n.º 2
0
Archivo: ji.c Proyecto: placek/ji
static int
process_connection(int fd, struct xmpp *xmpp)
{
  int res, max_fd;
  struct contact *u, *next;
  fd_set fds;
  struct timeval tv;

  add_contact(0, "");
  fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK);
  while (1) {
    FD_ZERO(&fds);
    FD_SET(fd, &fds);
    max_fd = fd;
    for (u = contacts; u && is_ready; u = u->next)
      if (u->fd >= 0) {
        FD_SET(u->fd, &fds);
        if (u->fd > max_fd)
          max_fd = u->fd;
      }
    tv.tv_sec = keep_alive_ms / 1000;
    tv.tv_usec = (keep_alive_ms % 1000) * 1000;
    res = select(max_fd + 1, &fds, 0, 0, (keep_alive_ms > 0) ? &tv : 0);
    if (res < 0)
      break;
    if (res > 0) {
      if (FD_ISSET(fd, &fds) && process_server_input(fd, xmpp))
        break;
      for (u = contacts; u; u = next) {
        next = u->next;
        if (FD_ISSET(u->fd, &fds))
          handle_contact_input(xmpp, u);
      }
    } else if (io_send(1, " ", &fd) < 1)
      break;
  }
  return 0;
}