ActionPtr VMHL13Model::executeParallelTask(int host_nb, void **host_list, double *flops_amount, double *bytes_amount, double rate){ #define cost_or_zero(array,pos) ((array)?(array)[pos]:0.0) if ((host_nb == 1) && (cost_or_zero(bytes_amount, 0) == 0.0)) return ((HostCLM03Ptr)host_list[0])->execute(flops_amount[0]); else if ((host_nb == 1) && (cost_or_zero(flops_amount, 0) == 0.0)) return communicate((HostCLM03Ptr)host_list[0], (HostCLM03Ptr)host_list[0],bytes_amount[0], rate); else if ((host_nb == 2) && (cost_or_zero(flops_amount, 0) == 0.0) && (cost_or_zero(flops_amount, 1) == 0.0)) { int i,nb = 0; double value = 0.0; for (i = 0; i < host_nb * host_nb; i++) { if (cost_or_zero(bytes_amount, i) > 0.0) { nb++; value = cost_or_zero(bytes_amount, i); } } if (nb == 1) return communicate((HostCLM03Ptr)host_list[0], (HostCLM03Ptr)host_list[1],value, rate); } #undef cost_or_zero THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */ return NULL; }
void NetApply(char *ip){ unsigned char buf[32] = {0}; unsigned char sendbuf[7] ={0x77, 0x6c, 0xf0, 0x0, 0x1, 0x2, (unsigned char)clsGlobal.ipGwDb->devNetFun}; int slen=0, i = 0; communicate(ip, sendbuf, 7, buf, &slen); }
void Simulation::step() { stream(d_domain->set, d_domain->nodes); communicate(d_domain->messengers); postStreamProcess(); collission(d_domain->set, d_domain->nodes); }
/* * Serves echo back service forever. *sfd* is the file descriptor of * the server socket. when the incoming connection from the client is * accepted, this function forks another process and the forked * process communicates with client. The parent process goes back to * the loop and can accept another client. */ void serve(int sfd) { while(1) { int fd; while((fd = accept(sfd, NULL, NULL)) == -1 && errno == EINTR); if(fd == -1) { perror("accept"); } else { int r = fork(); if(r == -1) { perror("fork"); close(fd); } else if(r == 0) { int r = communicate(fd); shutdown(fd, SHUT_WR); close(fd); if(r == 0) { exit(EXIT_SUCCESS); } else { exit(EXIT_FAILURE); } } } } }
RsiServer::RsiServer(int port, SysInfo *sysinfo){ this->_sysinfo = sysinfo; if(signal(SIGCHLD, sig_child) == SIG_ERR){ LOG_ERROR("could not bind SIGCHLD to sig_child"); exit(-1); } if(signal(SIGINT, sig_int) == SIG_ERR){ LOG_ERROR("could not bind SIGINT to sig_int"); exit(-1); } int server_sockfd = listen_port(port); int keep_alive = 1; if(setsockopt(server_sockfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&keep_alive, sizeof(keep_alive)) == -1){ LOG_ERROR("Could not set keep_alive option"); exit(-1); } while(1){ int client_sockfd = accept_client(server_sockfd); pid_t pid = fork(); if(pid == 0){ // child process close(server_sockfd); while (true) { if(communicate(client_sockfd) < 0) exit(-1); } } else{ close(client_sockfd); } } }
// 获取输出有效码率 ErrorTypeEm OutChn_validBitrateGet(char *ip, int outChn, int *outValidBitrate) { unsigned char buf[20]; int i = 0; unsigned char sendbuf[12]; int slen=0; enum ErrorTypeEm res; sendbuf[0]=0x77; sendbuf[1]=0x6C; sendbuf[2]=0x21; sendbuf[3]=(unsigned char)outChn; sendbuf[4]=0x03; memset(buf,0,sizeof(buf)); communicate(ip, sendbuf, 5, buf, &slen); //printf("\n####Recive GetOutChnTSID receive nums=[%d]\n", slen ); if( 9 == slen ){ //for(i=0;i<slen;i++) // printf("Recive OutChn_validBitrateGet buf[%d]=0x[%02x]\n",i, buf[i]); int offset = 5; for (i = 0; i < 4; i++) { *outValidBitrate += buf[offset++] << (i * 8); } res = ok; }else res = error; return res; }
void ParallelBlockCommunicator2D::duplicateOverlaps(MultiBlock2D& multiBlock, modif::ModifT whichData) const { MultiBlockManagement2D const& multiBlockManagement = multiBlock.getMultiBlockManagement(); PeriodicitySwitch2D const& periodicity = multiBlock.periodicity(); // Implement a caching mechanism for the communication structure. if (overlapsModified) { overlapsModified = false; LocalMultiBlockInfo2D const& localInfo = multiBlockManagement.getLocalInfo(); std::vector<Overlap2D> overlaps(multiBlockManagement.getLocalInfo().getNormalOverlaps()); for (pluint iOverlap=0; iOverlap<localInfo.getPeriodicOverlaps().size(); ++iOverlap) { PeriodicOverlap2D const& pOverlap = localInfo.getPeriodicOverlaps()[iOverlap]; if (periodicity.get(pOverlap.normalX,pOverlap.normalY)) { overlaps.push_back(pOverlap.overlap); } } delete communication; communication = new CommunicationStructure2D ( overlaps, multiBlockManagement, multiBlockManagement, multiBlock.sizeOfCell() ); } communicate(*communication, multiBlock, multiBlock, whichData); }
void NetworkClient::update(){ AnnDebug() << "client update"; now = AnnEngine::Instance()->getTimeFromStartUp(); float frameTime = now - last; last = now; communicate(frameTime); }
/******************************************************************** * Runs the naming game for a maximum of <rounds> rounds ********************************************************************/ void NamingGame::run(uint rounds) { uint sender, receiver; srand(time(NULL)); std::string word; // For am maximum of <rounds> rounds for (int i = 0; i < rounds; ++i) { // Choose one random node (sender) sender = chooseNode(); // Choose one random neighbor (receiver) receiver = chooseNeighbor(sender); if (receiver == -1) { --i; continue; } // Choose one random word from the sender; word = chooseWord(sender); // Send him a random word. Hijinks ensue communicate(sender, receiver, word); // FIXME Testing only //printResults(); //if (i % 100 == 0) std::cout << "Round " << i << std::endl; } // ??? (TODO) // Profit! }
struct hiddev_usage_ref* init_report(int d, struct hiddev_report_info* new_ri) { ri = *new_ri; ri.report_type = HID_REPORT_TYPE_OUTPUT; { int version; if (0 != ioctl(d, HIDIOCGVERSION, &version)) fatal(E_RARE, "Can't get hiddev version"); /*printf("hiddev is version 0x%x\n", version);*/ } for (unsigned int u = 0; u <= 63; ++u) { ur[u].report_type = HID_REPORT_TYPE_OUTPUT; ur[u].report_id = ri.report_id; ur[u].field_index = 0; ur[u].usage_index = u; if (0 != ioctl(d, HIDIOCGUCODE, &ur[u])) fatal_e(E_RARE, "Can't get usage code %u", u); } wait(); ur[0].value = 0x10; communicate(d); return ur; }
/** * Create a client and connect to localhost on the specified port. * \param host The host name or ip address to connect to. * \param port The port to connect to. */ void client(char * host, char* port) { #ifdef DEBUG puts("Client start requested."); #endif //resolve domain and port name and connect to target struct addrinfo hints, *res, *rp; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; if (0 != getaddrinfo(host, port, &hints, &res)) { fprintf(stderr, "Error resolving address \"%s\". Exiting.\n", host); exit(1); } //evaluate results for (rp = res; rp != NULL; rp = rp->ai_next) { sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); if (sock == -1) continue; if (connect(sock, rp->ai_addr, rp->ai_addrlen) == 0) break; /* Success */ close(sock); sock = -1; } freeaddrinfo(res); exitIfError(sock,"Error connecting to socket"); //send messages communicate(); }
void MirrorMetadataWork::process(char* bufIn, unsigned bufInLen, char* bufOut, unsigned bufOutLen) { communicate(); // notify mirrorer about completion Program::getApp()->getMetadataMirrorer()->completeSubmittedTasks(nodeID); }
std::pair<IOBufQueue, IOBufQueue> Subprocess::communicateIOBuf( const CommunicateFlags& flags, IOBufQueue data) { std::pair<IOBufQueue, IOBufQueue> out; auto readCallback = [&] (int pfd, int cfd) -> bool { if (cfd == 1 && flags.readStdout_) { return handleRead(pfd, out.first); } else if (cfd == 2 && flags.readStderr_) { return handleRead(pfd, out.second); } else { // Don't close the file descriptor, the child might not like SIGPIPE, // just read and throw the data away. return discardRead(pfd); } }; auto writeCallback = [&] (int pfd, int cfd) -> bool { if (cfd == 0 && flags.writeStdin_) { return handleWrite(pfd, data); } else { // If we don't want to write to this fd, just close it. return false; } }; communicate(std::move(readCallback), std::move(writeCallback)); return out; }
// 获取网络ID ErrorTypeEm GetOutChnNetID(char *ip, int outChn, unsigned int *outNetId) { unsigned char buf[20]; int i = 0; unsigned char sendbuf[12]; int slen=0; //get call channal signal status enum ErrorTypeEm res; sendbuf[0]=0x77; sendbuf[1]=0x6C; sendbuf[2]=0x21; sendbuf[3]=(unsigned char)outChn; sendbuf[4]=0x08; sendbuf[5]=0x01; memset(buf,0,sizeof(buf)); communicate(ip, sendbuf, 6, buf, &slen); //printf("\n####Recive GetOutChnNetID receive nums=[%d]\n", slen ); if( 8 == slen ){ // for(i=0;i<slen;i++) // printf("Recive GetOutChnNetID buf[%d]=0x[%02x]\n",i, buf[i]); *outNetId = ( buf[7]<<8| buf[6]) & 0xffff; res = ok; } else res = error; return res; }
void TelescopeControl::update(double deltaTime) { labelFader.update((int)(deltaTime*1000)); reticleFader.update((int)(deltaTime*1000)); circleFader.update((int)(deltaTime*1000)); // communicate with the telescopes: communicate(); }
void chatInsert(char c) { if (c == '\n') { communicate(); clearChatBuffer(); } else { chatBuffer[chatBufPointer++] = c; } }
int reserve_seat(Client c, char flightNumber[FLIGHT_NUMBER_LENGTH], int seat) { reqMsg.req.comm = RESERVE_SEAT; reqMsg.req.client = c; strncpy(reqMsg.req.flightNumber, flightNumber, FLIGHT_NUMBER_LENGTH); reqMsg.req.seat = seat; communicate(); return respMsg.resp.responseCode; }
int cancel_seat(Client c, char flightNumber[FLIGHT_NUMBER_LENGTH], int seat) { reqMsg.req.comm = CANCEL_SEAT; strncpy(reqMsg.req.flightNumber, flightNumber, FLIGHT_NUMBER_LENGTH); reqMsg.req.seat = seat; reqMsg.req.client = c; communicate(); return respMsg.resp.responseCode; }
/* thread method */ void * handle(void *info){ char buffer[BUFFER_SIZE]; user_info * user = (user_info *)info; while(1){ memset(buffer, 0, BUFFER_SIZE); communicate(buffer, user); } return NULL; }
/*! * Update of ghost cell; */ void LevelSet::exchangeGhosts( ){ std::unordered_map<int,std::vector<long>> &sendList = m_kernel->getMesh()->getGhostExchangeSources() ; std::unordered_map<int,std::vector<long>> &recvList = m_kernel->getMesh()->getGhostExchangeTargets() ; communicate(sendList,recvList); return ; }
int main(int argc, char* argv[]) { // For command-line arguments struct Arguments args; struct sigaction signal_action; parse_arguments(&args, argc, argv); setup_client_signals(&signal_action); communicate(&signal_action, &args); }
int main(int argc, char **argv) { struct settings cfg = {false, false, false}; #ifdef __AFL_LOOP while (__AFL_LOOP(ITERATIONS)) #endif communicate(cfg, STDIN_FILENO, STDOUT_FILENO); return 0; }
int main(int argc, char* argv[]) { // The socket through which we communicate with the client int connection; Arguments args; parse_arguments(&args, argc, argv); connection = connect_to_client(); communicate(connection, &args); return EXIT_SUCCESS; }
int update_reports(const char *host, const char *service) { struct wslay_event_callbacks callbacks = { recv_callback, send_callback, genmask_callback, NULL, /* on_frame_recv_start_callback */ NULL, /* on_frame_recv_callback */ NULL, /* on_frame_recv_end_callback */ NULL, /* on_msg_recv_callback */ }; return communicate(host, service, "/updateReports?&agent=wslay", &callbacks); }
void RefreshIpInOutMode(char *ip){ unsigned char buf[32] = {0}; unsigned char sendbuf[6] ={0x77,0x6c,0xf0,0x0, 0x1, 0x1}; int slen=0, i = 0; communicate(ip, sendbuf, 6, buf, &slen); if(slen == sizeof(sendbuf) + 1){ int mode = buf[6]; if(mode == 1){ clsGlobal.ipGwDb->devNetFun = 1; }else{ clsGlobal.ipGwDb->devNetFun = 0; } } }
int run_testcase(const char *host, const char *service, int casenum) { struct wslay_event_callbacks callbacks = { recv_callback, send_callback, genmask_callback, NULL, /* on_frame_recv_start_callback */ NULL, /* on_frame_recv_callback */ NULL, /* on_frame_recv_end_callback */ on_msg_recv_callback }; char buf[1024]; snprintf(buf, sizeof(buf), "/runCase?case=%d&agent=wslay", casenum); return communicate(host, service, buf, &callbacks); }
int main(int argc, char *argv[]) { int sockfd, newsockfd, pid; socklen_t client_len; struct sockaddr_in server_addr, client_addr; sockfd = socket(AF_INET, SOCK_STREAM, 0); if(sockfd < 0) error("Error in opening socket"); bzero((char *)&server_addr, sizeof(server_addr)); get_conf(); //获取各种配置信息 printf("webroot is %s\n", webroot); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(portno); inet_pton(AF_INET, "127.0.0.1", &server_addr.sin_addr.s_addr); //点分式转换成字符串形式 if(bind(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) error("Error when binding!\n"); listen(sockfd, 10); client_len = sizeof(client_addr); /* * Main process of Server continue listening * Another one process deal with the connection */ while(1) { newsockfd = accept(sockfd, (struct sockaddr *)&client_addr, &client_len); if(newsockfd < 0) error("Error when accepting!\n"); pid = fork(); if(pid < 0) error("Error when forking!\n"); if(pid == 0) { close(sockfd); communicate(newsockfd); exit(1); } else { //sleep(2); //?sleeping can help the running of multi-process more clear close(newsockfd); } } //end of while(1) close(sockfd); return(0); }
void resolvekeys(void) { req_t *rwalk; keyrecord_t *kwalk; oidset_t *swalk; int i; char *oid; /* Fetch the key data, and determine the indices we want to use */ dataoperation = GET_KEYS; starthosts(1); communicate(); /* Generate new requests for the datasets we now know the indices of */ for (rwalk = reqhead; (rwalk); rwalk = rwalk->next) { if (!rwalk->keyrecords) continue; for (kwalk = rwalk->keyrecords; (kwalk); kwalk = kwalk->next) { if (!kwalk->indexoid) { /* Dont report failed lookups for the pseudo match-all key record */ if (*kwalk->key != '*') { /* We failed to determine the index */ errprintf("Could not determine index for host=%s mib=%s key=%s\n", rwalk->hostname, kwalk->mib->mibname, kwalk->key); } continue; } swalk = kwalk->mib->oidlisthead; while (swalk) { rwalk->setnumber++; for (i=0; (i <= swalk->oidcount); i++) { oid = (char *)malloc(strlen(swalk->oids[i].oid) + strlen(kwalk->indexoid) + 2); sprintf(oid, "%s.%s", swalk->oids[i].oid, kwalk->indexoid); make_oitem(kwalk->mib, kwalk->key, &swalk->oids[i], oid, rwalk); xfree(oid); } swalk = swalk->next; } rwalk->next_oid = rwalk->oidhead; } } }
void Kitchen::run() { // Start Cooks and PARRTAY std::list<Thread>::iterator it = _threads.begin(); std::list<Thread>::iterator end = _threads.end(); while (it != end) { (*it).start(); ++it; } // Reserve _threadRes.start(); // handle IO communicate(); }
void ParallelBlockCommunicator2D::communicate ( std::vector<Overlap2D> const& overlaps, MultiBlock2D const& originMultiBlock, MultiBlock2D& destinationMultiBlock, modif::ModifT whichData ) const { PLB_PRECONDITION( originMultiBlock.sizeOfCell() == destinationMultiBlock.sizeOfCell() ); CommunicationStructure2D communication ( overlaps, originMultiBlock.getMultiBlockManagement(), destinationMultiBlock.getMultiBlockManagement(), originMultiBlock.sizeOfCell() ); global::profiler().start("mpiCommunication"); communicate(communication, originMultiBlock, destinationMultiBlock, whichData); global::profiler().stop("mpiCommunication"); }