This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3200 sl_Select 使用不成功问题

Other Parts Discussed in Thread: CC3200

TI工程师,你们好:

UDP客户端发送数据和接收数据中我使用了sl_Select去等待可发送和可接收事件,代码如下,但是出现的现象是写的sl_Select要等足8秒(我设置就为8秒)才返回,而读的sl_Select就一直都不返回,请问是我使用上存在问题还是其他什么原因呢?谢谢

  SlTimeval_t         sel_to;
  SlSockAddrIn_t      ipas_addr;
  SlFdSet_t           rfds, wfds;
  SlSockNonblocking_t enable_option;
  int                 i_addr_size, socket_fd = -1, ret;
  

  ipas_addr.sin_family      = SL_AF_INET;
  ipas_addr.sin_port        = sl_Htons(PORT);
  ipas_addr.sin_addr.s_addr = sl_Htonl(IP);
  i_addr_size = sizeof(SlSockAddrIn_t);

  socket_fd = sl_Socket(SL_AF_INET, SL_SOCK_DGRAM, 0);
  if(socket_fd < 0){
    DO_Printf("sl_Socket call Failure!\r\n");
    goto function_exit;
  }
  
  enable_option.NonblockingEnabled = 0x1;
  sl_SetSockOpt(socket_fd, SOL_SOCKET, SL_SO_NONBLOCKING, &enable_option, sizeof(enable_option));
  
  keep_on_send:
  sel_to.tv_sec  = 8;
  sel_to.tv_usec = 0;
  SL_FD_ZERO(&wfds);
  SL_FD_SET(socket_fd, &wfds);
  ret = sl_Select(socket_fd + 1, 0, &wfds, 0, &sel_to);
  if(ret < 0){
    DO_Printf("sl_Select1 call failure!\r\n");
    goto function_exit;
  }else{
    if(SL_FD_ISSET(socket_fd, &wfds)){
      ret = sl_SendTo(socket_fd, sp + already_len, willbe_len - already_len, 0, (SlSockAddr_t *)&ipas_addr, i_addr_size);
      if(ret < 0){
        DO_Printf("sl_SendTo call Failure!\r\n");
        goto function_exit;
      }else{
        already_len += ret;
        DO_Printf("Send Data Count:%d\r\n", already_len);
        if(already_len < willbe_len){
          goto keep_on_send;
        }
      }
    }else{
      DO_Printf("Send Data Timeout!\r\n");
      goto function_exit;
    }
  }
  
  DO_Printf("Test Send Finish\r\n");
  
  keep_on_recv:
  SL_FD_ZERO(&rfds);
  SL_FD_SET(socket_fd, &rfds);
  sel_to.tv_sec  = 8;
  sel_to.tv_usec = 0;
  ret = sl_Select(socket_fd + 1, &rfds, 0, 0, &sel_to);
  if(ret < 0){
    DO_Printf("sl_Select2 call failure!\r\n");
    goto function_exit;
  }else{
    if(SL_FD_ISSET(socket_fd, &rfds)){
      ret = sl_RecvFrom(socket_fd, sp + already_len, willbe_len - already_len, 0, (SlSockAddr_t *)(&ipas_addr), (SlSocklen_t*)(&i_addr_size));
      if(ret < 0){
        if(ret == SL_EAGAIN){
          goto keep_on_recv;
        }
        DO_Printf("sll_SendTo call Failure!\r\n");
        goto function_exit;
      }else{
        already_len += ret;
        if(already_len < willbe_len){
          goto keep_on_recv;
        }
      }
    }else{
      DO_Printf("Recv Data Timeout!\r\n");
      goto function_exit;
    }
  }
  .....