user3581289
user3581289

Reputation: 21

When the new value specified for SO_RCVBUF in setsockopt() will take effect?

My query is related to “SO_RCVBUF” option in setsocketopt() api. When the new value specified for SO_RCVBUF in setsockopt() will take effect?

I am testing the flow control of TCP/IP and below is my environment. The client program is a slow reader and it has a single socket. To test the flow control, I am reducing the value of SO_RCVBUF to 5000 bytes after establishing the connection and before receiving the data. My expectation is that, my server program after sending 5000+ bytes should wait for client to read. But the server program sends the data till ~60000 bytes. After that the server program will wait for client to read. Once the client reads ~55000 bytes, then I see the new value of receive buffer (5000bytes) getting utilized.

Is it expected? I guess effect of setsocketopt() should be immediate. The initial value of receive buffer should not have any effect after setsocketopt().

Regards, Prashanth

Upvotes: 2

Views: 1750

Answers (1)

John Zwinck
John Zwinck

Reputation: 249163

I think you should set SO_RCVBUF before calling connect(), because that is when the buffers are allocated. By calling it afterward it may have no effect at all, or a delayed effect as you observed.

Upvotes: 2

Related Questions