[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Make all the other read/writes into recv/sends, except when...



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv4626/src/common

Modified Files:
	util.c util.h 
Log Message:
Make all the other read/writes into recv/sends, except when they shouldn't be.


Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- util.c	9 Mar 2004 22:09:12 -0000	1.57
+++ util.c	11 Mar 2004 06:35:03 -0000	1.58
@@ -282,12 +282,15 @@
 
 /* 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 @@
 
 /* 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 @@
 
   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);

Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- util.h	9 Mar 2004 22:09:12 -0000	1.33
+++ util.h	11 Mar 2004 06:35:03 -0000	1.34
@@ -66,8 +66,8 @@
 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);