简体   繁体   中英

I set SO_RCVLOWAT (Receive Low Water Mark ) option on a UDP socket but it doesn't work

I am using C network programming to set the socket option SO_RCVLOWAT on a UDP socket. I succeeded as shown by the return value of getsockopt() . The problem: I can still receive any data sizes greater than zero.

Example: I set the socket option SO_RCVLOWAT value to 1024 byte on the client side and server sent 256 byte to the client. It can receive the 256 byte, but it actually shouldn't receive this message because the receive low water mark is 1024 byte.

Relevant code:

rc = setsockopt(sd, SOL_SOCKET, SO_RCVLOWAT, (char *)&recvlowat, sizeof(recvlowat));
        if(rc < 0){
                VL_MISC_ERR(("Setting SO_RCVLOWAT option error, %s",strerror(errno)));
                return -1;
        }

sd : a valid file descriptor

Then I use recvfrom :

c = recvfrom(sd, databuf,  datalen, 0, (struct sockaddr_in *)&localSock, &addrlen);

It isn't supposed to have that effect in UDP. recvfrom() receives one datagram at a time, period. If you want to receive more than one at a time, use recvmsg() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM