Differences From Artifact [937ba60b81]:
- File
src/OFStreamObserver_select.m
— part of check-in
[417b213d41]
at
2012-07-16 23:49:50
on branch trunk
— Add OF_ENSURE.
This is to be used when the condition includes a statement that needs to
be executed, as with assert, this would not be executed anymore when
NDEBUG is defined. (user: js, size: 3310) [annotate] [blame] [check-ins using]
To Artifact [2098b64113]:
- File
src/OFStreamObserver_select.m
— part of check-in
[1255f3a11a]
at
2012-08-10 20:08:24
on branch trunk
— Directly use the runtime's autorelease pools.
This greatly improves performance, as it gets rid of the overhead of
OFAutoreleasePool. (user: js, size: 3314) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
20 21 22 23 24 25 26 | #include <string.h> #include <unistd.h> #import "OFStreamObserver_select.h" #import "OFStream.h" #import "OFArray.h" | < > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <string.h> #include <unistd.h> #import "OFStreamObserver_select.h" #import "OFStream.h" #import "OFArray.h" #import "autorelease.h" #import "macros.h" @implementation OFStreamObserver_select - init { self = [super init]; |
︙ | ︙ | |||
67 68 69 70 71 72 73 | if (!FD_ISSET(fd, &readFDs)) FD_CLR(fd, &exceptFDs); } - (BOOL)observeWithTimeout: (int)timeout { | | | > > | < < > > | < < < > > > > | < | < | < | > < < | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | if (!FD_ISSET(fd, &readFDs)) FD_CLR(fd, &exceptFDs); } - (BOOL)observeWithTimeout: (int)timeout { void *pool = objc_autoreleasePoolPush(); OFStream **objects; fd_set readFDs_; fd_set writeFDs_; fd_set exceptFDs_; struct timeval time; size_t i, count; [self _processQueue]; if ([self _processCache]) { objc_autoreleasePoolPop(pool); return YES; } objc_autoreleasePoolPop(pool); #ifdef FD_COPY FD_COPY(&readFDs, &readFDs_); FD_COPY(&writeFDs, &writeFDs_); FD_COPY(&exceptFDs, &exceptFDs_); #else readFDs_ = readFDs; writeFDs_ = writeFDs; exceptFDs_ = exceptFDs; #endif time.tv_sec = timeout / 1000; time.tv_usec = (timeout % 1000) * 1000; if (select((int)maxFD + 1, &readFDs_, &writeFDs_, &exceptFDs_, (timeout != -1 ? &time : NULL)) < 1) return NO; if (FD_ISSET(cancelFD[0], &readFDs_)) { char buffer; #ifndef _WIN32 OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); #else OF_ENSURE(recvfrom(cancelFD[0], &buffer, 1, 0, NULL, NULL) > 0); #endif } objects = [readStreams objects]; count = [readStreams count]; for (i = 0; i < count; i++) { int fileDescriptor = [objects[i] fileDescriptor]; pool = objc_autoreleasePoolPush(); if (FD_ISSET(fileDescriptor, &readFDs_)) [delegate streamIsReadyForReading: objects[i]]; if (FD_ISSET(fileDescriptor, &exceptFDs_)) { [delegate streamDidReceiveException: objects[i]]; /* * Prevent calling it twice in case the FD is in both * sets. */ FD_CLR(fileDescriptor, &exceptFDs_); } objc_autoreleasePoolPop(pool); } objects = [writeStreams objects]; count = [writeStreams count]; for (i = 0; i < count; i++) { int fileDescriptor = [objects[i] fileDescriptor]; pool = objc_autoreleasePoolPush(); if (FD_ISSET(fileDescriptor, &writeFDs_)) [delegate streamIsReadyForWriting: objects[i]]; if (FD_ISSET(fileDescriptor, &exceptFDs_)) [delegate streamDidReceiveException: objects[i]]; objc_autoreleasePoolPop(pool); } return YES; } @end |