int udp_send(void) { p_debug("udp_send"); struct sockaddr_in addr; int sockfd, len = 0; int addr_len = sizeof(struct sockaddr_in); char buffer[256]; int broadcast = 1; if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { p_debug("creat socket error"); return -1; } if(-1 == setsockopt(sockfd,SOL_SOCKET,SO_BROADCAST,&broadcast,sizeof(broadcast))) { p_debug("setsockopt error"); close(sockfd); return -1; } bzero(&addr, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(BROADCAST_PORT); addr.sin_addr.s_addr = INADDR_BROADCAST; sprintf(buffer, "{\"header\":{\"cmd\":%d, \"seq\":%d, \"ver\":%d, \"device\":%d, \"appid\":%d, \ \"code\":%d}, \"data\":[]}", BROADCAST_CMD, BROADCAST_SEQ, BROADCAST_VER, BROADCAST_DEVICE, \
void kill_error(int r) { if(nosignals == 0) { nosignals=1; p_debug(); p_log(LOG_ERROR,-1,lngtxt(636)); } exit(0x0); }
void ill_error(int r) { if(nosignals == 0) { nosignals=1; p_debug(); p_log(LOG_WARNING,-1,lngtxt(635)); nosignals=0; } return; }
void term_error(int r) { if(nosignals == 1) return; nosignals=1; p_debug(); p_log(LOG_ERROR,-1,lngtxt(610)); flushconfig(); nosignals=0; return; }
void hup_error(int r) { if(nosignals == 0) { nosignals=1; p_debug(); p_log(LOG_WARNING,-1,lngtxt(611)); if(*user(1)->login!=0) cmdrehash(1); nosignals=0; } return; }
void usr2_error(int r) { if(nosignals == 0) { nosignals=1; p_debug(); p_log(LOG_INFO,-1,lngtxt(633)); resetconfig(); readconfig(); loadusers(); nosignals=0; } return; }
/*############################## Functions ###################################*/ int check_internet_status(void) { p_debug("access get_wwanip\n"); char value[64]= "\0"; char uci_option_str[64]= "\0"; struct ifreq ifr_wlan1; int inet_sock_wlan1; int ret = 0; ctx=uci_alloc_context(); memset(uci_option_str, '\0', 64); memset(value, '\0', 64); strcpy(uci_option_str, "network.wan.workmode"); uci_get_option_value(uci_option_str, value); uci_free_context(ctx); p_debug("value = %s\n",value); if(!strcmp(value, "0")) strcpy(ifr_wlan1.ifr_name, "eth0.1"); else if(!strcmp(value, "1")) strcpy(ifr_wlan1.ifr_name, "apcli0"); else if(!strcmp(value, "2")) strcpy(ifr_wlan1.ifr_name, "ppp0"); else{ p_debug("unknown workmode\n"); return -1; } inet_sock_wlan1 = socket(AF_INET, SOCK_DGRAM, 0); if(-1 == inet_sock_wlan1) { p_debug("creat socket error!\n"); ret = -1; } if (ioctl(inet_sock_wlan1, SIOCGIFADDR, &ifr_wlan1) < 0) { p_debug("get no wan ip!\n"); ret = 0; }else { p_debug("get wan ip success!\n"); ret = 1; } if(-1 != inet_sock_wlan1) close(inet_sock_wlan1); return ret; }
int main() { list_node *token_list; token current_token; job *job_list; init_tokenizer(stdin); init_shell(); while (1) { fprintf(stdout, "myshell>"); token_list = create_list(sizeof(token)); //字句解析を行なってリストに追加する while ((current_token = get_token()).kind != token_type_eol && current_token.kind != token_type_eof) { add_list(token_list, ¤t_token); } request_job_notification (); if (token_list->next == NULL) { p_debug("continue"); continue; } //字句解析結果を表示 //dump_token_list_data(token_list); //構文解析を行う job_list = parse(token_list); //実行 launch_job(job_list); free_list(token_list); } }
void * backend_thread(){ // connection for listening on a port // 2 conn_t cannot be allocated on stack (see comment on conn_t) // since cause a seg faults conn_t * pConnListen; conn_t * pConn; pid_t childpid, childpid2; int status; //int retval = 0; // Network state // FIXME cuda_bridge_request_t == cuda_packet_t == rpkt_t, this is rediculous strm_hdr_t *hdr = NULL; rpkt_t *rpkts = NULL; // array of cuda packets if( (pConnListen = conn_malloc(__FUNCTION__, NULL)) == NULL ) return NULL; // this allocates memory for the strm.rpkts, i.e., the array of packets if( (pConn = conn_malloc(__FUNCTION__, NULL)) == NULL ) return NULL; fprintf(stderr, "**************************************\n"); fprintf(stderr, "%s.%d: hey, here server thread!\n", __FUNCTION__, __LINE__); fprintf(stderr, "**************************************\n"); // set up the connection conn_localbind(pConnListen); for(;;) { conn_accept(pConnListen, pConn); // blocking printf("ACCEPTED A CONN***********\n"); if((childpid = fork()) == 0) { if((childpid2 = fork()) == 0) { // CLOSE the listen connection // conn_close(pConnListen); // Connection-related structures hdr = &pConn->strm.hdr; rpkts = pConn->strm.rpkts; // an array of packets (MAX_REMOTE_BATCH_SIZE) // these are buffers for extra data transferred as pConn->pReqBuffer = NULL; pConn->pRspBuffer = NULL; while(1) { p_debug("------------------New RPC--------------------\n"); memset(hdr, 0, sizeof(strm_hdr_t)); memset(rpkts, 0, MAX_REMOTE_BATCH_SIZE * sizeof(rpkt_t)); pConn->request_data_size = 0; pConn->response_data_size = 0; pConn->pReqBuffer = freeBuffer(pConn->pReqBuffer); pConn->pRspBuffer = freeBuffer(pConn->pRspBuffer); //recv the header describing the batch of remote requests if (1 != get(pConn, hdr, sizeof(strm_hdr_t))) { break; } p_debug(" received request header. Expecting %d packets. And extra request buffer of data size %d\n", hdr->num_cuda_pkts, hdr->data_size); if (hdr->num_cuda_pkts <= 0) { p_warn("Received header specifying zero packets, ignoring\n"); continue; } // Receive the entire batch. // first the packets, then the extra data (reqbuf) // // let's assume that we have enough space. otherwise we have a problem // pConn allocates the buffers for incoming cuda packets // so we should be fine if(1 != get(pConn, rpkts, hdr->num_cuda_pkts * sizeof(rpkt_t))) { break; } p_info("Received %d packets, each of size of (%lu) bytes\n", hdr->num_cuda_pkts, sizeof(rpkt_t)); p_info( "Received method %s (method_id %d) from Thr_id: %lu.\n", methodIdToString(rpkts[0].method_id), rpkts[0].method_id, rpkts[0].thr_id); // receiving the request buffer if any if(hdr->data_size > 0){ p_info("Expecting data size/Buffer: %u, %d.\n", hdr->data_size, pConn->request_data_size); // let's assume that the expected amount of data will fit into // the buffer we have (size of pConn->request_data_buffer // allocate the right amount of memory for the request buffer pConn->pReqBuffer = malloc(hdr->data_size); if( mallocCheck(pConn->pReqBuffer, __FUNCTION__, NULL) == ERROR ){ break; } //assert(hdr->data_size <= TOTAL_XFER_MAX); if(1 != get(pConn, pConn->pReqBuffer, hdr->data_size)){ pConn->pReqBuffer = freeBuffer(pConn->pReqBuffer); break; } pConn->request_data_size = hdr->data_size; p_info( "Received request buffer (%d bytes)\n", pConn->request_data_size); } // execute the request pkt_execute(&rpkts[0], pConn); // we need to send the one response packet + response_buffer if any // @todo you need to check if he method needs to send // and extended response - you need to provide the right // data_size if( strm_expects_response(&pConn->strm) ){ // send the header about response p_debug( "pConn->response_data_size %d\n", pConn->response_data_size); if (conn_sendCudaPktHdr(&*pConn, 1, pConn->response_data_size) == ERROR) { p_info( "__ERROR__ after : Sending the CUDA packet response header: Quitting ... \n"); break; } // send the standard response (with cuda_error_t, and simple arguments etc) if (1 != put(pConn, rpkts, sizeof(rpkt_t))) { p_info("__ERROR__ after : Sending CUDA response packet: Quitting ... \n"); break; } p_info("Response packet sent.\n"); // send the extra data if you have anything to send if( pConn->response_data_size > 0 ){ if (1 != put(pConn, pConn->pRspBuffer, pConn->response_data_size)) { p_info("__ERROR__ after: Sending accompanying response buffer: Quitting ... \n" ); break; } p_info( "Response buffer sent (%d) bytes.\n", pConn->response_data_size); } } } freeBuffer(pConn->pReqBuffer); freeBuffer(pConn->pRspBuffer); conn_close(pConnListen); conn_close(pConn); free(pConnListen); free(pConn); return NULL; } //if(childpid2==0) else exit(0); } //if(childpid==0) //CLOSE THE other conn conn_close(pConn); waitpid(childpid, &status, NULL); }//for(;;) }
void* handle_req(void* p) { conn_t * pConn = (conn_t*)p; // Network state // FIXME cuda_bridge_request_t == cuda_packet_t == rpkt_t, this is rediculous strm_hdr_t *hdr = NULL; rpkt_t *rpkts = NULL; // array of cuda packets // CLOSE the listen connection // conn_close(pConnListen); // Connection-related structures hdr = &pConn->strm.hdr; rpkts = pConn->strm.rpkts; // an array of packets (MAX_REMOTE_BATCH_SIZE) // these are buffers for extra data transferred as pConn->pReqBuffer = NULL; pConn->pRspBuffer = NULL; while(1) { p_debug("------------------New RPC--------------------\n"); memset(hdr, 0, sizeof(strm_hdr_t)); memset(rpkts, 0, MAX_REMOTE_BATCH_SIZE * sizeof(rpkt_t)); pConn->request_data_size = 0; pConn->response_data_size = 0; pConn->pReqBuffer = freeBuffer(pConn->pReqBuffer); pConn->pRspBuffer = freeBuffer(pConn->pRspBuffer); //recv the header describing the batch of remote requests if (1 != get(pConn, hdr, sizeof(strm_hdr_t))) { break; } p_debug(" received request header. Expecting %d packets. And extra request buffer of data size %d\n", hdr->num_cuda_pkts, hdr->data_size); if (hdr->num_cuda_pkts <= 0) { p_warn("Received header specifying zero packets, ignoring\n"); continue; } // Receive the entire batch. // first the packets, then the extra data (reqbuf) // // let's assume that we have enough space. otherwise we have a problem // pConn allocates the buffers for incoming cuda packets // so we should be fine if(1 != get(pConn, rpkts, hdr->num_cuda_pkts * sizeof(rpkt_t))) { break; } p_info("Received %d packets, each of size of (%lu) bytes\n", hdr->num_cuda_pkts, sizeof(rpkt_t)); p_info( "Received method %s (method_id %d) from Thr_id: %lu.\n", methodIdToString(rpkts[0].method_id), rpkts[0].method_id, rpkts[0].thr_id); // receiving the request buffer if any if(hdr->data_size > 0){ p_info("Expecting data size/Buffer: %u, %d.\n", hdr->data_size, pConn->request_data_size); // let's assume that the expected amount of data will fit into // the buffer we have (size of pConn->request_data_buffer // allocate the right amount of memory for the request buffer pConn->pReqBuffer = malloc(hdr->data_size); if( mallocCheck(pConn->pReqBuffer, __FUNCTION__, NULL) == ERROR ){ break; } //assert(hdr->data_size <= TOTAL_XFER_MAX); if(1 != get(pConn, pConn->pReqBuffer, hdr->data_size)){ pConn->pReqBuffer = freeBuffer(pConn->pReqBuffer); break; } pConn->request_data_size = hdr->data_size; p_info( "Received request buffer (%d bytes)\n", pConn->request_data_size); } // execute the request pkt_execute(&rpkts[0], pConn); // we need to send the one response packet + response_buffer if any // @todo you need to check if he method needs to send // and extended response - you need to provide the right // data_size if( strm_expects_response(&pConn->strm) ){ // send the header about response p_debug( "pConn->response_data_size %d\n", pConn->response_data_size); if (conn_sendCudaPktHdr(&*pConn, 1, pConn->response_data_size) == ERROR) { p_info( "__ERROR__ after : Sending the CUDA packet response header: Quitting ... \n"); break; } // send the standard response (with cuda_error_t, and simple arguments etc) if (1 != put(pConn, rpkts, sizeof(rpkt_t))) { p_info("__ERROR__ after : Sending CUDA response packet: Quitting ... \n"); break; } p_info("Response packet sent.\n"); // send the extra data if you have anything to send if( pConn->response_data_size > 0 ){ if (1 != put(pConn, pConn->pRspBuffer, pConn->response_data_size)) { p_info("__ERROR__ after: Sending accompanying response buffer: Quitting ... \n" ); break; } p_info( "Response buffer sent (%d) bytes.\n", pConn->response_data_size); } } }//while(1) dec_thread_count_per_device(); freeBuffer(pConn->pReqBuffer); freeBuffer(pConn->pRspBuffer); //conn_close(pConnListen); conn_close(pConn); //free(pConnListen); free(pConn); return NULL; }