i use nonblocking socket receive new connection. code repeatedly fails accept()
.
int sockfd = ::socket(family, sock_stream | sock_nonblock | sock_cloexec, ipproto_tcp); ::bind(sockfd, bind_addr, static_cast<socklen_t>(sizeof(struct sockaddr_in6))); ret = ::listen(sockfd, somaxconn); while (true) { ::poll(&*pollfds_.begin(), pollfds_.size(), timeoutms); struct sockaddr_in6 addr; bzero(&addr, sizeof addr); socklen_t addrlen = static_cast<socklen_t>(sizeof *addr); int connfd = ::accept4(sockfd, sockaddr_cast(addr), &addrlen, sock_nonblock | sock_cloexec); }
errno
eagain
.
from manpage accept(2)
:
eagain or ewouldblock
the socket marked nonblocking , no connections present accepted. posix.1-2001 allows either error returned case, , not require these constants have same value, portable application should check both possibilities.
this means call accept
made before client has connected.
Comments
Post a Comment