Skip to content

Commit

Permalink
Merge pull request #1787 from davidBar-On/issue-1707-UDP-higher-packe…
Browse files Browse the repository at this point in the history
…t-loss-compared-to-nuttcp

No select() when reading stream data
  • Loading branch information
bmah888 authored Oct 25, 2024
2 parents 062ad48 + c038abe commit 38b4dde
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/iperf_sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ iperf_sctp_recv(struct iperf_stream *sp)
#if defined(HAVE_SCTP_H)
int r;

r = Nread(sp->socket, sp->buffer, sp->settings->blksize, Psctp);
r = Nread_no_select(sp->socket, sp->buffer, sp->settings->blksize, Psctp);
if (r < 0)
return r;

Expand Down
2 changes: 1 addition & 1 deletion src/iperf_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ iperf_tcp_recv(struct iperf_stream *sp)
{
int r;

r = Nread(sp->socket, sp->buffer, sp->settings->blksize, Ptcp);
r = Nread_no_select(sp->socket, sp->buffer, sp->settings->blksize, Ptcp);

if (r < 0)
return r;
Expand Down
2 changes: 1 addition & 1 deletion src/iperf_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ iperf_udp_recv(struct iperf_stream *sp)
double transit = 0, d = 0;
struct iperf_time sent_time, arrival_time, temp_time;

r = Nread(sp->socket, sp->buffer, size, Pudp);
r = Nread_no_select(sp->socket, sp->buffer, size, Pudp);

/*
* If we got an error in the read, or if we didn't read anything
Expand Down
27 changes: 27 additions & 0 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,33 @@ Nread(int fd, char *buf, size_t count, int prot)
return count - nleft;
}

/********************************************************************/
/* reads 'count' bytes from a socket - but without using select() */
/********************************************************************/
int
Nread_no_select(int fd, char *buf, size_t count, int prot)
{
register ssize_t r;
register size_t nleft = count;

while (nleft > 0) {
r = read(fd, buf, nleft);
if (r < 0) {
/* XXX EWOULDBLOCK can't happen without non-blocking sockets */
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)
break;
else
return NET_HARDERROR;
} else if (r == 0)
break;

nleft -= r;
buf += r;

}
return count - nleft;
}


/*
* N W R I T E
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int create_socket(int domain, int proto, const char *local, const char *bind_dev
int netdial(int domain, int proto, const char *local, const char *bind_dev, int local_port, const char *server, int port, int timeout);
int netannounce(int domain, int proto, const char *local, const char *bind_dev, int port);
int Nread(int fd, char *buf, size_t count, int prot);
int Nread_no_select(int fd, char *buf, size_t count, int prot);
int Nwrite(int fd, const char *buf, size_t count, int prot) /* __attribute__((hot)) */;
int has_sendfile(void);
int Nsendfile(int fromfd, int tofd, const char *buf, size_t count) /* __attribute__((hot)) */;
Expand Down

0 comments on commit 38b4dde

Please sign in to comment.