udp傳送完訊息後要關閉埠描述符
阿新 • • 發佈:2019-02-04
int get_osd_oob_list(struct osd_node onode, struct list_head *head) { printf("\nEntering %s ", __func__); char message[4096]; char oob_receive_buf[8192]; int ret, m_type, valid_len; int failure_time = 0; int socket_descriptor; struct sockaddr_in sin; int sin_len; int port = OSD_RECEIVE_RESULT_PORT; int is_cur_osd = (onode.osd_no == current_osd_no) ? 1:0; CACHE_INFO("This time being processed osd_node is: no:%d and name %s and current restarted osdno:%d",\ onode.osd_no, onode.osd_address, current_osd_no); CACHE_INFO("+++++++++In line%d and is_cur_osd :%d", __LINE__, is_cur_osd); if(onode.osd_no == current_osd_no) is_cur_osd = 1; CACHE_INFO("++++++++++++++++IN line%d and is_cur_osd :%d", __LINE__, is_cur_osd); memset(&sin, 0, sizeof(sin)); sin.sin_family=AF_INET; sin.sin_addr.s_addr=htonl(INADDR_ANY); sin.sin_port=htons(port); sin_len=sizeof(sin); socket_descriptor=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); bind(socket_descriptor,(struct sockaddr *)&sin,sizeof(sin)); *(uint32_t *) &message[0] = OOB_SCAN; memcpy(&message[4], current_osd_ip, 20); send_osd_message(onode.osd_address, OSD_RECEIVE_CMD_PORT, message, 24); printf("\nIn %s and line:%d and read oob info cmd is sent to osd:%s", __func__, __LINE__, onode.osd_address); while(1){ if(recvfrom(socket_descriptor,oob_receive_buf, sizeof(oob_receive_buf),0,(struct sockaddr *)&sin,&sin_len)){ m_type = get_ntohl_be(&oob_receive_buf[0]); if(m_type!=OOB_DATA){ CACHE_DEBUG("Invalid data because the data type is not OOB_DATA..."); failure_time++; if(failure_time > 2) break; else continue; } valid_len = get_ntohl_be(&oob_receive_buf[4]); if(!valid_len){ CACHE_INFO("No more valid oob info on node %s and goto next step... ", onode.osd_address); break; } CACHE_INFO("Received oob info len:%d", valid_len); if(valid_len % OOB_LEN != 0) CACHE_DEBUG("Something is wrong with the oob data len..."); ret = oob_data_process(oob_receive_buf+8, valid_len, head, is_cur_osd); }//if } close(socket_descriptor); printf("\nLeaving %s ...\n\n", __func__); return 0; }
按如下呼叫上述函式,在忘記close(socket_descriptor);的時候,第二次進入上述函式,無法正常接收資料,執行緒掛住!
for(i=0; i< related_osd_table->osd_count; i++){
printf("\nTo get osd oob list %d", i);
ret = get_osd_oob_list(related_osd_table->osd[i], &osd_oobinfo_list[i]);
}