The typical coding pattern to use when you don't know how many messages will 
come back: send a dump request, followed by an echo-ping.

When the ping reply shows up, the dump is complete...

HTH... Dave

From: vpp-dev@lists.fd.io <vpp-dev@lists.fd.io> On Behalf Of 
wangchuan...@163.com
Sent: Tuesday, September 11, 2018 4:34 AM
To: vpp-dev <vpp-dev@lists.fd.io>
Subject: [vpp-dev] VPP's C-type-api example

Hi all,
    I code my example following src/vpp-api/client, but do {vac_read}while(1) 
often block when the results-num does not know.
It shows  
pthread_cond_wait<http://www.baidu.com/link?url=oxJEzGJWUf50LwNKT9sIuEzSyHMAr3lJcfvYTyhfiwf6pNTtf1ZjdaxAkdWrmkvdqF9zP8UGH_QdDw_qY5ugMb2mmKmuQGfCCuTXI1Hy_YPlvpv1vzQI1Is_JlP0FDGj>
 when gdb.
Help please!
Thanks very much!

void printIntefaces()
{
  api_main_t * am = &api_main;
  vl_api_sw_interface_dump_t message;
  M_NOALLOC(SW_INTERFACE_DUMP);
  message.name_filter_valid = 0;
  strcpy(message.name_filter, "Gigabit");
  vac_write((char *)&message, sizeof(message));
  char* pMsg = NULL;
  int nLen = 0;
  int ret = 0;
  int nCount = 0;
  do  {
    printf("begin interface read .. \n");
    ret = vac_read(&pMsg, &nLen, 1);
    printf("begin interface end .. \n");
    if(ret != -1)
      {
    vl_api_sw_interface_details_t* pSV = (vl_api_sw_interface_details_t*)pMsg;
    printf("%lu:%s  \n", ntohl(pSV->sw_if_index), pSV->interface_name);
      vac_free(pMsg);
        nCount += 1;
      }
    else{
      break;
    }
  }while(1);
 printf("get real count[%d] \n", nCount);
}

________________________________
wangchuan...@163.com<mailto:wangchuan...@163.com>
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#10467): https://lists.fd.io/g/vpp-dev/message/10467
Mute This Topic: https://lists.fd.io/mt/25510961/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to