void request_answer(int sock) { int start, end; struct timeval t1, t2; query q; gettimeofday(&t1, 0); query_init(&q); socket_set_timeout(sock, 5, 5); /* read query, read interval start, read interval end */ if(!request_read_query(sock, &q) || !request_read_integer(sock, &start) || !request_read_integer(sock, &end)) { query_delete(&q); close(sock); return; } query_prepare(&q); request_send_result(sock, &q, start, end); query_delete(&q); close(sock); gettimeofday(&t2, 0); /* printf("%i milliseconds\n", ((t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec) / 1000); */ return; }
HRESULT CDECL wined3d_query_create(struct wined3d_device *device, enum wined3d_query_type type, struct wined3d_query **query) { struct wined3d_query *object; HRESULT hr; TRACE("device %p, type %#x, query %p.\n", device, type, query); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); if (!object) { ERR("Failed to allocate query memory.\n"); return E_OUTOFMEMORY; } hr = query_init(object, device, type); if (FAILED(hr)) { WARN("Failed to initialize query, hr %#x.\n", hr); HeapFree(GetProcessHeap(), 0, object); return hr; } TRACE("Created query %p.\n", object); *query = object; return WINED3D_OK; }
QUERY_REC *query_create(const char *server_tag, const char *nick, int automatic) { QUERY_REC *rec; g_return_val_if_fail(nick != NULL, NULL); rec = g_new0(QUERY_REC, 1); rec->chat_type = IRC_PROTOCOL; rec->name = g_strdup(nick); rec->server_tag = g_strdup(server_tag); query_init(rec, automatic); return rec; }
static void sig_layout_restore_item(WINDOW_REC *window, const char *type, CONFIG_NODE *node) { char *name, *tag, *chat_type; chat_type = config_node_get_str(node, "chat_type", NULL); name = config_node_get_str(node, "name", NULL); tag = config_node_get_str(node, "tag", NULL); if (name == NULL || tag == NULL) return; if (g_ascii_strcasecmp(type, "CHANNEL") == 0) { /* bind channel to window */ WINDOW_BIND_REC *rec = window_bind_add(window, tag, name); rec->sticky = TRUE; } else if (g_ascii_strcasecmp(type, "QUERY") == 0 && chat_type != NULL) { CHAT_PROTOCOL_REC *protocol; /* create query immediately */ signal_add("query created", (SIGNAL_FUNC) signal_query_created_curwin); restore_win = window; protocol = chat_protocol_find(chat_type); if (protocol == NULL) window_bind_add(window, tag, name); else if (protocol->query_create != NULL) protocol->query_create(tag, name, TRUE); else { QUERY_REC *query; query = g_new0(QUERY_REC, 1); query->chat_type = chat_protocol_lookup(chat_type); query->name = g_strdup(name); query->server_tag = g_strdup(tag); query_init(query, TRUE); } signal_remove("query created", (SIGNAL_FUNC) signal_query_created_curwin); } }
//------------------------------------------------------------------------------ // FUNCTION // // // DESCRIPTION // // // PARAMETERS // // // RETURN // // //------------------------------------------------------------------------------ char *query_getvar(http_req *req, char *name) { query_var *var; int idx=0; if(!(req->query_tbl)) query_init(req); var = req->query_tbl; while( var->name && (idx<NUM_QUERYVAR) ) { //org, if( strncmp(var->name, name, strlen(name))== 0 ) if( strcmp(var->name, name)== 0 ) return var->value; var++; idx++; } return NULL; }
//------------------------------------------------------------------------------ // FUNCTION // // // DESCRIPTION // // // PARAMETERS // // // RETURN // // //------------------------------------------------------------------------------ void query_set(http_req *req, char *name, char *val) { query_var *var; int idx=0; if(!(req->query_tbl)) query_init(req); var = req->query_tbl; while( var->name && (idx<NUM_QUERYVAR) ) { var++; idx++; } if( idx == NUM_QUERYVAR) printf("Query table was not large enough\n"); var->name = name; var->value = val; }
int main (int argc, char **argv) { int status = 0; int i; char *filename = NULL; progname = argv[0]; bufsiz = resolv_number (BGPDUMP_BUFSIZ_DEFAULT, NULL); nroutes = resolv_number (ROUTE_LIMIT_DEFAULT, NULL); status = bgpdump_getopt (argc, argv); argc -= optind; argv += optind; if (status) return status; if (argc == 0) { printf ("specify rib files.\n"); usage (); exit (-1); } if (verbose) { printf ("bufsiz = %llu\n", bufsiz); printf ("nroutes = %llu\n", nroutes); } /* default cmd */ if (! brief && ! show && ! route_count && ! plen_dist && ! udiff && ! lookup && ! peer_table_only && ! stat && ! compat_mode && ! autsiz && ! heatmap) show++; if (stat) peer_stat_init (); char *buf; buf = malloc (bufsiz); if (! buf) { printf ("can't malloc %lluB-size buf: %s\n", bufsiz, strerror (errno)); exit (-1); } peer_table_init (); if (peer_spec_size) { for (i = 0; i < peer_spec_size; i++) { peer_route_table[i] = route_table_create (); peer_route_size[i] = 0; peer_ptree[i] = ptree_create (); } } if (lookup) { route_init (); ptree[AF_INET] = ptree_create (); ptree[AF_INET6] = ptree_create (); } if (udiff) { diff_table[0] = malloc (nroutes * sizeof (struct bgp_route)); diff_table[1] = malloc (nroutes * sizeof (struct bgp_route)); assert (diff_table[0] && diff_table[1]); memset (diff_table[0], 0, nroutes * sizeof (struct bgp_route)); memset (diff_table[1], 0, nroutes * sizeof (struct bgp_route)); if (udiff_lookup) { diff_ptree[0] = ptree_create (); diff_ptree[1] = ptree_create (); } } /* for each rib files. */ for (i = 0; i < argc; i++) { filename = argv[i]; file_format_t format; struct access_method *method; void *file; size_t ret; format = get_file_format (filename); method = get_access_method (format); file = method->fopen (filename, "r"); if (! file) { fprintf (stderr, "# could not open file: %s\n", filename); continue; } size_t datalen = 0; while (1) { ret = method->fread (buf + datalen, bufsiz - datalen, 1, file); if (debug) printf ("read: %lu bytes to buf[%lu]. total %lu bytes\n", ret, datalen, ret + datalen); datalen += ret; /* end of file. */ if (ret == 0 && method->feof (file)) { if (debug) printf ("read: end-of-file.\n"); break; } bgpdump_process (buf, &datalen); if (debug) printf ("process rest: %lu bytes\n", datalen); } if (datalen) { printf ("warning: %lu bytes unprocessed data remains: %s\n", datalen, filename); } method->fclose (file); /* For each end of the processing of files. */ if (route_count) { peer_route_count_show (); peer_route_count_clear (); } if (plen_dist) { peer_route_count_by_plen_show (); peer_route_count_by_plen_clear (); } } /* query_table construction. */ if (lookup) { query_limit = 0; if (lookup_file) query_limit = query_file_count (lookup_file); if (lookup_addr) query_limit++; query_init (); if (lookup_addr) query_addr (lookup_addr); if (lookup_file) query_file (lookup_file); if (debug) query_list (); } /* query to route_table (ptree). */ if (lookup) { if (benchmark) benchmark_start (); if (peer_spec_size) { for (i = 0; i < peer_spec_size; i++) { printf ("peer %d:\n", peer_spec_index[i]); if (verbose) ptree_list (peer_ptree[i]); ptree_query (peer_ptree[i], query_table, query_size); } } else { if (verbose) ptree_list (ptree[qaf]); ptree_query (ptree[qaf], query_table, query_size); } if (benchmark) { benchmark_stop (); benchmark_print (query_size); } } if (heatmap) { for (i = 0; i < peer_spec_size; i++) { heatmap_image_hilbert_gplot (i); heatmap_image_hilbert_data (i); //heatmap_image_hilbert_data_aspath_max_distance (i); } } if (lookup) { free (query_table); ptree_delete (ptree[AF_INET]); ptree_delete (ptree[AF_INET6]); route_finish (); } if (udiff) { free (diff_table[0]); free (diff_table[1]); if (lookup) { ptree_delete (diff_ptree[0]); ptree_delete (diff_ptree[1]); } } if (stat) { peer_stat_show (); //peer_stat_finish (); } free (buf); return status; }
int main( int argc, char **argv ) { // Read any command line arguments from our friend the user. arguments(argc, argv); // Catch some signals so can exit cleanly signal(SIGINT, exit_interrupt); #ifndef WIN32 signal(SIGHUP, exit_interrupt); signal(SIGTERM, exit_interrupt); signal(SIGPIPE, SIG_IGN); if (debug_on) setvbuf(stdout, NULL, _IONBF, 0); #endif printf("%s - Jorgen Lundman v%s %s %s\n\n", argv ? argv[0] : "llink", VERSION, VERSION_STRING, #if WITH_DVDREAD "(libdvdread)" #else #if HAVE_CLINKC "(libdvdnav, ClinkC)" #else "(libdvdnav)" #endif #endif ); lion_buffersize(conf_buffersize); //lion_buffersize(2352); if (lion_init()) { printf("Failed to initialize lion/networking\n"); exit(-1); } debugf("\n"); // Read configuration file, if any // Warning, calls lion_poll until done. conf_init(); debugf("[main] initialising...\n"); // Warning, calls lion_poll until done. mime_init(); // Warning, calls lion_poll until done. skin_init(); ssdp_init(); httpd_init(); request_init(); root_init(); llrar_init(); visited_init(); cgicmd_init(); #ifdef EXTERNAL external_init(); #endif printf("[main] ready!\n"); // Background? #ifndef WIN32 if (!foreground) { if (fork()) exit(0); setsid(); if (conf_pidfile) { FILE *fd; if ((fd = fopen(conf_pidfile, "w"))) { fprintf(fd, "%u\r\n", getpid()); fclose(fd); } } } #endif cupnp_init(); // Scan for media if (conf_xmlscan) { signal(SIGINT, SIG_DFL); xmlscan_run(); do_exit = 1; } query_init(); #ifdef WIN32 SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS); #endif // The main loop while ( !do_exit ) { // Was 250,0 - we should probably let users control this in // conf settings. if (lion_poll(0, 1)<0) do_exit=1; request_events(); #ifdef EXTERNAL external_resume(); #endif } printf("\n[main] releasing resources...\n"); query_free(); cupnp_free(); #ifdef EXTERNAL external_free(); #endif root_free(); cgicmd_free(); visited_free(); llrar_free(); request_free(); httpd_free(); ssdp_free(); skin_free(); mime_free(); conf_free(); #ifndef WIN32 // Crashed when releasing spawned processes, until i can fix: lion_free(); #endif debugf("[main] done.\n"); return 0; }