When will socket.send () block be blocked? (UDP)

I was reading about UDP sockets in python.

By default, the socket is configured to send or receive blocks of data, halting program execution until the socket is ready. Calls to send () wait for buffer space to be available for outgoing data, and calls to recv () wait for another program to send data that can be read.

I understand the receiving part, it must wait until the other end leaves. but why do we need a send block? The book says "send () is waiting for buffer space to be available." What is buffer space?

This is for the entire operating system or specific to each application.

Is there a way to find out how much buffer space is available?

+3


source to share


1 answer


The buffer referenced by BSD sockets and the POSIX documentation, and presumably whatever you read is a buffer on a per socket basis, not per system or per application. This is the same one you can install with SO_SNDBUF

. When this buffer is full, it send

will be blocked.

But the real question is, why is this buffer filling up?



Underneath what your application can see, the kernel usually has something like a ring of transmit buffers for the network adapter. When the network adapter finishes setting the data on the buffer from the explorer, it pulls another one out of the ring. When there is room on the ring, it pulls another transmit buffer from one of the socket buffers. Or, if there are too many buffers waiting, it discards some of them and then pulls in one. So this part is system-wide (or at least NIC-wide).

So, just knowing that your send buffer size doesn't really tell you everything you really need, and to truly understand this, you need to ask questions specific to your kernel. If it's Linux or * BSD, the networking stack is open source and reasonably well documented (on Linux, if I remember correctly, and if my 2.4x knowledge is still useful, searching SO_SNDBUF

and txqueuelen

giving you good starting points); otherwise it might not be the case. Of course Linux provides all the information that can be found somewhere on the filesystem /proc

, so once you know what you want to look for, you can find it. * BSD doesn't cover as much, but there's a lot in there. Even Windows has a lot of performance counters that matter.

+1


source







All Articles