Yes, it's safe. On Linux, all the data you specify gets immediately copied into a buffer in the kernel, before send
returns. If the kernel's buffer is full, it returns EAGAIN or EWOULDBLOCK (which are the same thing in Linux, apparently) and nothing happens. You don't have to worry that the kernel will go and send the packet later after you've changed the data in the buffer.
On Windows, non-blocking "overlapped" operations do remember your buffer and use it later - so watch out for that if you ever do non-blocking I/O on Windows. (You'll know if you do, because it's totally different from blocking I/O)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…