Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
UNAME =$(shell uname)

CFLAGS_COMMON =-std=gnu99 -Wall -Werror
# -pthread needed for MT errno
CFLAGS_COMMON =-std=gnu99 -Wall -Werror -pthread
CFLAGS_Linux =-D _GNU_SOURCE -D _XOPEN_SOURCE=700
CFLAGS_SunOS =-D __EXTENSIONS__ -D _XOPEN_SOURCE=600
CFLAGS +=$(CFLAGS_COMMON) $(CFLAGS_$(UNAME))
Expand Down
39 changes: 36 additions & 3 deletions seqtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ typedef struct test {
struct addrinfo *lai; /* local addr to bind (client only) */
socklen_t addrlen;
sample_t *samples;
int spin; /* spin loop recv flag */
} test_t;

/*
Expand Down Expand Up @@ -216,6 +217,29 @@ range(uint32_t minval, uint32_t maxval)
return (val);
}

/*
* Receive len bytes into buf. If the t->spin flag is set a spin loop
* is used to receive. Otherwise a blocking recv() is performed. The
* return value is that of the recv() call.
*/
static ssize_t
st_recv(test_t *t, void *buf, size_t len)
{
ssize_t rv = 0;

if (t->spin == 1) {
while (((rv = recv(t->sock, buf, len, MSG_DONTWAIT)) == -1)) {
if (errno != EAGAIN)
break;
}

} else {
rv = recv(t->sock, buf, len, 0);
}

return (rv);
}

/*
* senderreceiver is a pthread worker that sends a single message and expects
* a reply.
Expand Down Expand Up @@ -295,8 +319,10 @@ senderreceiver(void *arg)
} else {
break;
}
rv = recv(t->sock, rptr, resid, 0);

rv = st_recv(t, rptr, resid);
now = gethrtime();

if (rv < 0) {
perror("rcvr/recv");
goto out;
Expand Down Expand Up @@ -543,8 +569,10 @@ replier(void *arg)
} else {
break;
}
rv = recv(t->sock, rptr, resid, 0);

rv = st_recv(t, rptr, resid);
now = gethrtime();

if (rv < 0) {
perror("replier/recv");
goto out;
Expand Down Expand Up @@ -808,6 +836,7 @@ main(int argc, char **argv)
uint32_t rintvl;
uint32_t nthreads;
uint32_t count;
int opt_l = 0;
enum mode mode;
int nais;
struct addrinfo **ais;
Expand All @@ -826,11 +855,14 @@ main(int argc, char **argv)
/* initialize the timer */
(void) randtime();

while ((c = getopt(argc, argv, "o:srdS")) != EOF) {
while ((c = getopt(argc, argv, "o:lsrdS")) != EOF) {
switch (c) {
case 'd':
debug++;
break;
case 'l':
opt_l = 1;
break;
case 's':
mode = MODE_ASYNC_SEND;
break;
Expand Down Expand Up @@ -1096,6 +1128,7 @@ main(int argc, char **argv)
t->rseqno = 0;
t->sseqno = 0;
t->samples = calloc(count, sizeof (sample_t));
t->spin = opt_l;

if (mode == MODE_ASYNC_SEND) {
t->addr = addrs[(i / 2) % naddrs];
Expand Down