+
+ if (nob == 0)
+ return 0;
+ else
+ return -ETIMEDOUT;
+}
+
+int
+libcfs_sock_write (cfs_socket_t *sock, void *buffer, int nob, int timeout)
+{
+ int rc;
+ struct pollfd pfd;
+ cfs_time_t start_time = cfs_time_current();
+
+ pfd.fd = sock->s_fd;
+ pfd.events = POLLOUT;
+ pfd.revents = 0;
+
+ /* poll(2) measures timeout in msec */
+ timeout *= 1000;
+
+ while (nob != 0 && timeout > 0) {
+ cfs_time_t current_time;
+
+ rc = poll(&pfd, 1, timeout);
+ if (rc < 0)
+ return -errno;
+ if (rc == 0)
+ return -ETIMEDOUT;
+ if ((pfd.revents & POLLOUT) == 0)
+ return -EIO;
+
+ rc = write(sock->s_fd, buffer, nob);
+ if (rc < 0)
+ return -errno;
+ if (rc == 0)
+ return -EIO;
+
+ buffer = ((char *)buffer) + rc;
+ nob -= rc;
+
+ current_time = cfs_time_current();
+ timeout -= 1000 *
+ cfs_duration_sec(cfs_time_sub(current_time,
+ start_time));
+ start_time = current_time;
+ }
+