Câu trả lời là trong một phần khác của man 2 send
:
When the message does not fit into the send buffer of the socket,
send() normally blocks, unless the socket has been placed in nonblock‐
ing I/O mode. In nonblocking mode it would fail with the error EAGAIN
or EWOULDBLOCK in this case. The select(2) call may be used to deter‐
mine when it is possible to send more data.
Hoặc cách khác, phiên bản POSIX (man 3p send
):
If space is not available at the sending socket to hold the message to
be transmitted, and the socket file descriptor does not have O_NONBLOCK
set, send() shall block until space is available. If space is not
available at the sending socket to hold the message to be transmitted,
and the socket file descriptor does have O_NONBLOCK set, send() shall
fail. The select() and poll() functions can be used to determine when
it is possible to send more data.
Vì vậy, trong khi một read
dữ liệu phần được phổ biến , không thể xảy ra một phần send
trong chế độ chặn (chặn chi tiết triển khai).
Nguồn
2012-09-29 22:32:22
-1: Chính xác ngược - đối với mọi giao thức dựa trên luồng (chẳng hạn như TCP), gửi có thể trả về ít hơn số tiền được yêu cầu, nếu bộ đệm cục bộ gần như đã đầy từ các lần gửi trước đó. Đối với các giao thức datagram (như UDP), việc gửi sẽ không thành công hoặc gửi toàn bộ bộ đệm dưới dạng gói - không thể gửi một phần. –
Tôi đã không bỏ phiếu, nhưng hãy xem câu trả lời của tôi, bạn đã sai. –
@Kiril Kirov - bạn và Chris Dodd là hoàn toàn chính xác. Rắm não về phía tôi - xin lỗi. Tôi đã sửa chữa câu trả lời của mình. Cảm ơn bạn! – paulsm4