int iterate_usb(int (is_interesting)(struct usb_device *), int (do_open)(struct usb_dev_handle *), int (do_process)(struct usb_dev_handle *), int (do_close)(struct usb_dev_handle *) ) { usb_find_busses(); usb_find_devices(); int result = 0; struct usb_bus *bus; struct usb_device *dev; for (bus = usb_busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { if (is_interesting(dev)) { struct usb_dev_handle *handle = open_handle_for_device(dev, do_open); if (handle) { if (do_process) result += do_process(handle); if (do_close) result += close_handle(handle, do_close); } else { result += 1; } } } } return result; }
/*override*/void process( job& j ) { do_process(j); //wait until the gate is open. while( gate==0 ) Harness::Sleep(1); __TBB_ASSERT( nesting.limit<=2, NULL ); if( nesting.level>=nesting.limit ) return; size_type max_outstanding_connections = max_job_count(); // if nesting.level==0 if( nesting.level==1 ) max_outstanding_connections *= (1+max_outstanding_connections); if( default_concurrency()<=max_outstanding_connections+2 ) // i.e., if it is not guaranteed that at least two connections may be made without depleting the_balance return; // at this point, ( nesting.level<nesting.limit ) && ( my_server->default_concurrency()-max_outstanding_connections>2 ) for( ;; ) { while( n_available_hw_threads<=1 ) Harness::Sleep(1); int n = --n_available_hw_threads; if( n>0 ) break; // else I lost ++n_available_hw_threads; } DoOneConnection<MyFactory,MyClient> doc(max_job_count(),Nesting(nesting.level+1,nesting.limit),0,false); doc(0); ++n_available_hw_threads; }
/*override*/void process( job& j, void* cookie, size_type index ) { MyTeam& t = *static_cast<MyTeam*>(cookie); ASSERT( t.self_ptr==&t, "trashed cookie" ); ASSERT( index<t.max_thread, NULL ); ASSERT( !t.info[index].ran, "duplicate index?" ); t.info[index].job = &j; t.info[index].ran = true; do_process(j); if( index==1 && nesting.level<nesting.limit ) { DoOneConnection<MyFactory,MyClient> doc(MaxThread,Nesting(nesting.level+1,nesting.limit),0,false); doc(0); } #if _WIN32||_WIN64 // test activate/deactivate if( t.n_thread>1 && t.n_thread%2==0 ) { if( nesting.level==0 ) { if( index&1 ) { size_type target = index-1; ASSERT( target<t.max_thread, NULL ); // wait until t.info[target].job is defined tbb::internal::spin_wait_until_eq( t.info[target].ran, true ); server->try_increase_load( 1, true ); server->reactivate( t.info[target].job ); } else { server->deactivate( &j ); } } } #endif /* _WIN32||_WIN64 */ ++t.barrier; }
void read_cb(EV_P_ struct ev_io *w, int revent) { connection_t *con = (connection_t *) w->data; dbgin(); do_process(con); }
static void do_process(int depth, SReference rest, SVectorRef &vec, bool rs) { SExpressionCons *dp = rest.DynamicCastGetPtr<SExpressionCons>(); if(!dp) { vec = new SExpressionVector(rs ? 0 : depth); } else { do_process(depth+1, dp->Cdr(), vec, rs); vec[depth] = dp->Car(); } }
error_type_t AudioFilter::process(audio_buffer_t& buffer) { error_type_t ret = error_type_t::ok; if (child_) { ret = child_->process(buffer); if (ret != error_type_t::ok) return ret; } return do_process(buffer); }
void invert_node_t::do_process( const render::context_t& context) { Imath::Box2i area( Imath::intersect( input_as<image_node_t>()->defined(), defined())); if( area.isEmpty()) return; if( get_value<int>( param( "channels"))) boost::gil::fill_pixels( image_view(), image::pixel_t( 0, 0, 0, 1)); do_process( input_as<image_node_t>()->const_subimage_view( area), subimage_view( area), context); }
void RequestProcessor::do_process_request(PROCESS_RHS_FUNC_T pproc, PacketWrapper *wrapper) { MultiWrapper *multi_wrapper = dynamic_cast<MultiWrapper*>(wrapper); if (multi_wrapper != NULL) { do_process(pproc, multi_wrapper); } else { log_error("the wrapper should be MultiWrapper, pcode: %d", wrapper->get_packet()->getPCode()); } }
void RequestProcessor::do_process_request(PROCESS_RH_FUNC_T pproc, PacketWrapper *wrapper) { SingleWrapper *single_wrapper = dynamic_cast<SingleWrapper*>(wrapper); if (single_wrapper != NULL) { do_process(pproc, single_wrapper); } else { log_error("the wrapper should be SingleWrapper, pcode: %d", wrapper->get_packet()->getPCode()); } }
int main(int argc, char **argv) { extern char *__progname; int ret, c; ret = 0; while ((c = getopt(argc, argv, "fFlpPrstT")) != -1) { switch (c) { case 'f': ret |= check_inheritance(); break; case 'F': ret |= do_fdpass(); break; case 'l': ret |= do_flock(); break; case 'p': ret |= do_pipe(); break; case 'P': ret |= do_process(); break; case 'r': ret |= do_random(); break; case 's': ret |= do_signal(); break; case 't': ret |= do_tun(); break; case 'T': ret |= do_pty(); break; default: fprintf(stderr, "Usage: %s -[fPprTt]\n", __progname); exit(1); } } return (ret); }
int main (int argc, char **argv) { //初始化必要的资源 if( init_resource() < 0 ){ debug(LOG_ERR, " init_resource fail !"); return -1; } parse_commandline(argc, argv); /* Init the signals to catch chld/quit/etc */ init_signals(); if( do_process() < 0 ) { debug(LOG_ERR, " do_process fail !"); exit(-1); } debug(LOG_ERR, "%s : QUIT do_process()",__FUNCTION__); return 0; }
static SReference process_fixed_vectors(const SReference &list, void*) { SVectorRef vr; do_process(0, list, vr, false); return vr; }
static SReference process_resizeable_vectors(const SReference &list, void*) { SVectorRef vr; do_process(0, list, vr, true); return vr; }
inline void operator()( const boost::asio::ip::udp::endpoint& sender_endpoint) { do_process(sender_endpoint); }
int F847119(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) { int ret=0; char h_password[7] = ""; //卡密码 char seed_key[17] = ""; //种子密钥 T_t_pif_card tCard; T_t_tif_tradeserial tradeserial; T_t_tif_writefailed tWriteFailed; T_t_cif_customer tCustomer; ST_CPACK aPack; ST_PACK *out_pack = &(aPack.pack); memset(&tCard,0,sizeof(tCard)); memset(&tradeserial,0,sizeof(tradeserial)); memset(&tWriteFailed, 0, sizeof tWriteFailed); memcpy(seed_key,STATIC_SEED_KEY,sizeof(seed_key)); //读种子密钥 ResetNormalCPack(&aPack,0,1); SetCol(handle,0); SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL5,F_LVOL6, F_SCUST_NO, F_SCUST_NO2,F_SCUST_AUTH,F_SCUST_AUTH2, F_SDATE0,F_SNAME,F_SNAME2, F_SOPEN_EMP,F_SSTATUS0, F_DAMT2,F_LSERIAL1,F_VSMESS, F_SORDER0,F_SORDER1,F_SORDER2, F_SHOLDER_AC_NO,F_SSTAT_TYPE,F_SSTAT_TYPE2, F_SNATION_CODE,F_SBRANCH_CODE0, 0); /************************************************************************/ ret = do_process(&tCard, &tWriteFailed, rPack, &tradeserial); if (ret) { *pRetCode = ret; goto L_RETU; } ret=DB_t_cif_customer_read_lock_by_cur_and_cut_id(tCard.cosumer_id, &tCustomer); if(ret) { writelog(LOG_ERR,"cut_id[%d]",tCard.cosumer_id); if(DB_NOTFOUND==ret) *pRetCode = E_CUSTOMER_NOT_EXIST; else *pRetCode = E_DB_CUSTOMER_R; goto L_RETU; } EncodePwd(seed_key,h_password,tCard.password,1); //卡密码 DB_t_cif_customer_free_lock_cur(); if(amtcmp(tradeserial.out_balance,0)<0) { *pRetCode=E_ENTER_ACCOUNT; goto L_RETU; } sprintf(out_pack->vsmess,"流水号:%d 补写金额:%.2lf元 补写前卡余额:%.2lf元 卡当前余额:%.2lf元",tradeserial.serial_no,tradeserial.trade_fee,tradeserial.in_balance,tradeserial.out_balance); writelog(LOG_DEBUG,out_pack->vsmess); out_pack->lvol0 = tCard.card_id; //交易卡号 out_pack->lvol1 = tCustomer.cut_type; //客户类别 out_pack->lvol5 = tCustomer.fee_type; //收费类别 des2src(out_pack->scust_no,tCard.showid); //显示卡号 des2src(out_pack->scust_no2,tCustomer.classdept_no); //部门号 des2src(out_pack->scust_auth,tCustomer.stuemp_no); //学号 des2src(out_pack->scust_auth2,tCustomer.man_id); //身份证号 des2src(out_pack->sname,tCustomer.cut_name); //客户姓名 des2src(out_pack->sname2,tCustomer.lib_cardid); //图书证号 des2src(out_pack->sstatus0,tCustomer.sex); //性别 des2src(out_pack->sopen_emp,h_password); //卡密码 des2src(out_pack->sdate0,tCard.end_time); //有效截至日期 strcpy(out_pack->sorder0,CARD_STRUCT_VERSION); //制卡版本号 strcpy(out_pack->sorder1,CARD_REGISTER_PUBLISH_CODE); //发卡注册标识号 strcpy(out_pack->sorder2,CARD_REGISTER_SERVICE_CODE); //服务注册标识号 sprintf(out_pack->sholder_ac_no,"%d",tCustomer.cut_id); //客户号 des2src(out_pack->sstat_type,tCustomer.man_idtype); //证件类型 des2src(out_pack->snation_code,tCustomer.country); //国籍 sprintf(out_pack->sstat_type2,"%d",tCustomer.nation); //民族 des2src(out_pack->sbranch_code0,tCustomer.school_code); //院校代码 out_pack->damt2=tradeserial.out_balance; //出卡值=入卡值+发生额 out_pack->lserial1=tradeserial.serial_no; //流水号 PutRow(handle,out_pack,pRetCode,szMsg); return 0; L_RETU: return -1; }
int do_loop(void) { int efd; int sfd; int rc; int connfd; struct epoll_event event; struct epoll_event *events; tor_array_t *cache_sock; cache_sock = tor_array_new(TOR_MAX_EVENT, sizeof(http_context *)); events = calloc(TOR_MAX_EVENT, sizeof(struct epoll_event)); if (!events) { perror(""); exit(EXIT_FAILURE); } rc = 0; sfd = create_and_bind(INADDR_ANY, config.port); if (sfd < 0) { exit(EXIT_FAILURE); } rc = set_fl(sfd, O_NONBLOCK); if (rc < 0) { exit(EXIT_FAILURE); } rc = listen(sfd, 10); if (rc < 0) { perror("listen"); exit(EXIT_FAILURE); } efd = epoll_create1(0); if (efd < 0) { perror(""); exit(EXIT_FAILURE); } if (fd_add(efd, sfd) < 0) exit(EXIT_FAILURE); int i, n; http_context *http; for (;;) { n = epoll_wait(efd, events, TOR_MAX_EVENT, -1); for (i = 0; i < n; i++) { if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP) || !(events[i].events & EPOLLIN)) { close(events[i].data.fd); tor_log_err("epoll error %d\n", events[i].data.fd); } else if (events[i].data.fd == sfd) { for (;;) { connfd = accept(sfd, NULL, NULL); if (connfd == -1) { if ((errno != EAGAIN) && (errno != EWOULDBLOCK)) { perror("accept"); } break; } if (set_fl(connfd, O_NONBLOCK) < 0) { perror("set_fl"); exit(EXIT_FAILURE); } if (fd_add(efd, connfd) < 0) { perror("fd_add"); exit(EXIT_FAILURE); } http = http_new(connfd, list_dir, sock_read, writen_nonblock); fprintf(stderr, "put fd = %d:sfd = %d http = %p\n", connfd, sfd, http); tor_array_put(cache_sock, connfd, &http); } } else { fprintf(stderr, "get fd = %d\n", events[i].data.fd); http = *(http_context **)tor_array_get(cache_sock, events[i].data.fd); fprintf(stderr, "fd = %d\n", http->fd); http_read_head(http); do_process(http); http_free(http); } } fprintf(stderr, "=============\n"); } close(sfd); close(efd); }
int F847119(TRUSERID *handle,int iRequest,ST_PACK *rPack,int *pRetCode,char *szMsg) { int ret=0; char h_password[7] = ""; //卡密码 char seed_key[17] = ""; //种子密钥 T_t_card tCard; T_t_tif_tradeserial tradeserial; T_t_tif_writefailed tWriteFailed; T_t_customer tCustomer; ST_CPACK aPack; ST_PACK *out_pack = &(aPack.pack); memset(&tCard,0,sizeof(tCard)); memset(&tradeserial,0,sizeof(tradeserial)); memset(&tWriteFailed, 0, sizeof tWriteFailed); memcpy(seed_key,STATIC_SEED_KEY,sizeof(seed_key)); //读种子密钥 ResetNormalCPack(&aPack,0,1); SetCol(handle,0); SetCol(handle,F_LVOL0,F_LVOL1,F_LVOL5,F_LVOL6, F_SCUST_NO, F_SCUST_NO2,F_SCUST_AUTH,F_SCUST_AUTH2, F_SDATE0,F_SNAME,F_SNAME2, F_SOPEN_EMP,F_SSTATUS0, F_DAMT2,F_LSERIAL1,F_VSMESS,0); /************************************************************************/ ret = do_process(&tCard, &tWriteFailed, rPack, &tradeserial); if (ret) { *pRetCode = ret; goto L_RETU; } ret=DB_t_customer_read_lock_by_cur_and_custid(tCard.custid, &tCustomer); if(ret) { writelog(LOG_ERR,"custid[%d]",tCard.custid); if(DB_NOTFOUND==ret) *pRetCode = E_CUSTOMER_NOT_EXIST; else *pRetCode = E_DB_CUSTOMER_R; goto L_RETU; } EncodePwd(seed_key,h_password,tCard.password,1); //卡密码 DB_t_customer_free_lock_cur(); if(amtcmp(tradeserial.out_balance,0)<0) { *pRetCode=E_ENTER_ACCOUNT; goto L_RETU; } sprintf(out_pack->vsmess,"流水号:%d 补写金额:%.2lf元 补写前卡余额:%.2lf元 卡当前余额:%.2lf元",tradeserial.serial_no,tradeserial.trade_fee,tradeserial.in_balance,tradeserial.out_balance); writelog(LOG_DEBUG,out_pack->vsmess); out_pack->lvol0 = tCard.cardno; //交易卡号 out_pack->lvol1 = tCustomer.custtype; //客户类别 out_pack->lvol5 = tCustomer.feetype; //收费类别 des2src(out_pack->scust_no,tCard.showid); //显示卡号 des2src(out_pack->scust_no2,tCustomer.deptcode); //部门号 des2src(out_pack->scust_auth,tCustomer.stuempno); //学号 des2src(out_pack->scust_auth2,tCustomer.man_id); //身份证号 des2src(out_pack->sname,tCustomer.custname); //客户姓名 des2src(out_pack->sname2,tCustomer.lib_cardid); //图书证号 des2src(out_pack->sstatus0,tCustomer.sex); //性别 des2src(out_pack->sopen_emp,h_password); //卡密码 des2src(out_pack->sdate0,tCard.endtime); //有效截至日期 out_pack->damt2=tradeserial.out_balance; //出卡值=入卡值+发生额 out_pack->lserial1=tradeserial.serial_no; //流水号 PutRow(handle,out_pack,pRetCode,szMsg); return 0; L_RETU: return -1; }
void do_process_shared_prt_2(const std::shared_ptr<char>& data, std::size_t size) { do_process(data.get(), size); }
void do_process_shared_prt(const boost::shared_ptr<char[]>& data, std::size_t size) { do_process(data.get(), size); }
int vfs_signalling_thread(void *arg) { t_thread_arg *argp = (t_thread_arg *)arg; if (sub_init_signalling(argp->name)) { LOG(glogfd, LOG_ERROR, "sub_init_signalling %s err %m\n", argp->name); stop = 1; return -1; } if (argp->port > 0) { lfd = get_listen_sock(argp->port); if (lfd < 0) { LOG(glogfd, LOG_ERROR, "get_listen_sock err %d\n", argp->port); stop = 1; return -1; } LOG(glogfd, LOG_DEBUG, "%s listen on %d\n", argp->name, argp->port); } maxevent = argp->maxevent; epfd = epoll_create(maxevent); if(epfd < 0) { LOG(glogfd, LOG_ERROR, "epoll_create(%d): %m\n", maxevent); stop = 1; return -1; } pev = (struct epoll_event*)malloc(sizeof(struct epoll_event) * maxevent); if(pev == NULL) { LOG(glogfd, LOG_ERROR, "allocate epoll_event(%d): %m\n", maxevent); stop = 1; return -1; } if (argp->port > 0) { if (argp->flag) set_socket_attr(lfd); } iobuf = malloc(init_buff_size); if (iobuf == NULL) { LOG(glogfd, LOG_ERROR, "allocate iobuf [%d] error %m\n", init_buff_size); stop = 1; return -1; } struct threadstat *thst = get_threadstat(); int event = EPOLLIN; if (argp->port > 0) epoll_add(epfd, lfd, event); int n = 0, i = 0; time_t last = time(NULL); time_t now = last; LOG(glogfd, LOG_DEBUG, "%s:%s:%d\n", ID, FUNC, LN); while (!stop) { n = epoll_wait(epfd, pev, maxevent, 1000); for(i = 0; i < n; i++) { if (argp->port > 0 && pev[i].data.fd == lfd) accept_new(); else do_process(pev[i].data.fd, pev[i].events); } thread_reached(thst); now = time(NULL); if (now > last + g_config.cktimeout) { last = now; if (solib.svc_timeout) solib.svc_timeout(); } } return 0; }