socket: calculate hdr_size once per PDU process loop

ISCSI_HEADER_SIZE is determined based on the iscsi->header_digest
setting, which may change via iscsi_process_pdu().

Signed-off-by: David Disseldorp <ddiss@suse.de>
This commit is contained in:
David Disseldorp
2018-10-25 22:56:10 +02:00
parent 96dc6e7ebd
commit 009892b017

View File

@@ -596,16 +596,17 @@ static int
iscsi_read_from_socket(struct iscsi_context *iscsi)
{
struct iscsi_in_pdu *in;
ssize_t data_size, count, padding_size;
ssize_t hdr_size, data_size, count, padding_size;
do {
hdr_size = ISCSI_HEADER_SIZE;
if (iscsi->incoming == NULL) {
iscsi->incoming = iscsi_szmalloc(iscsi, sizeof(struct iscsi_in_pdu));
if (iscsi->incoming == NULL) {
iscsi_set_error(iscsi, "Out-of-memory: failed to malloc iscsi_in_pdu");
return -1;
}
iscsi->incoming->hdr = iscsi_smalloc(iscsi, ISCSI_HEADER_SIZE);
iscsi->incoming->hdr = iscsi_smalloc(iscsi, hdr_size);
if (iscsi->incoming->hdr == NULL) {
iscsi_set_error(iscsi, "Out-of-memory");
return -1;
@@ -614,11 +615,11 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
in = iscsi->incoming;
/* first we must read the header, including any digests */
if (in->hdr_pos < ISCSI_HEADER_SIZE) {
if (in->hdr_pos < hdr_size) {
/* try to only read the header, the socket is nonblocking, so
* no need to limit the read to what is available in the socket
*/
count = ISCSI_HEADER_SIZE - in->hdr_pos;
count = hdr_size - in->hdr_pos;
count = recv(iscsi->fd, &in->hdr[in->hdr_pos], count, 0);
if (count == 0) {
/* remote side has closed the socket. */
@@ -635,7 +636,7 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
in->hdr_pos += count;
}
if (in->hdr_pos < ISCSI_HEADER_SIZE) {
if (in->hdr_pos < hdr_size) {
/* we don't have the full header yet, so return */
break;
}