/* If hash digest is enabled, the function will update the hash while copying. Combining these two operations doesn't buy us a lot (yet), but in the future we could implement combined copy+crc, just way we do for network layer checksums.  */
static int iscsi_tcp_segment_recv(struct iscsi_tcp_conn *tcp_conn, struct iscsi_segment *segment, const void *ptr, unsigned int len)
/* If hash digest is enabled, the function will update the hash while copying. Combining these two operations doesn't buy us a lot (yet), but in the future we could implement combined copy+crc, just way we do for network layer checksums.  */
static int iscsi_tcp_segment_recv(struct iscsi_tcp_conn *tcp_conn, struct iscsi_segment *segment, const void *ptr, unsigned int len)
{
	unsigned int copy = 0, copied = 0;
	while (!iscsi_tcp_segment_done(tcp_conn, segment, 1, copy)) {
		if (copied == len) {
			ISCSI_DBG_TCP(tcp_conn->iscsi_conn,
				      "copied %d bytes\n", len);
			break;
		}
		copy = min(len - copied, segment->size - segment->copied);
		ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "copying %d\n", copy);
		memcpy(segment->data + segment->copied, ptr + copied, copy);
		copied += copy;
	}
	return copied;
}