void bfmcommIroIro<Float>::comm_start (int result_cb, Fermion_t psi,int dag) { // gather the faces. Routines here are threaded. // All threads cooperate in gathering. int me = this->thread_barrier(); if ( me == 0 ) { recv_init((Fermion_t)psi); } this->thread_barrier(); gather (result_cb,psi,dag); this->thread_barrier(); if ( me == 0 ) { // Slow initial implementation // Ideally insert BGNET calls and exit here after the BGNET_Put starts // running asynchronously. for(int mu=0;mu<4;mu++){ int simd_factor = this->simd(); simd_factor = simd_factor/this->simd_grid[mu]; int words = this->simd_nbound[mu] * HALF_SPINOR_SIZE * simd_factor * this->cbLs; int idx=2*mu; int idxp=2*mu+1; Communicator::instance()->transfer_bk((double *)this->simd_rbuf[idx],(double *)this->sendbufs[idx],words,mu); Communicator::instance()->transfer_fw((double *)this->simd_rbuf[idxp],(double *)this->sendbufs[idxp],words,mu); } } this->thread_barrier(); return; }
bool cPluginMcli::InitMcli (void) { if(m_recv_init_done && (m_mld_init_done || !m_cmd.mld_start) && m_api_init_done && m_mmi_init_done) return true; int ifacelen = strlen(m_cmd.iface); if(ifacelen) { // Check if iface exists FILE *file = fopen("/proc/net/if_inet6", "r"); if(!file) return false; bool found = false; char buf[255]; while(fgets(buf, sizeof(buf), file)) { int buflen = strlen(buf); while(buf[buflen-1]=='\n') buf[--buflen] = 0; while(buf[buflen-1]=='\r') buf[--buflen] = 0; while(buf[buflen-1]==' ' ) buf[--buflen] = 0; if((buflen >= ifacelen) && (!strcmp(&buf[buflen-ifacelen], m_cmd.iface))) { found = true; break; } } fclose(file); if(!found) return false; } // Ok, iface exists so go on if (!m_recv_init_done) { if(!recv_init (m_cmd.iface, m_cmd.port)) m_recv_init_done = 1; else return false; } if (!m_mld_init_done && m_cmd.mld_start) { if(!mld_client_init (m_cmd.iface)) m_mld_init_done = 1; else return false; } if (!m_api_init_done) { if(!api_sock_init (m_cmd.cmd_sock_path)) m_api_init_done = 1; else return false; } if(!m_mmi_init_done) { if((m_cam_mmi = mmi_broadcast_client_init (m_cmd.port, m_cmd.iface)) != NULL) m_mmi_init_done = 1; else return false; } for(int i=m_devs.Count(); i < MCLI_MAX_DEVICES; i++) { cMcliDevice *m = NULL; cPluginManager::CallAllServices ("OnNewMcliDevice-" MCLI_DEVICE_VERSION, &m); if(!m) { m = new cMcliDevice; } if(m) { m->SetMcliRef (this); cMcliDeviceObject *d = new cMcliDeviceObject (m); m_devs.Add (d); } } return true; }
int recv_run(pthread_mutex_t *recv_ready_mutex) { log_trace("recv", "recv thread started"); log_debug("recv", "capturing responses on %s", zconf.iface); if (!zconf.dryrun) { recv_init(); } if (zconf.send_ip_pkts) { struct ether_header *eth = (struct ether_header *) fake_eth_hdr; memset(fake_eth_hdr, 0, sizeof(fake_eth_hdr)); eth->ether_type = htons(ETHERTYPE_IP); } // initialize paged bitmap seen = pbm_init(); if (zconf.filter_duplicates) { log_debug("recv", "duplicate responses will be excluded from output"); } else { log_debug("recv", "duplicate responses will be included in output"); } if (zconf.filter_unsuccessful) { log_debug("recv", "unsuccessful responses will be excluded from output"); } else { log_debug("recv", "unsuccessful responses will be included in output"); } pthread_mutex_lock(recv_ready_mutex); zconf.recv_ready = 1; pthread_mutex_unlock(recv_ready_mutex); zrecv.start = now(); if (zconf.max_results == 0) { zconf.max_results = -1; } do { if (zconf.dryrun) { sleep(1); } else { recv_packets(); if (zconf.max_results && zrecv.success_unique >= zconf.max_results) { break; } } } while (!(zsend.complete && (now()-zsend.finish > zconf.cooldown_secs))); zrecv.finish = now(); // get final pcap statistics before closing recv_update_stats(); if (!zconf.dryrun) { pthread_mutex_lock(recv_ready_mutex); recv_cleanup(); pthread_mutex_unlock(recv_ready_mutex); } zrecv.complete = 1; log_debug("recv", "thread finished"); return 0; }
void eth_init( Hubyte *src ) { Huint i; // Copy the source mac address for( i = 0; i < ETH_MAC_SIZE; i++ ) eth_mac[i] = src[i]; // Initialize the sending functionality //send_init( "eth1" ); send_init( "en0" ); // Initialize the receiving functionality //recv_init( "eth1" ); recv_init( "en0" ); }
int main(){ sa.sa_handler = sigpipe; sigaction(SIGPIPE,&sa, 0); constant_init(); printf("HOSTIP=%s,BROADCASTIP=%s,\n",HOSTIP,BROADCASTIP); beacon_init(); ManageRoute_init(); recv_init(); pthread_t id; pthread_attr_t attr; pthread_attr_init (&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if( pthread_create(&id,&attr,(void*)recv_departure,NULL) !=0 ){ //perror("beacon start error"); printf("recv start error!%s\n",strerror(errno)); //beep(2000,2000); abort(); exit(1); } if( pthread_create(&id,&attr,(void*)beacon,NULL) !=0 ){ //perror("beacon start error"); printf("beacon start error!%s\n",strerror(errno)); //beep(2000,2000); abort(); exit(1); } if( pthread_create(&id,&attr,(void*)ManageRoute,NULL) !=0 ){ //perror("broadcastRoute start error"); printf("ManageRoute start error!%s\n",strerror(errno)); //beep(2000,2000); abort(); exit(1); } pthread_attr_destroy(&attr); printf("--------------------Static Router has started successfully-------------------\n"); while(1){ sleep(1000); } }
portBASE_TYPE transceiver::force_done(void) { if (static_cast<int8>(-1) == buf_queue_put(&m_buf_queue, m_rx_buf, m_rx_index)){ buf_queue_pop(&m_buf_queue); buf_queue_put(&m_buf_queue, m_rx_buf, m_rx_index); } if (m_duplex == HALF_DUPLEX){ m_rx_index = 0; rx_status_set(RX_STAT_DONE); }else { recv_init(); } //initiative call device handle cpu_pendsv_trig(); return 0; }
/** * Called when a new thread is created. * Receives the init packet and then the data packets. * Exits when done or if communication with client is lost. **/ void * do_threading(void * ptr) { int sock_num = (int) ptr; struct sockaddr_in cli_addr; FILE * p_file = malloc(sizeof(FILE)); init_pkt_t * p_init_pkt = malloc(INIT_PKT_SZ); //debug_max("-------- new thread -----------\n"); /* Receive the init packet */ // Keep trying to receive the init pointer // How many times should we try this? int init_res = RES_NO_DATA; while (init_res != RES_SUCCESS) { init_res = recv_init(sock_num, &cli_addr, &p_init_pkt, &p_file); //debug_max("do_threading()/recv_init: init_res = %i\n", init_res); if (init_res == RES_NO_DATA) { debug_errors("do_threading(): did not receive init packet from client; exiting\n"); return NULL; } else if (init_res == RES_FILE_ERR) { debug_errors("do_threading(): could not open file for writing; exiting\n"); return NULL; } } if (init_res != RES_SUCCESS) { debug_errors("do_threading(): could not get the init packet; exiting\n"); return NULL; } /* Receive the data packets */ recv_file(sock_num, &cli_addr, p_init_pkt->hdr.file_len, p_init_pkt->hdr.buffer_sz, p_file); fclose(p_file); free(p_init_pkt); //debug_max("do_threading(): finished with this client\n"); return NULL; }
void find_netcv_adapter(adapter **a) { int i, k, n, na; netceiver_info_list_t *nc_list; adapter *ad; // find 1st free adapter for (na = 0; na < MAX_ADAPTERS; na++) if (!a[na] || (a[na]->pa == -1 && a[na]->fn == -1)) break; /* call recv_init of libmcli to initialize the NetCeiver API */ if(recv_init("vlan4", 23000)) LOGL(0, "Netceiver init failed"); fprintf(stderr, "REEL: Search for %d Netceivers... ", opts.netcv_count); n = 0; do { usleep(500000); fprintf(stderr, "####"); nc_list = nc_get_list(); } while (nc_list->nci_num < opts.netcv_count && n++ < 20); nc_lock_list (); fprintf(stderr, "\n"); // loop trough list of found netceivers and ad them to list of adapters for (n = 0; n < nc_list->nci_num; n++) { netceiver_info_t *nci = nc_list->nci + n; fprintf (stderr, "Found NetCeiver: %s \n", nci->uuid); for (i = 0; i < nci->tuner_num; i++) { // TODO: implement disable (low prio) if (na >= MAX_ADAPTERS) break; if (!a[na]) a[na] = malloc1(sizeof(adapter)); fprintf (stderr, " Tuner: %s, Type %d\n", nci->tuner[i].fe_info.name, nci->tuner[i].fe_info.type); ad = a[na]; ad->pa = 0; ad->fn = 0; sn[na].want_tune = 0; sn[na].want_commit = 0; sn[na].ncv_rec = NULL; /* initialize signal status info */ ad->strength = 0; ad->max_strength = 0xff; ad->status = 0; ad->snr = 0; ad->max_snr = 0xff; ad->ber = 0; /* register callback functions in adapter structure */ ad->open = (Open_device) netcv_open_device; ad->set_pid = (Set_pid) netcv_set_pid; ad->del_filters = (Del_filters) netcv_del_pid; ad->commit = (Adapter_commit) netcv_commit; ad->tune = (Tune) netcv_tune; ad->delsys = (Dvb_delsys) netcv_delsys; ad->post_init = (Adapter_commit) NULL; ad->close = (Adapter_commit) netcv_close; /* register delivery system type */ for (k = 0; k < 10; k++) ad->sys[k] = 0; switch(nci->tuner[i].fe_info.type) { case FE_DVBS2: ad->sys[0] = ad->tp.sys = SYS_DVBS2; ad->sys[1] = SYS_DVBS; break; case FE_QPSK: ad->sys[0] = ad->tp.sys = SYS_DVBS; break; case FE_QAM: ad->sys[0] = ad->tp.sys = SYS_DVBC_ANNEX_A; break; case FE_OFDM: //ad->sys[0] = SYS_DVBT; // DVB-T not yet implemented... break; } na++; // increase number of tuner count } } nc_unlock_list(); // netceivers appearing after this will be recognized by libmcli but will not made available to minisatip for (; na < MAX_ADAPTERS; na++) if (a[na]) a[na]->pa = a[na]->fn = -1; }