Beispiel #1
0
// 读请求
void SSLSession::read()
{
	IMessage* req = create_request();			

	boost::asio::async_read(socket_, 
		boost::asio::buffer(req->GetMsgHeader(), req->GetMsgHeaderSize()), 
		boost::asio::transfer_all(),
		strand_.wrap(
			boost::bind(&SSLSession::handle_read_head, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, req)
		)
	);
}
Beispiel #2
0
PJ_DEF(pj_status_t) pjsip_regc_unregister(pjsip_regc *regc,
					  pjsip_tx_data **p_tdata)
{
    pjsip_tx_data *tdata;
    pjsip_msg *msg;
    pjsip_hdr *hdr;
    pj_status_t status;

    PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL);

    pj_lock_acquire(regc->lock);

    if (regc->timer.id != 0) {
	pjsip_endpt_cancel_timer(regc->endpt, &regc->timer);
	regc->timer.id = 0;
    }

    regc->expires_requested = 0;

    status = create_request(regc, &tdata);
    if (status != PJ_SUCCESS) {
	pj_lock_release(regc->lock);
	return status;
    }

    msg = tdata->msg;

    /* Add Contact headers. */
    hdr = (pjsip_hdr*)regc->contact_hdr_list.next;
    while ((void*)hdr != (void*)&regc->contact_hdr_list) {
	pjsip_msg_add_hdr(msg, (pjsip_hdr*)
			       pjsip_hdr_shallow_clone(tdata->pool, hdr));
	hdr = hdr->next;
    }

    /* Also add bindings which are to be removed */
    while (!pj_list_empty(&regc->removed_contact_hdr_list)) {
	hdr = (pjsip_hdr*)regc->removed_contact_hdr_list.next;
	pjsip_msg_add_hdr(msg, (pjsip_hdr*)
			       pjsip_hdr_clone(tdata->pool, hdr));
	pj_list_erase(hdr);
    }

    /* Add Expires:0 header */
    hdr = (pjsip_hdr*) pjsip_expires_hdr_create(tdata->pool, 0);
    pjsip_msg_add_hdr(msg, hdr);

    pj_lock_release(regc->lock);

    *p_tdata = tdata;
    return PJ_SUCCESS;
}
static void
join_make_offer(gpointer key, gpointer value, gpointer user_data)
{
	const char *join_to = NULL;
	const crm_node_t *member = value;

	CRM_ASSERT(member != NULL);
	if(crm_is_member_active(member) == FALSE) {
	    return;
	}

	join_to = member->uname;
	if(join_to == NULL) {
		crm_err("No recipient for welcome message");
		return;
	}

	/* 	各種ハッシュテーブルから対象ノード情報を削除する */
	erase_node_from_join(join_to);

	if(saved_ccm_membership_id != crm_peer_seq) {
		saved_ccm_membership_id = crm_peer_seq;
		crm_info("Making join offers based on membership %llu",
			 crm_peer_seq);
	}	
	
	if(member->processes & crm_proc_crmd) {
		/* CRM_OP_JOIN_OFFERメッセージを生成する */
		xmlNode *offer = create_request(
			CRM_OP_JOIN_OFFER, NULL, join_to,
			CRM_SYSTEM_CRMD, CRM_SYSTEM_DC, NULL);
		char *join_offered = crm_itoa(current_join_id);
		
		crm_xml_add_int(offer, F_CRM_JOIN_ID, current_join_id);
		/* send the welcome */
		crm_debug("join-%d: Sending offer to %s",
			  current_join_id, join_to);

		/* 対象ノードにCRM_OP_JOIN_OFFERメッセージを送信する */
		send_cluster_message(join_to, crm_msg_crmd, offer, TRUE);
		free_xml(offer);

		/* welcomed_nodesハッシュテーブルに対象ノードを保存 */
		g_hash_table_insert(
			welcomed_nodes, crm_strdup(join_to), join_offered);
	} else {
		crm_info("Peer process on %s is not active (yet?): %.8lx %d",
			 join_to, (long)member->processes,
			 g_hash_table_size(crm_peer_cache));
	}
	
}
Beispiel #4
0
void solve() {
    int64 argument;
    {
        FILE  *in = fopen("function.in" ,"r");
        fscanf(in,"%lld",&argument);
        fclose(in );
    }

    cache = (int32*)malloc(sizeof(int32*)*(argument+1));
    memset(cache,0,argument+1);

    {
        //todo: realloc
        request **stack  = (request**)malloc(sizeof(request*)*INIT_STACK);
               ( *stack) = (request* )malloc(sizeof(request ));
               (**stack) = create_request(argument);

        request **bottom = stack;
        do {
            request current = **bottom;
            int64   value   = current.argument;

            if (value < 3 || cache[value] != 0) {
                incCounter(value);
                free(*bottom);
                bottom--;
            } else {
                int64 left, right;
                if (value % 2 == 0) {
                    left  = value - 1;
                    right = value - 3;
                } else {
                    left  = (value / 7)*6 + ((value % 7)*6)/7;
                    right = (value / 3)*2 + ((value % 3)*2)/3;
                }
                if (cache[left] == 0 || cache[right] == 0) {
                    //left and right will be computed twice =/
                    processArg(left, &bottom);
                    processArg(right,&bottom);
                } else {
                    cache[value] = (cache[left] + cache[right]) % two32;
                }
            }
        } while (bottom != stack);
    }

    {
        FILE *out = fopen("function.out","w");
        fprintf(out,"%lld",counter);
        fclose(out);
    }
}
void main(){

	unsigned char c;
	unsigned int  n;
	int fifo;
	int dex;

	srandom(time(NULL));

	while(1){

		bzero(&cmd,DATALEN);
		dex = random()%100;
	printf("按Y打印页表,按M打印实存,按F打印辅存,按C手动产生请求,按R随机产生新请求,按X退出程序\n");
		c = getchar();
		if(c == 'r' || c == 'R'){
			cmd.type = 'r';
			if(dex % 2 == 0)
				do_request(0);
			else
				do_request(1);
		}
		else if(c == 'c' || c == 'C'){
			cmd.type = 'c';
			create_request();
		}
		else
			cmd.type = c;
	
////////////////////////fifo begin/////////////////////////
		if((fifo = open(fifoaddr,O_WRONLY)) < 0)
		{
			printf("enq open fifo failed");
			exit(1);
		}

		if(write(fifo,&cmd,DATALEN) < 0)
		{
			printf("enq write failed");
			exit(1);
		}

		close(fifo);

		if(c == 'x' || c == 'X')
			break;
		while((c = getchar()) != '\n');

	}
	return ;
}
Beispiel #6
0
static void write_char(struct bt_bas *bas, GAttrib *attrib, uint16_t handle,
					const uint8_t *value, size_t vlen,
					GAttribResultFunc func,
					gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(bas, user_data);

	id = gatt_write_char(attrib, handle, value, vlen, func, req);

	set_and_store_gatt_req(bas, req, id);
}
Beispiel #7
0
static void discover_char(struct bt_bas *bas, GAttrib *attrib,
						uint16_t start, uint16_t end,
						bt_uuid_t *uuid, gatt_cb_t func,
						gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(bas, user_data);

	id = gatt_discover_char(attrib, start, end, uuid, func, req);

	set_and_store_gatt_req(bas, req, id);
}
Beispiel #8
0
static void
throttle_send_command(enum throttle_state_e mode)
{
    xmlNode *xml = NULL;

    xml = create_request(CRM_OP_THROTTLE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);
    crm_xml_add_int(xml, F_CRM_THROTTLE_MODE, mode);
    crm_xml_add_int(xml, F_CRM_THROTTLE_MAX, throttle_job_max);

    send_cluster_message(NULL, crm_msg_crmd, xml, TRUE);
    free_xml(xml);

    crm_info("Updated throttle state to %.4x", mode);
}
Beispiel #9
0
/*
** LOCK requests
*/
PRIVATE BOOL lock_request (Cmdline * arg) {

    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * dst = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor * src = NULL;
    HTParentAnchor * base = NULL;
    BOOL status = NO;
    char * data = NULL;
        
    if (arg->I) {
        HTPrint ("Adding If header %s\n",arg->I);
        HTDAV_setIfHeader (headers,arg->I);
    }

    if (arg->arg1)  {
        data = create_body (arg->arg1);
        HTPrint ("xml body  %s\n",data);
           
        /* chose the func */
        if (arg->func==1) {
            src = HTTmpAnchor(NULL);
            HTAnchor_setDocument(src, data);
            HTAnchor_setFormat(src, HTAtom_for ("text/xml"));
            HTAnchor_setLength(src, strlen(data));
        } 
    }

    if (arg->base_str && *(arg->base_str)) 
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);

    if (arg->D) HTDAV_setDepthHeader (headers,arg->D);
    if (arg->T) HTDAV_setTimeoutHeader (headers,arg->T);

    HTPrint ("function %d src? %s\n",arg->func,(src)?"yes":"no");

    switch (arg->func) {
        case 1: status = HTLOCKDocumentAnchor (request,dst,src,headers);
                break;
        case 2: status = HTLOCKAnchor (request,dst,data,headers);
                break;
        case 3: status = HTLOCKAbsolute (request,arg->request_uri,data,headers);
                break;
        case 4: status = HTLOCKRelative (request,arg->request_uri,base,data,headers);
                break;
    }

    return status;
}
Beispiel #10
0
/* is there a DC out there? */
void
do_cl_join_query(long long action,
                 enum crmd_fsa_cause cause,
                 enum crmd_fsa_state cur_state,
                 enum crmd_fsa_input current_input, fsa_data_t * msg_data)
{
    xmlNode *req = create_request(CRM_OP_JOIN_ANNOUNCE, NULL, NULL,
                                  CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);

    sleep(1);                   /* give the CCM time to propogate to the DC */
    update_dc(NULL);            /* Unset any existing value so that the result is not discarded */
    crm_debug("Querying for a DC");
    send_cluster_message(NULL, crm_msg_crmd, req, FALSE);
    free_xml(req);
}
Beispiel #11
0
/* Remove a file */
void
nfsfs_remove(pid_t pid, VNode self, const char *path) {
	dprintf(1, "*** nfsfs_remove: %d %s ***\n", pid, path);

	if (self != NULL) {
		// cant remove open files
		syscall_reply(process_get_tid(process_lookup(pid)), SOS_VFS_OPEN);
	} else {
		// remove file
		NFS_RemoveRequest *rq = (NFS_RemoveRequest *)
			create_request(RT_REMOVE, self, pid);
		rq->path = path;
		check_request((NFS_BaseRequest *) rq);
	}
}
Beispiel #12
0
/*!
 * \internal
 * \brief Create a join message from the DC
 *
 * \param[in] join_op  Join operation name
 * \param[in] host_to  Recipient of message
 */
static xmlNode *
create_dc_message(const char *join_op, const char *host_to)
{
    xmlNode *msg = create_request(join_op, NULL, host_to, CRM_SYSTEM_CRMD,
                                  CRM_SYSTEM_DC, NULL);

    /* Identify which election this is a part of */
    crm_xml_add_int(msg, F_CRM_JOIN_ID, current_join_id);

    /* Add a field specifying whether the DC is shutting down. This keeps the
     * joining node from fencing the old DC if it becomes the new DC.
     */
    crm_xml_add_boolean(msg, F_CRM_DC_LEAVING,
                        is_set(fsa_input_register, R_SHUTDOWN));
    return msg;
}
Beispiel #13
0
/*
** MOVE requests
*/
PRIVATE BOOL move_request ( Cmdline * arg ) { 
        
    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * src = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor * body = NULL;
    HTParentAnchor * base = NULL;
    BOOL status = NO;
        
    if (arg->arg1) {
       HTPrint ("Adding Destination header %s\n",arg->arg1);
       HTDAV_setDestinationHeader (headers,arg->arg1);
    }
        
    if (arg->I) {
       HTPrint ("Adding If header %s\n",arg->I);
       HTDAV_setIfHeader (headers,arg->I);
    }

    /* chose the func */
    if (arg->func==2 && arg->arg2 ) {
        body = HTTmpAnchor(NULL);
        HTAnchor_setDocument(body, arg->arg2);
        HTAnchor_setFormat(body, HTAtom_for ("text/xml"));
        HTAnchor_setLength(body, strlen(arg->arg2));                
     } 

    if (arg->base_str && *(arg->base_str)) 
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);

    if (arg->D) HTDAV_setDepthHeader (headers,arg->D);
    if (arg->O == 'T') HTDAV_setOverwriteHeader (headers,YES);
    else if (arg->O == 'F') HTDAV_setOverwriteHeader (headers,NO);

    switch (arg->func) {
        case 1: status = HTMOVEAnchor (request,src,arg->arg2,headers);
                break;
        case 2: status = HTMOVEDocumentAnchor (request,src,body,headers);
                break;
        case 3: status = HTMOVEAbsolute (request,arg->request_uri,arg->arg2, headers);
                break;
        case 4: status = HTMOVERelative (request,arg->request_uri,base,arg->arg2,headers);
                break;
    }

    return status;
}
Beispiel #14
0
/*
** PROPFIND requests
*/
PRIVATE BOOL propfind_request (Cmdline * arg) {
    BOOL status = NO;
    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * dst = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor *base = NULL;
    HTParentAnchor *src = NULL;
    char * xmlbody = NULL;

    /* chose the func */
    HTPrint ("should we set the xml body?\n");
    if (arg->arg1 && *(arg->arg1)) {
        if (!strcasecomp (arg->arg1,"allprop") || !strcasecomp (arg->arg1,"propname")) 
            xmlbody = create_propbody (arg->arg1);
        else
            xmlbody = arg->arg1;
        HTPrint ("xml body %s\n",xmlbody);        
    }        
    
    if (arg->func==2 && xmlbody && *xmlbody) {
        src = HTTmpAnchor(NULL);
        HTAnchor_setDocument(src, xmlbody);
        HTAnchor_setFormat(src, HTAtom_for ("text/xml"));
        HTAnchor_setLength(src, strlen(xmlbody));                
    } 

    if (arg->base_str && *(arg->base_str)) 
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);

    HTPrint ("setting headers\n");
    if (arg->D) HTDAV_setDepthHeader (headers,arg->D);


    switch (arg->func) {
        case 1: status = HTPROPFINDAnchor (request,dst,xmlbody,headers);
                break; 
        case 2: status = HTPROPFINDDocumentAnchor (request,dst,src,headers);
                break; 
        case 3: status = HTPROPFINDAbsolute (request,arg->request_uri,xmlbody,headers);
                break; 
        case 4: status = HTPROPFINDRelative (request,arg->request_uri,base,xmlbody,headers);
                break; 
    }    

    return status;
}
Beispiel #15
0
/*
** PROPPATCH requests
*/
PRIVATE BOOL proppatch_request (Cmdline * arg) {
    BOOL status = NO;
    HTDAVHeaders * headers = HTDAVHeaders_new();
    HTRequest * request = create_request ();
    HTAnchor * dst = HTAnchor_findAddress(arg->request_uri);
    HTParentAnchor *base = NULL;
    HTParentAnchor *src = NULL;
    char * xmlbody = NULL;
    
    if (arg->arg1 && *(arg->arg1)) 
        xmlbody = arg->arg1;        
    else 
        return NO;
    
    HTPrint ("xml body **%s**\n",xmlbody);        
    
    if (arg->func==2) {
        src = HTTmpAnchor(NULL);
        HTAnchor_setDocument(src, xmlbody);
        HTAnchor_setFormat(src, HTAtom_for ("text/xml"));
        HTAnchor_setLength(src, strlen(xmlbody));                
    } 

    if (arg->base_str && *(arg->base_str)) 
        base = (HTParentAnchor *) HTAnchor_findAddress(arg->base_str);

    HTPrint ("setting headers\n");
    if (arg->I && *(arg->I)) {           
        HTPrint ("Adding If header %s\n",arg->I);
        HTDAV_setIfHeader (headers,arg->I);
    }

    HTPrint ("Chosing func\n");
    switch (arg->func) {
        case 1: status = HTPROPPATCHAnchor (request,dst,xmlbody,headers);
                break; 
        case 2: status = HTPROPPATCHDocumentAnchor (request,dst,src,headers);
                break; 
        case 3: status = HTPROPPATCHAbsolute (request,arg->request_uri,xmlbody,headers);
                break; 
        case 4: status = HTPROPPATCHRelative (request,arg->request_uri,base,xmlbody,headers);
                break; 
    }    

    return status;
}
Beispiel #16
0
static void
join_make_offer(gpointer key, gpointer value, gpointer user_data)
{
    xmlNode *offer = NULL;
    crm_node_t *member = (crm_node_t *)value;

    CRM_ASSERT(member != NULL);
    if (crm_is_peer_active(member) == FALSE) {
        crm_info("Not making an offer to %s: not active (%s)", member->uname, member->state);
        if(member->expected == NULL && safe_str_eq(member->state, CRM_NODE_LOST)) {
            crm_update_peer_expected(__FUNCTION__, member, CRMD_JOINSTATE_DOWN);
        }
        return;
    }

    if (member->uname == NULL) {
        crm_err("No recipient for welcome message");
        return;
    }

    if (saved_ccm_membership_id != crm_peer_seq) {
        saved_ccm_membership_id = crm_peer_seq;
        crm_info("Making join offers based on membership %llu", crm_peer_seq);
    }

    if(user_data && member->join > crm_join_none) {
        crm_info("Skipping %s: already known %d", member->uname, member->join);
        return;
    }

    crm_update_peer_join(__FUNCTION__, (crm_node_t*)member, crm_join_none);

    offer = create_request(CRM_OP_JOIN_OFFER, NULL, member->uname,
                           CRM_SYSTEM_CRMD, CRM_SYSTEM_DC, NULL);

    crm_xml_add_int(offer, F_CRM_JOIN_ID, current_join_id);
    /* send the welcome */
    crm_info("join-%d: Sending offer to %s", current_join_id, member->uname);

    send_cluster_message(member, crm_msg_crmd, offer, TRUE);
    free_xml(offer);

    crm_update_peer_join(__FUNCTION__, member, crm_join_welcomed);
    /* crm_update_peer_expected(__FUNCTION__, member, CRMD_JOINSTATE_PENDING); */
}
Beispiel #17
0
static void
throttle_send_command(enum throttle_state_e mode)
{
    xmlNode *xml = NULL;
    static enum throttle_state_e last = -1;

    if(mode != last) {
        crm_info("New throttle mode: %.4x (was %.4x)", mode, last);
        last = mode;

        xml = create_request(CRM_OP_THROTTLE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);
        crm_xml_add_int(xml, F_CRM_THROTTLE_MODE, mode);
        crm_xml_add_int(xml, F_CRM_THROTTLE_MAX, throttle_job_max);

        send_cluster_message(NULL, crm_msg_crmd, xml, TRUE);
        free_xml(xml);
    }
}
Beispiel #18
0
void
join_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void *user_data)
{
    xmlNode *local_cib = NULL;
    char *join_id = user_data;
    xmlNode *generation = create_xml_node(NULL, XML_CIB_TAG_GENERATION_TUPPLE);

    CRM_LOG_ASSERT(join_id != NULL);

    query_call_id = 0;

    if (rc == pcmk_ok) {
        local_cib = output;
        CRM_LOG_ASSERT(safe_str_eq(crm_element_name(local_cib), XML_TAG_CIB));
    }

    if (local_cib != NULL) {
        xmlNode *reply = NULL;

        crm_debug("Respond to join offer join-%s", join_id);
        crm_debug("Acknowledging %s as our DC", fsa_our_dc);
        copy_in_properties(generation, local_cib);

        reply = create_request(CRM_OP_JOIN_REQUEST, generation, fsa_our_dc,
                               CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);

        crm_xml_add(reply, F_CRM_JOIN_ID, join_id);
        if (fsa_our_dc) {
            send_cluster_message(crm_get_peer(0, fsa_our_dc), crm_msg_crmd, reply, TRUE);
        } else {
            crm_warn("No DC for join-%s", join_id);
            send_cluster_message(NULL, crm_msg_crmd, reply, TRUE);
        }
        free_xml(reply);

    } else {
        crm_err("Could not retrieve Generation to attach to our"
                " join acknowledgement: %s", pcmk_strerror(rc));
        register_fsa_error_adv(C_FSA_INTERNAL, I_ERROR, NULL, NULL, __FUNCTION__);
    }

    free(join_id);
    free_xml(generation);
}
Beispiel #19
0
bool t_phone_user::send_im_iscomposing(const t_url &to_uri, const string &to_display, 
			const string &state, time_t refresh)
{
	t_request *req = create_request(MESSAGE, to_uri);
	
	// To
	req->hdr_to.set_uri(to_uri);
	req->hdr_to.set_display(to_display);

	// Call-ID
	req->hdr_call_id.set_call_id(NEW_CALL_ID(user_config));

	// CSeq
	req->hdr_cseq.set_method(MESSAGE);
	req->hdr_cseq.set_seqnr(NEW_SEQNR);
	
	// Body and Content-Type
	t_im_iscomposing_xml_body *body = new t_im_iscomposing_xml_body;
	MEMMAN_NEW(body);
	
	body->set_state(state);
	body->set_refresh(refresh);
	
	req->body = body;
	req->hdr_content_type.set_media(body->get_media());
	
	// Store and send request
	// Delete a possible pending options request
	if (r_message) {
		// RFC 3428 8
		// Send only 1 message at a time.
		// Store the message. It will be sent if the previous
		// message transaction is finished.
		pending_messages.push_back(req);
	} else {
		r_message = new t_client_request(user_config, req, 0);
		MEMMAN_NEW(r_message);
		phone->send_request(user_config, req, r_message->get_tuid());
		MEMMAN_DELETE(req);
		delete req;
	}
	
	return true;
}
Beispiel #20
0
PJ_DEF(pj_status_t) pjsip_regc_unregister_all(pjsip_regc *regc,
					      pjsip_tx_data **p_tdata)
{
    pjsip_tx_data *tdata;
    pjsip_contact_hdr *hcontact;
    pjsip_hdr *hdr;
    pjsip_msg *msg;
    pj_status_t status;

    PJ_ASSERT_RETURN(regc && p_tdata, PJ_EINVAL);

    pj_lock_acquire(regc->lock);

    if (regc->timer.id != 0) {
	pjsip_endpt_cancel_timer(regc->endpt, &regc->timer);
	regc->timer.id = 0;
    }

    status = create_request(regc, &tdata);
    if (status != PJ_SUCCESS) {
	pj_lock_release(regc->lock);
	return status;
    }

    msg = tdata->msg;

    /* Clear removed_contact_hdr_list */
    pj_list_init(&regc->removed_contact_hdr_list);

    /* Add Contact:* header */
    hcontact = pjsip_contact_hdr_create(tdata->pool);
    hcontact->star = 1;
    pjsip_msg_add_hdr(msg, (pjsip_hdr*)hcontact);
    
    /* Add Expires:0 header */
    hdr = (pjsip_hdr*) pjsip_expires_hdr_create(tdata->pool, 0);
    pjsip_msg_add_hdr(msg, hdr);

    pj_lock_release(regc->lock);

    *p_tdata = tdata;
    return PJ_SUCCESS;
}
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;
}
Beispiel #22
0
static void read_char(struct bt_dis *dis, GAttrib *attrib, uint16_t handle,
				GAttribResultFunc func, gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(dis, user_data);
	if (!req)
		return;

	id = gatt_read_char(attrib, handle, func, req);

	if (set_and_store_gatt_req(dis, req, id))
		return;

	error("dis: Could not read characteristic");
	g_attrib_cancel(attrib, id);
	free(req);
}
static int send_groupchatpacket(Group_Chat *chat, IP_Port ip_port, uint8_t *public_key, uint8_t *data, uint32_t length,
                                uint8_t request_id)
{
    if (id_equal(chat->self_public_key, public_key))
        return -1;

    uint8_t packet[MAX_DATA_SIZE];
    int len = create_request(chat->self_public_key, chat->self_secret_key, packet, public_key, data, length, request_id);
    packet[0] = NET_PACKET_GROUP_CHATS;

    if (len == -1)
        return -1;

    if (sendpacket(chat->net, ip_port, packet, len) == len)
        return 0;

    return -1;

}
Beispiel #24
0
static void discover_desc(struct bt_scpp *scpp, GAttrib *attrib,
				uint16_t start, uint16_t end, bt_uuid_t *uuid,
				gatt_cb_t func, gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(scpp, user_data);
	if (!req)
		return;

	id = gatt_discover_desc(attrib, start, end, uuid, func, req);
	if (set_and_store_gatt_req(scpp, req, id))
		return;

	error("scpp: Could not discover descriptor");
	g_attrib_cancel(attrib, id);
	free(req);
}
Beispiel #25
0
	bool	as_loadvars::load(const char * c_url)
	{
		lfl_string host, uri;
		request_data request;

		if( parse_url(c_url, host, uri) )
		{
			request.m_iface = new net_interface_tcp();
			request.m_ns = request.m_iface->connect(host, 80);
		}

		bool is_connected = request.m_ns ? true : false;

		if( !is_connected )
		{
			as_value function;
			if (get_member("onLoad", &function))
			{
				as_environment env(get_player());
				env.push(false);
				call_method(function, &env, this, 1, env.get_top_index());
			}

			delete request.m_iface;

			return false;
		}

		request.m_target = this;
		get_root()->add_listener(this);

		m_headers.set("Host", host);

		lfl_string request_string = create_request( "GET", uri, true );

		printf( request_string.c_str() );
		request.m_ns->write_string(request_string, 1);
		request.m_state = PARSE_REQUEST;

		m_requests.push_back( request );

		return true;
	}
/* ELECTION投票処理 */
void
election_vote(election_t *e)
{
    struct timeval age;
    xmlNode *vote = NULL;
    crm_node_t *our_node;

    if(e == NULL) {
        crm_trace("Not voting in election: not initialized");
        return;
    }

    our_node = crm_get_peer(0, e->uname);
    if (our_node == NULL || crm_is_peer_active(our_node) == FALSE) {
        crm_trace("Cannot vote yet: %p", our_node);
        return;
    }
	/* 自ノードの情報を生成する */
    e->state = election_in_progress;
    /* CRM_OP_VOTE(F_ATTRD_TASKフィールド)メッセージを生成する */
    vote = create_request(CRM_OP_VOTE, NULL, NULL, CRM_SYSTEM_CRMD, CRM_SYSTEM_CRMD, NULL);

    e->count++;
    crm_xml_add(vote, F_CRM_ELECTION_OWNER, our_node->uuid);
    crm_xml_add_int(vote, F_CRM_ELECTION_ID, e->count);

    crm_uptime(&age);
    crm_xml_add_int(vote, F_CRM_ELECTION_AGE_S, age.tv_sec);
    crm_xml_add_int(vote, F_CRM_ELECTION_AGE_US, age.tv_usec);
	/* クラスタに投票メッセージを送信する */
    send_cluster_message(NULL, crm_msg_crmd, vote, TRUE);
    free_xml(vote);

    crm_debug("Started election %d", e->count);
    if (e->voted) {
        g_hash_table_destroy(e->voted);
        e->voted = NULL;
    }
	/* ELECTIONのタイマーを開始する */
    election_timeout_start(e);
    return;
}
Beispiel #27
0
belle_sip_request_t *belle_sip_dialog_create_request(belle_sip_dialog_t *obj, const char *method){
	belle_sip_request_t *req;

	if (obj->state != BELLE_SIP_DIALOG_CONFIRMED && obj->state != BELLE_SIP_DIALOG_EARLY) {
		belle_sip_error("belle_sip_dialog_create_request(): cannot create [%s] request from dialog [%p] in state [%s]",method,obj,belle_sip_dialog_state_to_string(obj->state));
		return NULL;
	}
	/*don't prevent to send a BYE in any case */
	if (strcmp(method,"BYE")!=0 && obj->last_transaction && belle_sip_transaction_state_is_transient(belle_sip_transaction_get_state(obj->last_transaction))){

		if (obj->state != BELLE_SIP_DIALOG_EARLY && strcmp(method,"UPDATE")!=0) {
			belle_sip_error("belle_sip_dialog_create_request(): cannot create [%s] request from dialog [%p] while pending [%s] transaction in state [%s]",method,obj,belle_sip_transaction_get_method(obj->last_transaction), belle_sip_transaction_state_to_string(belle_sip_transaction_get_state(obj->last_transaction)));
			return NULL;
		} /*else UPDATE transaction can be send in // */
	}
	belle_sip_dialog_update_local_cseq(obj,method);
	
	req=create_request(obj,method,TRUE);
	return req;
}
Beispiel #28
0
int main(){
	char c;
	int fd;
	srandom(time(NULL));
	/* 在循环中模拟访存请求与处理过程 */
	while (TRUE)
	{
		bzero(&cmd,DATALEN);
		printf("按Y打印页表,按V打印辅存,按A打印实存\n按C手动产生请求,按N随机产生新请求,按X退出程序...\n");
		c = getchar();
		if(c == 'n' || c == 'N'){
			cmd.c = 'n';
			do_request();
		}
		else if(c == 'c' || c == 'C'){
			cmd.c = 'c';
			create_request();
		}
		else
			cmd.c = c;

		if((fd = open("/tmp/server",O_WRONLY)) < 0)
		{
			printf("enq open fifo failed");
			exit(1);
		}

		if(write(fd,&cmd,DATALEN) < 0)
		{
			printf("enq write failed");
			exit(1);
		}
//		printf("ok\n");

		close(fd);
		if(c == 'x' || c == 'X')
			break;
		while((c = getchar()) != '\n');
	}
	return 0;
}
Beispiel #29
0
static void discover_char(struct bt_dis *dis, GAttrib *attrib,
						uint16_t start, uint16_t end,
						bt_uuid_t *uuid, gatt_cb_t func,
						gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(dis, user_data);
	if (!req)
		return;

	id = gatt_discover_char(attrib, start, end, uuid, func, req);

	if (set_and_store_gatt_req(dis, req, id))
		return;

	error("dis: Could not send discover characteristic");
	g_attrib_cancel(attrib, id);
	free(req);
}
Beispiel #30
0
static void write_char(struct bt_scpp *scan, GAttrib *attrib, uint16_t handle,
					const uint8_t *value, size_t vlen,
					GAttribResultFunc func,
					gpointer user_data)
{
	struct gatt_request *req;
	unsigned int id;

	req = create_request(scan, user_data);
	if (!req)
		return;

	id = gatt_write_char(attrib, handle, value, vlen, func, req);

	if (set_and_store_gatt_req(scan, req, id))
		return;

	error("scpp: Could not read char");
	g_attrib_cancel(attrib, id);
	free(req);
}