Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No select() when reading stream data #1787

Merged
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
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
Loading