[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] implemented cpuworkers
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/common
Modified Files:
util.c util.h
Log Message:
implemented cpuworkers
please poke at it and report bugs
still needs polishing, and only handles onions now (should handle
OR handshakes too)
Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- util.c 14 Aug 2003 17:51:36 -0000 1.15
+++ util.c 20 Aug 2003 23:05:19 -0000 1.16
@@ -88,6 +88,21 @@
a->tv_usec %= 1000000;
}
+/* a wrapper for write(2) that makes sure to write all count bytes.
+ * Only use if fd is a blocking socket. */
+int write_all(int fd, const void *buf, size_t count) {
+ int written = 0;
+ int result;
+
+ while(written != count) {
+ result = write(fd, buf+written, count-written);
+ if(result<0)
+ return -1;
+ written += result;
+ }
+ return count;
+}
+
void set_socket_nonblocking(int socket)
{
#ifdef MS_WINDOWS
Index: util.h
===================================================================
RCS file: /home/or/cvsroot/src/common/util.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- util.h 14 Aug 2003 17:51:36 -0000 1.9
+++ util.h 20 Aug 2003 23:05:19 -0000 1.10
@@ -51,6 +51,8 @@
void tv_add(struct timeval *a, struct timeval *b);
int tv_cmp(struct timeval *a, struct timeval *b);
+int write_all(int fd, const void *buf, size_t count);
+
void set_socket_nonblocking(int socket);
/* Minimalist interface to run a void function in the background. On