diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-03-11 06:35:03 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-03-11 06:35:03 +0000 |
commit | 976bacae944cde32da6dedb7910538929f933452 (patch) | |
tree | a29eee029da1af0164425ac497fc0922a932777e /src/common | |
parent | 060d721554695cd689d5873cdd366d59721ada46 (diff) | |
download | tor-976bacae944cde32da6dedb7910538929f933452.tar tor-976bacae944cde32da6dedb7910538929f933452.tar.gz |
Make all the other read/writes into recv/sends, except when they shouldn't be.
svn:r1260
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/util.c | 16 | ||||
-rw-r--r-- | src/common/util.h | 4 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/common/util.c b/src/common/util.c index a62b0d320..16e191d14 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -282,12 +282,15 @@ time_t tor_timegm (struct tm *tm) { /* a wrapper for write(2) that makes sure to write all count bytes. * Only use if fd is a blocking fd. */ -int write_all(int fd, const char *buf, size_t count) { +int write_all(int fd, const char *buf, size_t count, int isSocket) { size_t written = 0; int result; while(written != count) { - result = write(fd, buf+written, count-written); + if (isSocket) + result = send(fd, buf+written, count-written, 0); + else + result = write(fd, buf+written, count-written); if(result<0) return -1; written += result; @@ -297,12 +300,15 @@ int write_all(int fd, const char *buf, size_t count) { /* a wrapper for read(2) that makes sure to read all count bytes. * Only use if fd is a blocking fd. */ -int read_all(int fd, char *buf, size_t count) { +int read_all(int fd, char *buf, size_t count, int isSocket) { size_t numread = 0; int result; while(numread != count) { - result = read(fd, buf+numread, count-numread); + if (isSocket) + result = recv(fd, buf+numread, count-numread, 0); + else + result = read(fd, buf+numread, count-numread); if(result<=0) return -1; numread += result; @@ -615,7 +621,7 @@ char *read_file_to_str(const char *filename) { string = tor_malloc(statbuf.st_size+1); - if(read_all(fd,string,statbuf.st_size) != statbuf.st_size) { + if(read_all(fd,string,statbuf.st_size,0) != statbuf.st_size) { log_fn(LOG_WARN,"Couldn't read all %ld bytes of file '%s'.", (long)statbuf.st_size,filename); free(string); diff --git a/src/common/util.h b/src/common/util.h index 02cde5604..9f4654b92 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -66,8 +66,8 @@ void tv_add(struct timeval *a, struct timeval *b); int tv_cmp(struct timeval *a, struct timeval *b); time_t tor_timegm (struct tm *tm); -int write_all(int fd, const char *buf, size_t count); -int read_all(int fd, char *buf, size_t count); +int write_all(int fd, const char *buf, size_t count, int isSocket); +int read_all(int fd, char *buf, size_t count, int isSocket); void set_socket_nonblocking(int socket); |