最近线上遇到一个问题 导致程序崩溃 最后查到是gethostbyname的问题 把代码精简了 如下:

bool test(char* host,int port)
{
    hostent *m_phostent=gethostbyname(host);
    if(m_phostent==NULL)return false;
    struct in_addr ip_addr;
    memcpy(&ip_addr,m_phostent->h_addr_list[0],4);///h_addr_list[0]里4个字节,每个字节8位
    return true;
}

这个代码咋一看也没有什么问题,但是在多线程环境下有一定几率崩溃的 最后通过加锁解决的

相关文章:

  • 2021-06-17
  • 2021-07-31
  • 2021-11-27
  • 2021-09-26
  • 2021-11-10
猜你喜欢
  • 2021-11-20
  • 2021-07-29
  • 2021-07-12
  • 2021-06-24
  • 2021-11-10
  • 2021-11-12
相关资源
相似解决方案