Skip to content

Commit

Permalink
update ttcp_blocking.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuo committed Oct 31, 2014
1 parent f17a62c commit 00996b6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/ace/ttcp/ttcp_blocking.cc
Expand Up @@ -59,10 +59,14 @@ static int write_n(int sockfd, const void* buf, int length)
while (written < length)
{
ssize_t nw = ::write(sockfd, static_cast<const char*>(buf) + written, length - written);
if (nw >= 0)
if (nw > 0)
{
written += static_cast<int>(nw);
}
else if (nw == 0)
{
break; // EOF
}
else if (errno != EINTR)
{
perror("write");
Expand All @@ -78,10 +82,14 @@ static int read_n(int sockfd, void* buf, int length)
while (nread < length)
{
ssize_t nr = ::read(sockfd, static_cast<char*>(buf) + nread, length - nread);
if (nr >= 0)
if (nr > 0)
{
nread += static_cast<int>(nr);
}
else if (nr == 0)
{
break; // EOF
}
else if (errno != EINTR)
{
perror("read");
Expand Down

0 comments on commit 00996b6

Please sign in to comment.