Up the scale of the SPX loopback check a bit: use much larger data sizes

so that we need to do segmentation.
This commit is contained in:
Robert Watson 2009-06-20 18:13:20 +00:00
parent 11dd0af11d
commit 046a577d69

View File

@ -46,11 +46,7 @@
#include <unistd.h> #include <unistd.h>
#define IPX_ENDPOINT "0xbebe.1.0x8a13" #define IPX_ENDPOINT "0xbebe.1.0x8a13"
#define PACKETLEN 128 #define PACKETLEN 16 * (1024 * 1024)
#if 0
#define SPX_SUPPORTS_SENDTO_WITH_CONNECT
#endif
static void static void
packet_fill(u_char *packet) packet_fill(u_char *packet)
@ -62,61 +58,40 @@ packet_fill(u_char *packet)
} }
static int static int
packet_check(u_char *packet) packet_check(u_char *packet, size_t totlen, ssize_t len)
{ {
int i; size_t i;
for (i = 0; i < PACKETLEN; i++) { for (i = totlen; i < totlen + len; i++) {
if (packet[i] != (i & 0xff)) if (packet[i] != (i & 0xff))
return (-1); return (-1);
} }
return (0); return (0);
} }
#ifdef SPX_SUPPORTS_SENDTO_WITH_CONNECT
static void
my_sendto(int sock, const char *who, pid_t pid, struct sockaddr *sa,
socklen_t sa_len)
{
u_char packet[PACKETLEN];
ssize_t len;
int error;
packet_fill(packet);
len = sendto(sock, packet, sizeof(packet), 0, sa, sa_len);
if (len < 0) {
error = errno;
(void)kill(pid, SIGTERM);
errno = error;
err(-1, "%s: sendto()", who);
}
if (len != sizeof(packet)) {
(void)kill(pid, SIGTERM);
errx(-1, "%s: sendto(): short send (%d length, %d sent)",
who, sizeof(packet), len);
}
}
#endif
static void static void
my_send(int sock, const char *who, pid_t pid) my_send(int sock, const char *who, pid_t pid)
{ {
u_char packet[PACKETLEN]; u_char packet[PACKETLEN];
ssize_t len; ssize_t len;
size_t totlen;
int error; int error;
totlen = 0;
packet_fill(packet); packet_fill(packet);
len = send(sock, packet, sizeof(packet), 0); while (totlen < PACKETLEN) {
len = send(sock, packet + totlen, PACKETLEN - totlen, 0);
if (len < 0) { if (len < 0) {
error = errno; error = errno;
(void)kill(pid, SIGTERM); (void)kill(pid, SIGTERM);
errno = error; errno = error;
err(-1, "%s: send()", who); err(-1, "%s: send()", who);
} }
if (len != sizeof(packet)) { if (len == 0) {
(void)kill(pid, SIGTERM); (void)kill(pid, SIGTERM);
errx(-1, "%s: send(): short send (%d length, %d sent)", who, errx(-1, "%s: send(): EOF", who);
sizeof(packet), len); }
totlen += len;
} }
} }
@ -125,25 +100,29 @@ my_recv(int sock, const char *who, pid_t pid)
{ {
u_char packet[PACKETLEN]; u_char packet[PACKETLEN];
ssize_t len; ssize_t len;
size_t totlen;
int error; int error;
totlen = 0;
bzero(packet, sizeof(packet)); bzero(packet, sizeof(packet));
len = recv(sock, packet, sizeof(packet), 0); while (totlen < PACKETLEN) {
len = recv(sock, packet + totlen, sizeof(packet) - totlen, 0);
if (len < 0) { if (len < 0) {
errno = error; errno = error;
(void)kill(pid, SIGTERM); (void)kill(pid, SIGTERM);
errno = error; errno = error;
err(-1, "%s: recv()", who); err(-1, "%s: recv()", who);
} }
if (len != sizeof(packet)) { if (len == 0) {
(void)kill(pid, SIGTERM); (void)kill(pid, SIGTERM);
errx(-1, "%s: recv(): got %d expected %d", who, len, errx(-1, "%s: recv(): EOF", who);
sizeof(packet));
} }
if (packet_check(packet) < 0) { if (packet_check(packet, totlen, len) < 0) {
(void)kill(pid, SIGTERM); (void)kill(pid, SIGTERM);
errx(-1, "%s: recv(): got bad data", who); errx(-1, "%s: recv(): got bad data", who);
} }
totlen += len;
}
} }
int int