summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-28 11:59:35 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2013-04-28 16:14:09 -0700
commit64c584c4a80f46fcb2ad5fc318572fe400b31535 (patch)
tree87a10b95a17b8fac6e71b711bbc82ca06ceb5ec8
parentb0b96c4b16c98aa81f392221528ad6c668c305b6 (diff)
Allow tests to repeat a data packet a specified number of times
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--include/xhiv.h3
-rw-r--r--src/server.c14
2 files changed, 12 insertions, 5 deletions
diff --git a/include/xhiv.h b/include/xhiv.h
index 26b0036..867258e 100644
--- a/include/xhiv.h
+++ b/include/xhiv.h
@@ -46,10 +46,11 @@ typedef struct xhiv_response {
uint32_t sequence; /* Sequence number, or XHIV_SEQ_IGNORE */
const void *match_data; /* Additional data for matching requests */
uint32_t length; /* Total length of reply packet, in 4-byte words */
+ uint32_t repeat; /* Number of times to repeat this packet in reply */
const void *response_data; /* Data to return */
uint32_t response_datalen; /* Length of response_data, in bytes */
/* Response will be filled with random data to fill the difference
- between response_datalen & length */
+ between (response_datalen * (1 + repeat)) & length */
uint32_t flags; /* flags controlling various options */
} xhiv_response;
diff --git a/src/server.c b/src/server.c
index c1acfe0..d9e4c4d 100644
--- a/src/server.c
+++ b/src/server.c
@@ -60,6 +60,7 @@ typedef struct client_response_buffer {
uint32_t length; /* Total length of reply packet, in 4-byte words */
uint64_t response_written; /* Number of bytes written so far */
uint32_t response_sequence; /* Sequence number to set or XHIV_SEQ_IGNORE */
+ uint32_t send_count; /* Number of times to send this data */
} client_response_buffer;
typedef struct client_state {
@@ -244,6 +245,9 @@ AddResponseToBuffer(client_response_buffer *crb, const xhiv_response *response,
new_crb->length = r->length;
new_crb->response_sequence = (r->flags & XHIV_NO_SET_SEQUENCE)
? XHIV_SEQ_IGNORE : sequence;
+ new_crb->send_count = r->repeat + 1; /* Always send at least once */
+ assert((new_crb->send_count * new_crb->response_datalen) <=
+ (new_crb->length << 2));
if (new_crb_tail != NULL) {
new_crb_tail->next = new_crb;
@@ -372,11 +376,12 @@ HandleClientResponses(client_state *client)
crb->response_written += wbytes;
}
- if (crb->response_written < crb->response_datalen) {
- nbytes = crb->response_datalen - crb->response_written;
+ total_bytes = (uint64_t) crb->response_datalen * crb->send_count;
+ while (crb->response_written < total_bytes) {
+ uint32_t offset = crb->response_written % crb->response_datalen;
+ nbytes = crb->response_datalen - offset;
wbytes = _XSERVTransWrite(client->conn,
- (const char *) crb->response_data + crb->response_written,
- nbytes);
+ (const char *) crb->response_data + offset, nbytes);
if (wbytes > 0)
crb->response_written += wbytes;
if (wbytes != nbytes) /* pipe is full, try again later */
@@ -384,6 +389,7 @@ HandleClientResponses(client_state *client)
}
total_bytes = ((uint64_t) crb->length) << 2;
+ assert(total_bytes >= crb->response_written);
nbytes = total_bytes - crb->response_written;
if (nbytes > 0) {
char ranbuf[32768];