I'm writing a server program, at the initialization, I want to bind() and listen() at certain ip/port. But then the whole program is blocked by listen(). Is there any way can make the program check for new incoming connection every, say, 5ms?
My code is currently like this:
int main(){
initialize();
do_something();
return 0;
}
In initialize(), socket is set up:
void initialize(){
sockfd = sock_create_bind(ip_addr[nodeid], port_addr[nodeid]);
listen(sockfd, 5);
peer_sockfd = accept(sockfd, (struct sockaddr *)&peer_addr, &peer_addr_len);
}
But initialize() never returns, and do_something() never get called. So I'm wondering is there anyway to prevent this blocking? Thanks.