int main() { int i; int pri; IBP_REQUESTS_QUEUE * queue; IBP_REQUEST_POOL * pool; IBP_REQUEST *request; IBP_CONNECTION *conn; queue = init_req_queue(1024,400); glbReqPool = init_request_pool(); for (i=0; i< 1024;i++){ conn = init_connection(i); request = create_request(conn); set_request_priority(request,random()%400); append_request(queue,request); } for(i=0; i< 1024; i++){ request=get_request(queue); free_request(pool,request); } fprintf(stderr,"Total allocated = %d idle request = %d\n", glbReqPool->allocated,glbReqPool->num); delete_req_queue(queue); delete_request_pool(glbRequestPool); return 0; }
void dispatch_request(char* from, char* to, int accept_socket, int* keep_alive){ char* req_str = (char*) malloc(sizeof(char) * (to - from + 1)); char* char_i; int int_i; int _ = 0; for(char_i = from, int_i = 0; char_i < to; char_i++, int_i++){ *(req_str + int_i) = *(char_i); } *(req_str + int_i) = '\0'; struct request* req = malloc_request(); parse_request(req, req_str); struct response* resp = malloc_response(req); //free(req_str); write_request(resp, accept_socket); if(resp->html == 0){ read_file(req->resource_name, accept_socket); } else{ _ = write(accept_socket, resp->html, strlen(resp->html)); } if(_ == -1){ printf("scream write %d\n", _); } *keep_alive = req->keep_alive; free(req_str); free_request(req); print_response(resp); free_response(resp); }
void dino_process_request(dino_http_site_t *dino_site, int socket) { dino_handle_t dhandle; init_request(&dhandle); if (-1 == socket) { log_error("accept", __FUNCTION__, __LINE__); } else { dhandle.http.socket = socket; accept_request(dino_site, &dhandle); } // Clear the cache memory... // This assumes that there is no memory allocations // that will be presisted across calls. // memory_cache_clear(); // Free DHANDLE // free_request(&dhandle); // Close Socket // close(socket); }
static void cancel_all_requests(liMemcachedCon *con) { int_request *req; GError *err1 = NULL, *err = NULL; gboolean first = TRUE; if (con->err) { err1 = g_error_copy(con->err); } else { g_set_error(&err1, LI_MEMCACHED_ERROR, LI_MEMCACHED_CONNECTION, "Connection reset"); } while (NULL != (req = g_queue_peek_head(&con->req_queue))) { if (NULL == err) { err = g_error_copy(err1); } if (req->req.callback) req->req.callback(&req->req, LI_MEMCACHED_RESULT_ERROR, NULL, &err); free_request(con, req); if (first) { if (err) err->code = LI_MEMCACHED_DISABLED; /* "silent" fail */ if (err1) err1->code = LI_MEMCACHED_DISABLED; /* "silent" fail */ if (con->err) con->err->code = LI_MEMCACHED_DISABLED; /* "silent" fail */ first = FALSE; } } if (NULL != err) g_clear_error(&err); if (NULL != err1) g_clear_error(&err1); }
liMemcachedRequest* li_memcached_get(liMemcachedCon *con, GString *key, liMemcachedCB callback, gpointer cb_data, GError **err) { int_request* req; if (!li_memcached_is_key_valid(key)) { g_set_error(err, LI_MEMCACHED_ERROR, LI_MEMCACHED_BAD_KEY, "Invalid key: '%s'", key->str); return NULL; } if (-1 == con->fd) memcached_connect(con); if (-1 == con->fd) { if (NULL == con->err) { g_set_error(err, LI_MEMCACHED_ERROR, LI_MEMCACHED_DISABLED, "Not connected"); } else if (err) { *err = g_error_copy(con->err); } return NULL; } req = g_slice_new0(int_request); req->req.callback = callback; req->req.cb_data = cb_data; req->type = REQ_GET; req->key = g_string_new_len(GSTR_LEN(key)); if (!push_request(con, req, err)) { free_request(con, req); return NULL; } return &req->req; }
static void service(FILE *in, FILE *out, char *docroot) { struct HTTPRequest *req; req = read_request(in); respond_to(req, out, docroot); free_request(req); }
/** mpi_wait(+Handle,-Status,-Data * * Completes a non-blocking operation. IF the operation was a send, the * function waits until the message is buffered or sent by the runtime * system. At this point the send buffer is released. If the operation * was a receive, it waits until the message is copied to the receive * buffer. * . */ static YAP_Bool mpi_wait_recv(term_t YAP_ARG1,...) { YAP_Term t1 = YAP_Deref(YAP_ARG1); // data MPI_Status status; MPI_Request *handle; char *s; int ret; size_t len; YAP_Term out; // The first argument (handle) must be an integer if(!YAP_IsIntTerm(t1)) { return false; } CONT_TIMER(); handle=INT2HANDLE(YAP_IntOfTerm(t1)); s=(char*)get_request(handle); // wait for communication completion if( MPI_CALL(MPI_Wait( handle , &status )) != MPI_SUCCESS) { PAUSE_TIMER(); return false; } len=YAP_SizeOfExportedTerm(s); // make sure we only fetch ARG3 after constructing the term out = string2term(s,(size_t*)&len); MSG_RECV(len); free_request(handle); PAUSE_TIMER(); ret=YAP_Unify(YAP_ARG3,out); return(ret & YAP_Unify(YAP_ARG2,YAP_MkIntTerm(status.MPI_ERROR))); }
/* * mpi_test(+Handle,-Status) * * Provides information regarding a handle, ie. if a communication operation has been completed. * If the operation has been completed the predicate succeeds with the completion status, * otherwise it fails. * ). */ static YAP_Bool mpi_test(term_t YAP_ARG1,...) { YAP_Term t1 = YAP_Deref(YAP_ARG1), // Handle t2 = YAP_Deref(YAP_ARG2); // Status MPI_Status status; MPI_Request *handle; int flag; // The first argument (handle) must be an integer if(!YAP_IsIntTerm(t1)) { return false; } CONT_TIMER(); handle=INT2HANDLE(YAP_IntOfTerm(t1)); // MPI_CALL(MPI_Test( handle , &flag, &status )); if( flag != true ) { PAUSE_TIMER(); return false; } free_request(handle); PAUSE_TIMER(); return(YAP_Unify(t2,YAP_MkIntTerm(status.MPI_ERROR))); }
/* * Provides information regarding a handle, ie. if a communication operation has been completed. * If the operation has been completed the predicate succeeds with the completion status, * otherwise it fails. * * mpi_test(+Handle,-Status,-Data). */ static YAP_Bool mpi_test_recv(void) { YAP_Term t1 = YAP_Deref(YAP_ARG1); // data MPI_Status status; MPI_Request *handle; int flag,len,ret; char *s; YAP_Term out; // The first argument (handle) must be an integer if(!YAP_IsIntTerm(t1)) { return false; } CONT_TIMER(); handle=INT2HANDLE(YAP_IntOfTerm(t1)); // if( MPI_CALL(MPI_Test( handle , &flag, &status ))!=MPI_SUCCESS) { PAUSE_TIMER(); return false; } s=(char*)get_request(handle); len=strlen(s); out = string2term(s,(size_t*)&len); // make sure we only fetch ARG3 after constructing the term ret=YAP_Unify(YAP_ARG3,out); free_request(handle); PAUSE_TIMER(); return(ret & YAP_Unify(YAP_ARG2,YAP_MkIntTerm(status.MPI_ERROR))); }
/* * Attempts to release the requests structures used in asynchronous communications */ static void gc(hashtable ht) { MPI_Request *handle; hashnode* node; MPI_Status status; int flag; node=(hashnode*)next_hashnode(ht); if ( node==NULL) return; gc(ht); // start at the end handle=INT2HANDLE(node->value); MPI_CALL(MPI_Test( handle , &flag, &status )); if ( flag==true) { MPI_CALL(MPI_Wait(handle,&status)); #ifdef DEBUG write_msg(__FUNCTION__,__FILE__,__LINE__,"Released handle...%s\n",(char*)node->obj); #endif if (ht==requests) free_request(handle); else free_broadcast_request(handle); } }
/****************************************************************************** * * * Function: get_value_db * * * * Purpose: retrieve data from database * * * * Parameters: item - item we are interested in * * * * Return value: SUCCEED - data successfully retrieved and stored in result * * NOTSUPPORTED - requested item is not supported * * * * Author: Eugene Grigorjev * * * ******************************************************************************/ int get_value_db(DC_ITEM *item, AGENT_RESULT *result) { const char *__function_name = "get_value_db"; AGENT_REQUEST request; int ret = NOTSUPPORTED; zabbix_log(LOG_LEVEL_DEBUG, "In %s() key_orig:'%s'", __function_name, item->key_orig); init_request(&request); if (SUCCEED == parse_item_key(item->key, &request)) { if (0 == strcmp(request.key, "db.odbc.select")) ret = db_odbc_select(item, &request, result); else if (0 == strcmp(request.key, "db.odbc.discovery")) ret = db_odbc_discovery(item, &request, result); else SET_MSG_RESULT(result, zbx_strdup(NULL, "Unsupported item key for this item type.")); } else SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid item parameter format.")); free_request(&request); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
static inline void clean_cli(client_t *client) { write_access_log(client, log_fd, log_path); if(client->req){ free_request(client->req); client->req = NULL; } Py_CLEAR(client->http_status); Py_CLEAR(client->headers); Py_CLEAR(client->response_iter); Py_CLEAR(client->response); #ifdef DEBUG printf("clean_cli environ status_code %d address %p \n", client->status_code, client->environ); #endif if(client->environ){ PyDict_Clear(client->environ); Py_DECREF(client->environ); } if(client->body){ if(client->body_type == BODY_TYPE_TMPFILE){ fclose(client->body); }else{ free_buffer(client->body); } client->body = NULL; } client->header_done = 0; client->response_closed = 0; client->chunked_response = 0; client->content_length_set = 0; client->content_length = 0; client->write_bytes = 0; }
t_list_single find_aux(t_list_words l, t_websearch search_engine, t_list_single sites) { if (IS_EMPTY(l)) { return sites; } else { char *results[NBR_WEBSITES]; int count; char *request; int i; INFO("Construction de la requête"); request = build_request(HEAD(l)); INFO("Requête : %s", request); count = websearch(search_engine, request, results, NBR_WEBSITES); INFO("Documents trouvés : %d", count); INFO("Stockage des sites trouvés"); for(i=0;i<count;i++) { if (add_single_sorted(results[i], NBR_WEBSITES-i, &sites) == 0) { free(results[i]); } } INFO("Libération de la requête"); free_request(request); return find_aux(NEXT(l), search_engine, sites); } }
/** This is used to delete all requests */ void sdl_user::delete_requests() { while (SDL_mutexP(requests_mtx) == -1) {}; while (request_list.size() > 0) { client_request *temp = request_list.front(); request_list.pop_front(); free_request(temp); } SDL_mutexV(requests_mtx); }
static inline void set_current_request(client_t *client) { request *req; req = shift_request(client->request_queue); client->bad_request_code = req->bad_request_code; client->body = req->body; client->body_type = req->body_type; client->environ = req->env; free_request(req); client->req = NULL; }
int get_value_simple(DC_ITEM *item, AGENT_RESULT *result) { const char *__function_name = "get_value_simple"; AGENT_REQUEST request; vmfunc_t vmfunc; int ret = NOTSUPPORTED; zabbix_log(LOG_LEVEL_DEBUG, "In %s() key_orig:'%s' addr:'%s'", __function_name, item->key_orig, item->interface.addr); init_request(&request); parse_item_key(item->key, &request); request.lastlogsize = item->lastlogsize; if (0 == strcmp(request.key, "net.tcp.service")) { if (SYSINFO_RET_OK == check_service(&request, item->interface.addr, result, 0)) ret = SUCCEED; } else if (0 == strcmp(request.key, "net.tcp.service.perf")) { if (SYSINFO_RET_OK == check_service(&request, item->interface.addr, result, 1)) ret = SUCCEED; } else if (SUCCEED == get_vmware_function(request.key, &vmfunc)) { if (NULL != vmfunc) { if (SYSINFO_RET_OK == vmfunc(&request, item->username, item->password, result)) ret = SUCCEED; } else SET_MSG_RESULT(result, zbx_strdup(NULL, "Support for VMware checks was not compiled in.")); } else { /* it will execute item from a loadable module if any */ if (SUCCEED == process(item->key, PROCESS_MODULE_COMMAND, result)) ret = SUCCEED; } if (NOTSUPPORTED == ret && !ISSET_MSG(result)) SET_MSG_RESULT(result, zbx_strdup(NULL, "Simple check is not supported.")); free_request(&request); zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(ret)); return ret; }
int alloc_send_free_request (struct alloc_ctx *ctx, struct job *job) { assert (job->state == FLUX_JOB_CLEANUP); if (!job->free_pending) { if (free_request (ctx, job) < 0) return -1; job->free_pending = 1; if ((job->flags & FLUX_JOB_DEBUG)) (void)event_job_post_pack (ctx->event_ctx, job, "debug.free-request", NULL); } return 0; }
int get_value_ssh(DC_ITEM *item, AGENT_RESULT *result) { AGENT_REQUEST request; int ret = NOTSUPPORTED; const char *port, *encoding, *dns; init_request(&request); if (SUCCEED != parse_item_key(item->key, &request)) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid item key format.")); goto out; } if (0 != strcmp(SSH_RUN_KEY, get_rkey(&request))) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Unsupported item key for this item type.")); goto out; } if (4 < get_rparams_num(&request)) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); goto out; } if (NULL != (dns = get_rparam(&request, 1)) && '\0' != *dns) { strscpy(item->interface.dns_orig, dns); item->interface.addr = item->interface.dns_orig; } if (NULL != (port = get_rparam(&request, 2)) && '\0' != *port) { if (FAIL == is_ushort(port, &item->interface.port)) { SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid third parameter.")); goto out; } } else item->interface.port = ZBX_DEFAULT_SSH_PORT; encoding = get_rparam(&request, 3); ret = ssh_run(item, result, ZBX_NULL2EMPTY_STR(encoding)); out: free_request(&request); return ret; }
int main() { request_t request; response_t response; request.id = 555; request.request_nodelist = strdup("vm[1-3]"); allocate(&request, &response); printf("response.id = %d\n", response.id); printf("response.allocate_nodelist = %s\n", response.allocate_nodelist); free_request(&request); free_response(&response); return 0; }
END_TEST START_TEST (test_resolve_with_static_path_when_file_is_absent) { request_info_t *request_info = make_request_info(strdup("/absent"), strdup("example.com"), 80); request_t *request = make_request(request_info, NULL, strdup(""), 0, 0); harp_resolver_t *resolver = harp_make_static_path_resolver(strdup("/tmp")); harp_config_t *config = harp_make_empty_config(); harp_cons_resolver(resolver, config); resolution_strategy_t strategy = resolve_request(request, config); ck_assert_int_eq(strategy, RESOLUTION_STRATEGY_404); harp_free_config(config); free_request(request); }
static void service ( FILE *in, /* input fd */ FILE *out, /* output fd */ char *docroot /* docroot path */ ) { struct HTTPRequest *req = NULL; dbg( "in=%p, out=%p, docroot=%p\n", in, out, docroot ); req = read_request( in ); respond_to( req, out, docroot ); free_request( req ); }
int schedule_retry(jsonrpc_request_t* req) { if(!req) { ERR("Trying to schedule retry for a null request.\n"); return -1; } if(req->retry == 0) { return -1; } req->ntries++; if(req->retry > 0 && req->ntries > req->retry) { WARN("Number of retries exceeded. Failing request.\n"); return -1; } /* next retry in milliseconds */ unsigned int time = req->ntries * req->ntries * req->timeout; if(time > RETRY_MAX_TIME) { time = RETRY_MAX_TIME; } jsonrpc_request_t* new_req = create_request(req->cmd); new_req->ntries = req->ntries; free_request(req); const struct timeval tv = ms_to_tv(time); new_req->retry_ev = evtimer_new(global_ev_base, retry_cb, (void*)new_req); if(evtimer_add(new_req->retry_ev, &tv)<0) { ERR("event_add failed while setting request retry timer (%s).", strerror(errno)); goto error; } return 0; error: ERR("schedule_retry failed.\n"); return -1; }
/* ** Liberates all the elements that has been malloced for a client */ void free_client(t_client *c) { t_list *l_req; t_request *req; if (close(c->socket) == -1) xwrite(1, FD_CLOSING_ERROR, my_strlen(FD_CLOSING_ERROR)); free(c->team_name); free(c->to_send); l_req = c->requests; while (l_req) { req = l_req->data; free_request(req); l_req = l_req->next; } my_free_all_list_struct(c->requests); free(c); }
/****************************************************************************** * * * Function: zbx_itemkey_extract_global_regexps * * * * Purpose: extract global regular expression names from item key * * * * Parameters: key - [IN] the item key to parse * * regexps - [OUT] the extracted regular expression names * * * ******************************************************************************/ static void zbx_itemkey_extract_global_regexps(const char *key, zbx_vector_str_t *regexps) { #define ZBX_KEY_LOG 1 #define ZBX_KEY_EVENTLOG 2 AGENT_REQUEST request; int item_key; const char *param; if (0 == strncmp(key, "log[", 4) || 0 == strncmp(key, "logrt[", 6)) item_key = ZBX_KEY_LOG; else if (0 == strncmp(key, "eventlog[", 9)) item_key = ZBX_KEY_EVENTLOG; else return; init_request(&request); if(SUCCEED != parse_item_key(key, &request)) goto out; /* "params" parameter */ if (NULL != (param = get_rparam(&request, 1)) && '@' == *param) zbx_vector_str_append_uniq(regexps, param + 1); if (ZBX_KEY_EVENTLOG == item_key) { /* "severity" parameter */ if (NULL != (param = get_rparam(&request, 2)) && '@' == *param) zbx_vector_str_append_uniq(regexps, param + 1); /* "source" parameter */ if (NULL != (param = get_rparam(&request, 3)) && '@' == *param) zbx_vector_str_append_uniq(regexps, param + 1); /* "logeventid" parameter */ if (NULL != (param = get_rparam(&request, 4)) && '@' == *param) zbx_vector_str_append_uniq(regexps, param + 1); } out: free_request(&request); }
static void clean_cli(client_t *client) { write_access_log(client, log_fd, log_path); if(client->req){ free_request(client->req); client->req = NULL; } #ifdef DEBUG printf("close environ %p \n", client->environ); #endif // force clear client->environ = rb_hash_new(); if(client->http != NULL){ ruby_xfree(client->http); client->http = NULL; } }
main_fn void xio_send_reply(struct client_info *ci) { struct request *req; struct xio_msg xrsp; req = list_first_entry(&ci->done_reqs, struct request, request_list); list_del(&req->request_list); memset(&xrsp, 0, sizeof(xrsp)); server_msg_vec_init(&xrsp); msg_prep_for_reply(&req->rp, req->data, &xrsp); xrsp.request = ci->xio_req; xio_send_response(&xrsp); xio_context_run_loop(xio_get_main_ctx(), XIO_INFINITE); req->data = NULL; /* the data is owned by xio */ free_request(req); }
/* sends a HTTP/1.0 500 page to fd, without requiring a request structure */ void send_emergency_500(int fd, const char *file, int line, const char *reason) { request *r; r = calloc(1, sizeof(request)); /* fill in an absolutely minimal request structure */ r->fd = fd; r->http = strdup("HTTP/1.0"); r->status = 500; r->meth = GET; r->close_conn = 1; /* and send the error */ send_errorpage(r); log_text(err, "Sending 500 %s at %s:%d (%s)", status_reason[500], file, line, reason); free_request(r); }
/* * Completes a non-blocking operation. IF the operation was a send, the * function waits until the message is buffered or sent by the runtime * system. At this point the send buffer is released. If the operation * was a receive, it waits until the message is copied to the receive * buffer. * mpi_wait(+Handle,-Status). */ static YAP_Bool mpi_wait(term_t YAP_ARG1,...) { YAP_Term t1 = YAP_Deref(YAP_ARG1), // Handle t2 = YAP_Deref(YAP_ARG2); // Status MPI_Status status; MPI_Request *handle; // The first argument must be an integer (an handle) if(!YAP_IsIntTerm(t1)) { return false; } handle=INT2HANDLE(YAP_IntOfTerm(t1)); CONT_TIMER(); // probe for term' size if( MPI_CALL(MPI_Wait( handle , &status )) != MPI_SUCCESS ) { PAUSE_TIMER(); return false; } free_request(handle); PAUSE_TIMER(); return(YAP_Unify(t2,YAP_MkIntTerm(status.MPI_ERROR))); }
void fail_request(int code, jsonrpc_request_t* req, char* err_str) { char* req_s; char* freeme = NULL; pv_value_t val; json_t* error; if(!req) { null_req: WARN("%s: (null)\n", err_str); goto end; } if(!(req->cmd) || (req->cmd->route.len <= 0)) { no_route: req_s = json_dumps(req->payload, JSON_COMPACT); if(req_s) { WARN("%s: \n%s\n", err_str, req_s); free(req_s); goto end; } goto null_req; } error = internal_error(code, req->payload); jsontoval(&val, &freeme, error); if(error) json_decref(error); if(send_to_script(&val, req->cmd)<0) { goto no_route; } end: if(freeme) free(freeme); if(req) { if(req->cmd) free_req_cmd(req->cmd); free_request(req); } }
int validate_mfg_card(char *device, int fd) { int ret = 0; struct ata_ioc_request *req; req = build_basic_command(0, 1, 0, ATA_ATA_IDENTIFY, ATA_CMD_READ, SECTOR_SIZE); ret = execute_command(req, fd); if(ret) err(1, "Validate mfg execute command failed.%d %d ",ret, errno); ret = validate_card(req->data); if (ret == 0) { show_details_disk(req->data, device); } else { noupdate_details_disk(device); } free_request(req); return ret; }