static void* handler(void *unused)
{
	int i;
	fd_set active_fd_set, read_fd_set;

	FD_ZERO(&active_fd_set);
	FD_SET(server_fd, &active_fd_set);

	while(1) {
		/* block until input arrives on one or more active sockets */
		read_fd_set = active_fd_set;
		if (select(FD_SETSIZE, &read_fd_set, NULL, NULL, NULL) < 0) {
			log_printf("select failure: %s\n", strerror(errno) );
			goto failed;
		}

		/* service all the socket with input pending */
		for(i=0; i < FD_SETSIZE; ++i) {
			if (FD_ISSET(i, &read_fd_set)) {
				if (i == server_fd)
					add_new_connection(i);
			}
		}
	}

failed:
	pthread_detach(pthread_self());
	return NULL;
}
Esempio n. 2
0
int
main(int argc, char *argv[]) {

  int temp;
  int loops = 0;
  int did_work;
  socklen_t addrlen = sizeof(struct sockaddr_storage);
  uber_state_t *uber_state;
  event_state_select_t *mumble;
  connection_t *connection_list;

  connection_t *temp_connection;

  uber_state = (uber_state_t *)malloc(sizeof(uber_state_t));
  uber_state->connection_list = NULL;
  uber_state->event_state = init_event_state();
  mumble = uber_state->event_state;
  uber_state->rdwr_since_accept = 0;

  fprintf(stderr,"Hello there, let's generate some transactions. Uberstate %p connection_list %p event_state %p\n", uber_state,uber_state->connection_list,uber_state->event_state);

  for (loops = 0; loops < atoi(argv[3]); loops++) {
    temp = establish_connection(argv[1],argv[2],AF_INET,&addrlen);

    /* initialize our event_state minfd */
    /* mumble->minfd = temp; */

    temp_connection = add_new_connection(uber_state,
					 temp,
					 CONNECTION_WRITING,
					 128);

    fprintf(stderr,"temp_connection is at %p\n",temp_connection);
  }

  do {
    loops++;
    if (debug > 1) {
      fprintf(stderr,"\nabout to walk loop %d\n",loops);
    }
    did_work = walk_connection_list(uber_state);
    if (!did_work) {
      if (debug) {
	fprintf(stderr,
		"walk_connection_list did no work, time to wait\n");
      }
      did_work = wait_for_events_and_walk(uber_state);
    }
  } while (1);

}
Esempio n. 3
0
int
accept_new_connection(uber_state_t *uber_state, connection_t *listen_connection) 
{
  SOCKET new_conn;
  connection_t *new_connection;

  if (debug) {
    fprintf(stderr,
	    "about to accept on connection %p fd %d\n",
	    listen_connection,
	    listen_connection->sock);
  }

  /* we don't care if the accept actually accepted a new connection,
     just that we tried calling accept. */
  uber_state->rdwr_since_accept = 0;


  new_conn = accept(listen_connection->sock,NULL,NULL);

  if (INVALID_SOCKET != new_conn) {
    
    /* one day we will want to see if this is inherited across
       accept() calls, but for now we just go ahead and make the
       call */

    fcntl(new_conn,F_SETFL, O_NONBLOCK);

    new_connection = add_new_connection(uber_state,
					new_conn,
					CONNECTION_READING,
					128);
    if (debug) {
      fprintf(stderr,
	      "accepted a connection to %p on fd %d\n",
	      new_connection,
	      new_conn);
    }
  }

  return new_conn;
}
Esempio n. 4
0
int isert_conn_established(struct iscsi_conn *iscsi_conn,
			   struct sockaddr *from_addr, int addr_len)
{
	return add_new_connection(&isert_listen_dev, iscsi_conn);
}