Socket with recv-timeout: What is wrong with this code?

前端 未结 6 2089
难免孤独
难免孤独 2021-02-20 16:41

I\'m trying to implement a socket with a recv timeout of 1 Second:

int sockfd;
struct sockaddr_in self;
struct sockaddr_in client_addr;
int addrlen=sizeof(clien         


        
6条回答
  •  深忆病人
    2021-02-20 17:13

    Which socket do you want to have the one-second timeout on? The one accepting connections, or the one established by accept()?

    I'd assume the latter - so try setting the receive timeout on clientfd AFTER the accept returns. You can also get to where you need to be using select, but you shouldn't need to.

提交回复
热议问题