summaryrefslogtreecommitdiffstats
path: root/src/server/protocol.h
diff options
context:
space:
mode:
authorSimon Rettberg2013-08-28 17:54:19 +0200
committerSimon Rettberg2013-08-28 17:54:19 +0200
commitbfdac5b274d8ca371307d2b4b417092ba25f11ab (patch)
treec62b57b0d56995057f152f1e1273dc3383a709a1 /src/server/protocol.h
parent[SERVER] On-the-fly transparent proxying (diff)
downloaddnbd3-bfdac5b274d8ca371307d2b4b417092ba25f11ab.tar.gz
dnbd3-bfdac5b274d8ca371307d2b4b417092ba25f11ab.tar.xz
dnbd3-bfdac5b274d8ca371307d2b4b417092ba25f11ab.zip
[SERVER] Copy CRC-32 list from uplink server if available
Split up helper.c, move file/disk related functions to fileutil.c Uplink: Make sure relayed requests are at least 1MiB
Diffstat (limited to 'src/server/protocol.h')
-rw-r--r--src/server/protocol.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/server/protocol.h b/src/server/protocol.h
index 96856f8..c8010ab 100644
--- a/src/server/protocol.h
+++ b/src/server/protocol.h
@@ -54,7 +54,7 @@ static inline int dnbd3_get_block(int sock, uint64_t offset, uint32_t size)
return send( sock, &request, sizeof(request), 0 ) == sizeof(request);
}
-static inline int dnbd3_get_crc32(int sock, uint8_t *buffer, size_t *bufferLen)
+static inline int dnbd3_get_crc32(int sock, uint32_t *master, void *buffer, size_t *bufferLen)
{
dnbd3_request_t request;
dnbd3_reply_t reply;
@@ -66,10 +66,16 @@ static inline int dnbd3_get_crc32(int sock, uint8_t *buffer, size_t *bufferLen)
fixup_request( request );
if ( send( sock, &request, sizeof(request), 0 ) != sizeof(request) ) return FALSE;
if ( !dnbd3_get_reply( sock, &reply ) ) return FALSE;
+ if ( reply.size == 0 ) {
+ *bufferLen = 0;
+ return TRUE;
+ }
+ if ( reply.size < 4 ) return FALSE;
+ reply.size -= 4;
if ( reply.cmd != CMD_GET_CRC32 || reply.size > *bufferLen ) return FALSE;
*bufferLen = reply.size;
- if ( reply.size == 0 ) return TRUE;
- return recv( sock, buffer, reply.size, 0 ) == (int)reply.size;
+ return recv( sock, master, sizeof(uint32_t), 0 ) == sizeof(uint32_t)
+ && recv( sock, buffer, reply.size, 0 ) == (int)reply.size;
}
/**