void SetUp( const ::benchmark::State& state ) { handle = open_tcp_server_socket( AF_INET, "127.0.0.1", "514" ); target = stumpless_open_tcp4_target( "tcp4-perf", "127.0.0.1", STUMPLESS_OPTION_NONE, STUMPLESS_FACILITY_USER ); entry = stumpless_new_entry( STUMPLESS_FACILITY_USER, STUMPLESS_SEVERITY_INFO, "add-entry-performance-test", "network-target", "this entry is for performance testing" ); accepted = accept_tcp_connection( handle ); stumpless_set_malloc( tcp4_memory_counter_malloc ); stumpless_set_realloc( tcp4_memory_counter_realloc ); stumpless_set_free( tcp4_memory_counter_free ); }
/* Run Server * Function tat will create a new socket, accept and handle connections from clients */ void run_server ( settings_t **settings, char* ( *callback ) ( char* ) ) { fd_set master; fd_set readSet; int listener; int new_fd; int max_fd; int i; /* Create our socket for handling connections */ listener = create_tcp_socket ( LISTEN_PORT ); /* Zero out the master fd_set */ FD_ZERO ( &master ); /* Add the server socket to the set of sockets */ FD_SET ( listener, &master ); /* The highest file descriptor (fd) */ max_fd = listener; /* Infinite loop */ for ( ;; ) { /* Copy the master set into a temporary fd */ readSet = master; /* Handle multiple connections via Select */ if ( select ( max_fd + 1, &readSet, NULL, NULL, NULL ) == -1 ) { DIE ( "select() failed" ); } /* Spin through all of the items in readSet and check for connections or requests */ for ( i = 0; i <= max_fd; i++ ) { /* We've got a new one! */ if (FD_ISSET ( i, &readSet ) ) { if ( i == listener ) { /* Accept a new client */ new_fd = accept_tcp_connection ( listener ); /* Add it to the list of sockets */ FD_SET ( new_fd, &master ); /* Specify the new max, if need be */ if ( new_fd > max_fd ) { max_fd = new_fd; } } else { /* Process information coming from a given socket, and close if necessary */ if ( handle_tcp_connection ( i, callback ) == 0 ) { close ( i ); FD_CLR ( i, &master ); } } } } } /* shut down */ close ( listener ); }