|
Network Block Device, nbd.c in Linux kernel source. Written by Pavel Machek, pavel@ucw.cz 完整程序的路径:/usr/src/linux/driver/block/nbd.c 程序段节选: /* * Send or receive packet. */ static int nbd_xmit(int send, int sockfd, char *buf, int size) { int result; struct msghdr msg; struct iovec iov; unsigned long flags; sigset_t oldset; do { iov.iov_base = buf; iov.iov_len = size; msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = NULL; msg.msg_controllen = 0; msg.msg_namelen = 0; msg.msg_flags = 0; if (send) result = sendmsg(sockfd, &msg, 0); else result = recvmsg(sockfd, &msg, 0); if (result <= 0) break; size -= result; buf += result; } while (size > 0); return result; } |