// Indication FairP2P event: delivery // Internal thread to wait for messages from other nodes void * mythread(void * arg) { char msg[BUFSIZE]; /* message buf */ char src[BUFSIZE]; /* source node */ printf("Thread to receive messages is run...\n"); while(1) { delivery(src, msg); fp2pDelivery(src, msg); } pthread_exit(NULL); }
void ConnectionContext::send(boost::shared_ptr<SenderContext> snd, const qpid::messaging::Message& message, bool sync) { qpid::sys::ScopedLock<qpid::sys::Monitor> l(lock); SenderContext::Delivery* delivery(0); while (!(delivery = snd->send(message))) { QPID_LOG(debug, "Waiting for capacity..."); wait();//wait for capacity } wakeupDriver(); if (sync) { while (!delivery->accepted()) { QPID_LOG(debug, "Waiting for confirmation..."); wait();//wait until message has been confirmed } } }
int execute_delivery(struct db_context_t *dbc, struct delivery_t *data) { int rc; int nvals=3; char * vals[3]; dbt2_init_values(vals, nvals); rc=delivery(dbc, data, vals, nvals); if (rc == -1 ) { LOG_ERROR_MESSAGE("DELIVERY FINISHED WITH ERRORS \n"); //should free memory that was allocated for nvals vars dbt2_free_values(vals, nvals); return ERROR; } return OK; }
/* * execute delivery transaction */ static int do_delivery (int t_num) { int c_num; int i,ret; clock_t clk1,clk2; double rt; struct timespec tbuf1; struct timespec tbuf2; int w_id, o_carrier_id; if(num_node==0){ w_id = RandomNumber(1, num_ware); }else{ c_num = ((num_node * t_num)/num_conn); /* drop moduls */ w_id = RandomNumber(1 + (num_ware * c_num)/num_node, (num_ware * (c_num + 1))/num_node); } o_carrier_id = RandomNumber(1, 10); clk1 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf1 ); for (i = 0; i < MAX_RETRY; i++) { ret = delivery(t_num, w_id, o_carrier_id); clk2 = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tbuf2 ); if(ret){ rt = (double)(tbuf2.tv_sec * 1000.0 + tbuf2.tv_nsec/1000000.0-tbuf1.tv_sec * 1000.0 - tbuf1.tv_nsec/1000000.0); if(rt > max_rt[3]) max_rt[3]=rt; hist_inc(3, rt ); if(counting_on){ if( rt < RTIME_DELIVERY ){ success[3]++; success2[3][t_num]++; }else{ late[3]++; late2[3][t_num]++; } } return (1); /* end */ }else{ if(counting_on){ retry[3]++; retry2[3][t_num]++; } } } if(counting_on){ retry[3]--; retry2[3][t_num]--; failure[3]++; failure2[3][t_num]++; } return (0); }