正如你所知道SENDMSG有這樣的聲明:sendmsg如何工作?
int sendmsg(int s, const struct msghdr *msg, int flags);
和指向msghdr結構有以下形式:
struct msghdr {
void * msg_name; /* optional address */
socklen_t msg_namelen; /* size of address */
struct iovec * msg_iov; /* scatter/gather array */
size_t msg_iovlen; /* # elements in msg_iov */
void * msg_control; /* ancillary data, see below */
socklen_t msg_controllen; /* ancillary data buffer len */
int msg_flags; /* flags on received message */
};
正如你看到的指向msghdr具有緩衝的數組,iovec結構,具有緩衝區計數msg_iovlen。我想知道sendmsg如何發送這些緩衝區。它連接所有緩衝區併發送或發送for循環嗎?
只是一個說明:如果這是好奇心,然後很酷。如果你正在嘗試寫出一些依賴於這些知識的東西,那麼你幾乎肯定會做錯了,並且會出現問題。 – 2010-11-23 17:37:07
@SanJacinto對你來說闡述**爲什麼**寫出一些依賴於這些知識的東西需要麻煩。你能詳細說明嗎? – 2012-07-09 01:55:09
@lori因爲文檔爲您提供了一組代碼界面,並告訴您對它們有什麼期望。界面變化非常緩慢。底層代碼沒有這樣的保證。如果你在蒐集關於內部的知識,並圍繞這些知識編寫代碼,那麼如果你更新內核或網絡堆棧中的某個驅動程序,並且調用它的代碼不再工作,則不應該感到驚訝。如果你這樣做,你做出了不好的選擇。 – 2012-07-09 11:07:20