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

前端 未结 6 2211
难免孤独
难免孤独 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:16

    You need one more closing parenthesis at each of these two lines.

    - setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on);
    + setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
    - setsockopt( sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv);
    + setsockopt( sockfd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
    

提交回复
热议问题