Pink网络框架socket相关

连接超时时间

怎么实现?

发送超时时间

struct timeval timeout = {send_timeout_ / 1000, (send_timeout_ % 1000) * 1000};
setsockopt(sockfd_, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));

接收超时时间

struct timeval timeout = {recv_timeout_ / 1000, (recv_timeout_ % 1000) * 1000};
setsockopt(sockfd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));

同步/异步

 int flags;
  if ((flags = fcntl(sockfd, F_GETFL, 0)) < 0) {
    close(sockfd);
    return -1;
  }
  flags |= O_NONBLOCK;
  if (fcntl(sockfd, F_SETFL, flags) < 0) {
    close(sockfd);
    return -1;
  }
  return flags;

keep alive

results matching ""

    No results matching ""