示例#1
0
int main(int argc, char **argv) {
  List *a = create_iter(6);
  List *b = create_iter(6);

  List *head = app_recur(a, b);

  return 1;
}
示例#2
0
int main(int argc, char **argv) {
  List *a = create_iter(6);
  List *b = create_iter(6);

  List *rev_a = reverse_iter(a);

  a->n->n = NULL;
  b->n->n = NULL;
  rev_a->n->n = NULL;

  return 1;
}
示例#3
0
int main(int argc, char **argv) {
  List *head = create_iter(6);

  remove_recur(head, 4);

  return 1;
}
示例#4
0
int main(int argc, char **argv) {
  List *head = create_iter(6);

  List *revd = reverse_recur(head);

  return 1;
}
示例#5
0
/***************************************************************************
 * Function: void flush_output()
 *
 * Description:
 *   Use select() to determine which connections that have output pending
 * are capable of accepting output at the moment, and send as much data to
 * those connections as they will accept.
 **************************************************************************/
void flush_output() {
  conn_data *conn;
  fd_set fd_outset;
  struct timeval sel_timeout;
  iterator *conn_iter = create_iter(conn_list);;

/*
 * Clear out the fd_set and add to it the fds of all connections with
 * output pending.
 */
  FD_ZERO(&fd_outset);
  for (init_iter(conn_iter); (conn = peek_iter(conn_iter));
       iterate_iter(conn_iter)) {
    if (length_list(conn->output) != 0) FD_SET(conn->fd, &fd_outset);
  }

/*
 * Use select to determine which fds actually belong in the set.
 * (NOFILE is the maximum number of open files per process, as described
 * previously)
 */
  bzero(&sel_timeout, sizeof(struct timeval));
  if (select(NOFILE, NULL, &fd_outset, NULL, &sel_timeout) <0 ) {
    fprintf(stderr, "Error: Selection of ready file descriptors failed.\n");
    perror("  flush_output(select)");
    exit(ERROR);
  }

/*
 * Process connections with pending output.  Note that it is necessary to
 * iterate the iterator _before_ executing the loop in case the connection
 * we're currently working on gets disconnected.
 */
  for (init_iter(conn_iter); (conn = peek_iter(conn_iter)); ) {
    iterate_iter(conn_iter);

    if (FD_ISSET(conn->fd, &fd_outset)) {
      if (send_text(conn) <= 0) {
        disconnect(conn);
        continue;
      }
    }
  }

  destroy_iter(conn_iter);
}
示例#6
0
void event(State* s) {
  if(s->iter==0||s->list==0) {
    s->list=create_iter(6);
  } else if(s->iter<s->maxlen) {
      insert_iter(s->list, s->iter);
  } else {
    delall_iter(s->list);
    s->list=0;
    s->iter=0;
  }
#ifdef MYPRINT
  if(s->list) {
    s->list->print();
    printf(" iter:%d max:%d\n",s->iter,s->maxlen);
  }
#endif
  s->iter++;
}
示例#7
0
void event(class State *s)
{
  if (s -> State::iter == 0 || s -> State::list == 0) {
    (*rts.avpushptr((void**)&(s -> list))) = create_iter(6);
  }
  else {
    if (s -> State::iter < s -> State::maxlen) {
      insert_iter(s -> State::list, s -> State::iter);
    }
    else {
      delall_iter(s -> State::list);
      (*rts.avpushptr((void**)&(s -> list))) = 0;
      (*rts.avpush(&(s -> iter))) = 0;
    }
  }
#ifdef PRINT
#endif
  (*rts.avpush(&(s -> iter)))++;
}
示例#8
0
/***************************************************************************
 * Function: void gather_input()
 *
 * Description:
 *   Use select() to examine activity on all open sockets/file-descriptors.
 * This includes new connections on port sockets and input on connection
 * sockets (and, I suppose, exception states on either).  After eliminating
 * any sockets in exception states, process all input on remaining sockets.
 **************************************************************************/
void gather_input() {
  int fd;
  port_data *port;
  conn_data *conn;
  fd_set fd_inset, fd_excset;
  struct timeval sel_timeout;
  iterator *conn_iter = create_iter(conn_list);
  iterator *port_iter = create_iter(port_list);

/*
 * Initialize the input and exception fd_sets to the empty state, then add
 * all of the port and connection socket file descriptors.
 *
 */
  FD_ZERO(&fd_inset);
  FD_ZERO(&fd_excset);
  for (init_iter(port_iter); (port = peek_iter(port_iter));
       iterate_iter(port_iter)) {
    fd = port->fd;
    FD_SET(fd, &fd_inset);
    FD_SET(fd, &fd_excset);
  }
  for (init_iter(conn_iter); (conn = peek_iter(conn_iter));
       iterate_iter(conn_iter)) {
    fd = conn->fd;
    FD_SET(fd, &fd_inset);
    FD_SET(fd, &fd_excset);
  }

/*
 * Calling "select" will remove all sockets from each of the fd_sets to
 * which they don't actually belong.  In other words, if there isn't any
 * input on a given connection (or no new connection on a port), it is
 * removed from the input set.  Note that NOFILE is the maximum number of
 * open files per process, and, I suspect, is not a portable constant.  If
 * it isn't defined anywhere on your system, you'll probably have to use the
 * "getrlimit" system call to find out what that number is.  Also note that
 * select will sleep for the amount of time indicated in sel_timeout before
 * returning, which can be used to regulate how much time is consumed by
 * each game loop.  For now, though, the timeout is set to 0, since we're
 * using "usleep" in the main loop.
 */
  bzero(&sel_timeout, sizeof(struct timeval));
  if (select(NOFILE, &fd_inset, NULL, &fd_excset, &sel_timeout) <0 ) {
    fprintf(stderr, "Error: Selection of ready file descriptors failed.\n");
    perror("  gather_input(select)");
    exit(ERROR);
  }

/*
 * Process all port sockets, checking for new connections and exception states.
 * Since multiple connections may be pending on a single port, we keep calling
 * "get_connection" on each port in the input set until that function returns
 * FALSE, indicating that no more connections are pending on it.
 */
  for (init_iter(port_iter); (port = peek_iter(port_iter));
       iterate_iter(port_iter)) {
    fd = port->fd;
    if (FD_ISSET(fd, &fd_excset)) {
      fprintf(stderr, "Error: Exception state on port %d (fd %d).\n",
              port->portnum, fd);
      exit(ERROR);
    } else if (FD_ISSET(fd, &fd_inset))
      while (get_connection(fd));
  }

/*
 * Process connection sockets, checking for new input and exception conditions.
 * Note that it is necessary to iterate the iterator _before_ executing the
 * loop in case the current connection gets disconnected.
 */
  for (init_iter(conn_iter); (conn = peek_iter(conn_iter)); ) {
    iterate_iter(conn_iter);
    fd = conn->fd;

/*
 * Check to see if this connection is in an exception state.  If it is,
 * disconnect it.
 */
    if (FD_ISSET(fd, &fd_excset)) {
      FD_CLR(fd, &fd_inset);
      disconnect(conn);
      continue;
    }

/*
 * Check to see if this connection has pending input.  If it does, attempt to
 * read it all in.  If nothing can be read in, disconnect it.
 */
    if (FD_ISSET(fd, &fd_inset)) {
      if (recv_text(conn) <= 0) {
        disconnect(conn);
        continue;
      }
      time(&(conn->input_time));
    }
  }

  destroy_iter(port_iter);
  destroy_iter(conn_iter);
}