Continue where you left off ×
From the wire to your accept(): sockets and the receive path
The Parcel's Journey · Open board
: one parcel travelling from a laptop to a server. This lesson follows the last stretch of that trip, from the server’s network card to the line of code that reads the parcel.
Before you start. A socket is the door a program holds for one network conversation, a file descriptor that read and write accept (Everything is a file descriptor ). The five calls that create and open such a door, socket, bind, listen, accept and recv, are in The five calls that open a door . The two queues that hold callers before accept are in The hold line (the listen queue, and the SYN flood) . The window, the amount a sender may send before it waits for a “got it”, is in The page that never arrived (TCP reliable delivery) .
The idea in 30 seconds
A packet goes from the card’s ring buffer to a batch read, then IP and TCP, then the socket’s receive buffer, then recv().
The card interrupts once for several packets, so a 20 MB download cost a few hundred interrupts, not thousands.
A program that does not read leaves bytes in the receive buffer, and the window tells the sender to stop.
On ss, Recv-Q and Send-Q mean bytes for a connection and queue lengths for a listener.
tc qdisc add ... netem delay 50ms makes a 100 ms round trip, and a larger receive buffer takes fewer of them for the same file.
Receive livelock is a machine so busy taking packets that it does no work, and batching is the cure.
Read the story
Lesson 35 of 44 in Networking
The rest of this lesson is part of a plan.
A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year .
See plans Already a member? Sign in
Or start free : a free account opens lessons 2 and 3 of every track.
In this lesson January 1996: a machine that is busy and does nothing Seven steps from the wire to your program Many packets, one interrupt The receive buffer: where bytes wait for recv() The receive window: the shelf talks back ss: two columns, two meanings netem: a bad network, made on purpose The interrupt, then polling: NAPI Where a packet can be lost on the way in The size the buffer needs The experiment, as run Limits of what was measured Terms it explains: interrupt, ring buffer, receive buffer, receive window, Recv-Q, Send-Q, NAPI, softirq.
Review Networking
Mark as read Saved in this browser, and to your account when you sign in.