aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorJef Poskanzer <jef@mail.acme.com>2013-02-22 15:54:05 -0800
committerJef Poskanzer <jef@mail.acme.com>2013-02-22 15:54:05 -0800
commit43929b3698066f9cfda9523c19595e084a6658a9 (patch)
treeef2cf08e60281ecb755c46b2be3a506e03267562 /src/net.c
parent231c56296e666e41ac5c6bb69eddd392f18619df (diff)
downloadiperf3-43929b3698066f9cfda9523c19595e084a6658a9.tar.gz
Added "burst mode" to send a bunch of packets in a row without
intervening select() calls. This increases performance quite a bit.
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c49
1 files changed, 17 insertions, 32 deletions
diff --git a/src/net.c b/src/net.c
index 03ca9f8..0dd6d82 100644
--- a/src/net.c
+++ b/src/net.c
@@ -131,7 +131,7 @@ Nread(int fd, void *buf, int count, int prot)
if (errno == EINTR)
n = 0;
else
- return -1;
+ return NET_HARDERROR;
} else if (n == 0)
break;
@@ -144,9 +144,6 @@ Nread(int fd, void *buf, int count, int prot)
/*
* N W R I T E
- *
- * XXX: After updating this function to use read/write, the only difference between
- * TCP and UDP is that udp handles ENOBUFS. Should we merge the two?
*/
int
@@ -155,34 +152,22 @@ Nwrite(int fd, void *buf, int count, int prot)
register int n;
register int nleft = count;
- if (prot == SOCK_DGRAM) { /* UDP mode */
- while (nleft > 0) {
- if ((n = write(fd, buf, nleft)) < 0) {
- if (errno == EINTR) {
- n = 0;
- } else if (errno == ENOBUFS) {
- /* wait if run out of buffers */
- /* XXX: but how long to wait? Start shorter and increase delay each time?? */
- delay(18000); // XXX: Fixme!
- n = 0;
- } else {
- return -1;
- }
- }
- nleft -= n;
- buf += n;
- }
- } else {
- while (nleft > 0) {
- if ((n = write(fd, buf, nleft)) < 0) {
- if (errno == EINTR)
- n = 0;
- else
- return -1;
- }
- nleft -= n;
- buf += n;
- }
+ while (nleft > 0) {
+ if ((n = write(fd, buf, nleft)) < 0) {
+ switch (errno) {
+ case EINTR:
+ return count - nleft;
+
+ case EAGAIN:
+ case ENOBUFS:
+ return NET_SOFTERROR;
+
+ default:
+ return NET_HARDERROR;
+ }
+ }
+ nleft -= n;
+ buf += n;
}
return count;
}