diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2012-04-13 12:21:22 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2012-04-13 12:21:22 +0800 |
commit | 51d99de6444e976afd7bc94ab20d070c05004cdd (patch) | |
tree | d5bdfe9db77794292cc7f0c3c5dfec4fce7a21f4 | |
parent | 507da2e1fd914e78a2d5a775cdfc79f44d014c11 (diff) | |
download | pttbbs-51d99de6444e976afd7bc94ab20d070c05004cdd.tar pttbbs-51d99de6444e976afd7bc94ab20d070c05004cdd.tar.gz pttbbs-51d99de6444e976afd7bc94ab20d070c05004cdd.tar.bz2 pttbbs-51d99de6444e976afd7bc94ab20d070c05004cdd.tar.lz pttbbs-51d99de6444e976afd7bc94ab20d070c05004cdd.tar.xz pttbbs-51d99de6444e976afd7bc94ab20d070c05004cdd.tar.zst pttbbs-51d99de6444e976afd7bc94ab20d070c05004cdd.zip |
fix toread/towrite return value.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@5630 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/common/sys/net.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/pttbbs/common/sys/net.c b/pttbbs/common/sys/net.c index 9f7f90af..fff804ec 100644 --- a/pttbbs/common/sys/net.c +++ b/pttbbs/common/sys/net.c @@ -259,18 +259,20 @@ int is_to_readwrite_again(int s) */ int toread(int fd, void *buf, int len) { - int s; - for( s = 0 ; len > 0 ; ) - if( (s = read(fd, buf, len)) <= 0 ) { + int s = 0, t = 0; + for(; len > 0 ;) { + if ((s = read(fd, buf, len)) <= 0) { if (is_to_readwrite_again(s)) continue; // XXX we define toread/towrite as '-1 for EOF and error'. return -1; // s; - }else{ + } else { buf += s; len -= s; + t += s; } - return s; + } + return t; } /** @@ -278,18 +280,20 @@ int toread(int fd, void *buf, int len) */ int towrite(int fd, const void *buf, int len) { - int s; - for( s = 0 ; len > 0 ; ) - if( (s = write(fd, buf, len)) <= 0){ + int s = 0, t = 0; + for(; len > 0 ;) { + if ((s = write(fd, buf, len)) <= 0) { if (is_to_readwrite_again(s)) continue; // XXX we define toread/towrite as '-1 for EOF and error'. return -1; // s; - }else{ + } else { buf += s; len -= s; + t += s; } - return s; + } + return t; } /** @@ -297,18 +301,20 @@ int towrite(int fd, const void *buf, int len) */ int torecv(int fd, void *buf, int len, int flag) { - int s; - for( s = 0 ; len > 0 ; ) - if( (s = recv(fd, buf, len, flag)) <= 0 ) { + int s = 0, t = 0; + for(; len > 0 ;) { + if((s = recv(fd, buf, len, flag)) <= 0) { if (is_to_readwrite_again(s)) continue; // XXX we define toread/towrite as '-1 for EOF and error'. return -1; // s; - }else{ + } else { buf += s; len -= s; + t += s; } - return s; + } + return t; } /** @@ -316,18 +322,20 @@ int torecv(int fd, void *buf, int len, int flag) */ int tosend(int fd, const void *buf, int len, int flag) { - int s; - for( s = 0 ; len > 0 ; ) - if( (s = send(fd, buf, len, flag)) <= 0){ + int s = 0, t = 0; + for(; len > 0 ;) { + if((s = send(fd, buf, len, flag)) <= 0){ if (is_to_readwrite_again(s)) continue; // XXX we define toread/towrite as '-1 for EOF and error'. return -1; // s; - }else{ + } else { buf += s; len -= s; + t += s; } - return s; + } + return t; } /** |