]> git.saurik.com Git - apple/cf.git/commitdiff
CF-476.17.tar.gz mac-os-x-1056 v476.17
authorApple <opensource@apple.com>
Tue, 13 Jan 2009 01:00:40 +0000 (01:00 +0000)
committerApple <opensource@apple.com>
Tue, 13 Jan 2009 01:00:40 +0000 (01:00 +0000)
BuildCFLite
CFSocket.c
CFVersion.c

index 9d1d810383bd82f099cac657d9e0ad3d55163c36..a96da5c1261550a23aee70dfb9b4134ce0892e89 100755 (executable)
@@ -83,7 +83,7 @@ if [ -z "$DSTBASE" ]; then DSTBASE=../CF-Root ; fi
 /bin/chmod -RH a-w,a+rX $DSTBASE/CoreFoundation.framework
 /bin/chmod -RH u+w $DSTBASE
 
-install_name_tool -id /System/Library/Frameworks/CoreFoundation/Versions/A/CoreFoundation $DSTBASE/CoreFoundation.framework/Versions/A/CoreFoundation
+install_name_tool -id /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation $DSTBASE/CoreFoundation.framework/Versions/A/CoreFoundation
 
 echo "Installing done.  The framework is in $DSTBASE"
 
index 51a1ca7cc83c272ed5c80e16b52a63d035ba4203..30b961e1895f682141ee7865009f83aca8a618bc 100644 (file)
@@ -22,7 +22,7 @@
  */
 /*     CFSocket.c
        Copyright (c) 1999-2007 Apple Inc.  All rights reserved.
-       Responsibility: Doug Davidson
+       Responsibility: Christopher Kane
 */
 
 #define _DARWIN_UNLIMITED_SELECT 1
@@ -284,10 +284,12 @@ static SInt32 __CFSocketCreateWakeupSocketPair(void) {
 
 // Version 0 RunLoopSources set a mask in an FD set to control what socket activity we hear about.
 CF_INLINE Boolean __CFSocketSetFDForRead(CFSocketRef s) {
+    __CFReadSocketsTimeoutInvalid = true;
     return __CFSocketFdSet(s->_socket, __CFReadSocketsFds);
 }
 
 CF_INLINE Boolean __CFSocketClearFDForRead(CFSocketRef s) {
+    __CFReadSocketsTimeoutInvalid = true;
     return __CFSocketFdClr(s->_socket, __CFReadSocketsFds);
 }
 
@@ -374,7 +376,7 @@ static void __CFSocketHandleWrite(CFSocketRef s, Boolean callBackNow) {
     if (0 != (s->_f.client & kCFSocketLeaveErrors) || 0 != getsockopt(s->_socket, SOL_SOCKET, SO_ERROR, (void *)&errorCode, (socklen_t *)&errorSize)) errorCode = 0;   // cast for WinSock bad API
 #if defined(LOG_CFSOCKET)
     if (errorCode) fprintf(stdout, "error %ld on socket %d\n", errorCode, s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
     __CFSocketLock(s);
     writeCallBacksAvailable = __CFSocketCallBackTypes(s) & (kCFSocketWriteCallBack | kCFSocketConnectCallBack);
     if ((s->_f.client & kCFSocketConnectCallBack) != 0) writeCallBacksAvailable &= ~kCFSocketConnectCallBack;
@@ -386,7 +388,7 @@ static void __CFSocketHandleWrite(CFSocketRef s, Boolean callBackNow) {
     __CFSocketSetWriteSignalled(s);
 #if defined(LOG_CFSOCKET)
     fprintf(stdout, "write signaling source for socket %d\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
     if (callBackNow) {
         __CFSocketDoCallback(s, NULL, NULL, 0);
     } else {
@@ -420,7 +422,7 @@ static void __CFSocketHandleRead(CFSocketRef s, Boolean causedByTimeout)
         }
 #if defined(LOG_CFSOCKET)
         fprintf(stdout, "read %ld bytes on socket %d\n", recvlen, s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
         if (0 >= recvlen) {
             //??? should return error if <0
             /* zero-length data is the signal for perform to invalidate */
@@ -513,7 +515,7 @@ static void __CFSocketHandleRead(CFSocketRef s, Boolean causedByTimeout)
                if (causedByTimeout) {
 #if defined(LOG_CFSOCKET)
                        fprintf(stdout, "TIMEOUT RECEIVED - WILL SIGNAL IMMEDIATELY TO FLUSH (%d buffered)\n", s->_bytesToBufferPos);
-#endif /* LOG_CFSOCKET */
+#endif
             /* we've got a timeout, but no bytes read.  Ignore the timeout. */
             if (s->_bytesToBufferPos == 0) {
 #if defined(LOG_CFSOCKET)
@@ -547,13 +549,13 @@ static void __CFSocketHandleRead(CFSocketRef s, Boolean causedByTimeout)
                                        s->_atEOF = true;
 #if defined(LOG_CFSOCKET)
                                        fprintf(stderr, "BUFFERED READ GOT ERROR %d\n", errno);
-#endif /* LOG_CFSOCKET */
+#endif
                                        break;
 
                                case 0:
        #if defined(LOG_CFSOCKET)
                                        fprintf(stdout, "DONE READING (EOF) - GOING TO SIGNAL\n");
-       #endif /* LOG_CFSOCKET */
+       #endif
                                        s->_atEOF = true;
                                        break;
                        
@@ -562,7 +564,7 @@ static void __CFSocketHandleRead(CFSocketRef s, Boolean causedByTimeout)
                                        if (s->_bytesToBuffer != s->_bytesToBufferPos) {
        #if defined(LOG_CFSOCKET)
                                                fprintf(stdout, "READ %d - need %d MORE - GOING BACK FOR MORE\n", ctRead, s->_bytesToBuffer - s->_bytesToBufferPos);
-       #endif /* LOG_CFSOCKET */
+       #endif
                                                __CFSpinLock(&__CFActiveSocketsLock);
                                                /* restore socket to fds */
                                                __CFSocketSetFDForRead(s);
@@ -572,7 +574,7 @@ static void __CFSocketHandleRead(CFSocketRef s, Boolean causedByTimeout)
                                        } else {
        #if defined(LOG_CFSOCKET)
                                                fprintf(stdout, "DONE READING (read %d bytes) - GOING TO SIGNAL\n", ctRead);
-       #endif /* LOG_CFSOCKET */
+       #endif
                                        }
                                }
                        }
@@ -582,7 +584,7 @@ static void __CFSocketHandleRead(CFSocketRef s, Boolean causedByTimeout)
     }
 #if defined(LOG_CFSOCKET)
     fprintf(stdout, "read signaling source for socket %d\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
     CFRunLoopSourceSignal(s->_source0);
     CFRunLoopRef rl = __CFSocketCopyRunLoopToWakeUp(s);
     __CFSocketUnlock(s);
@@ -611,9 +613,14 @@ static void _calcMinTimeout_locked(const void* val, void* ctxt)
        struct timeval** minTime = (struct timeval**) ctxt;
        if (timerisset(&s->_readBufferTimeout) && (*minTime == NULL || timercmp(&s->_readBufferTimeout, *minTime, <)))
                *minTime = &s->_readBufferTimeout;
+    else if (s->_leftoverBytes) {
+        /* If there's anyone with leftover bytes, they'll need to be awoken immediately */
+        static struct timeval sKickerTime = { 0, 0 };
+        *minTime = &sKickerTime;
+    }
 }
 
-void __CFSocketSetReadBufferTimeout(CFSocketRef s, CFTimeInterval timeout)
+void __CFSocketSetSocketReadBufferAttrs(CFSocketRef s, CFTimeInterval timeout, CFIndex length)
 {
     struct timeval timeoutVal;
 
@@ -623,33 +630,30 @@ void __CFSocketSetReadBufferTimeout(CFSocketRef s, CFTimeInterval timeout)
        /* activesocketslock protects our timeout calculation */
     __CFSocketLock(s);
        __CFSpinLock(&__CFActiveSocketsLock);
-    if (timercmp(&s->_readBufferTimeout, &timeoutVal, !=)) {
-        s->_readBufferTimeout = timeoutVal;
-        __CFReadSocketsTimeoutInvalid = true;
-    }
-       __CFSpinUnlock(&__CFActiveSocketsLock);
-    __CFSocketUnlock(s);
-}
 
-void __CFSocketSetReadBufferLength(CFSocketRef s, CFIndex length)
-{
-       __CFSocketLock(s);
+#if defined(LOG_CFSOCKET)
+    s->didLogSomething = false;
+#endif
+    
        if (s->_bytesToBuffer != length) {
-               if (s->_bytesToBufferPos != 0 && s->_bytesToBufferReadPos != 0) {
+        CFIndex ctBuffer = s->_bytesToBufferPos - s->_bytesToBufferReadPos;
+        
+        if (ctBuffer) {
                        /* As originally envisaged, you were supposed to be sure to drain the buffer before 
                         * issuing another request on the socket.  In practice, there seem to be times when we want to re-use 
                         * the stream (or perhaps, are on our way to closing it out) and this policy doesn't work so well.  
                         * So, if someone changes the buffer size while we have bytes already buffered, we put them 
                         * aside and use them to satisfy any subsequent reads. 
                         */
-#if defined(DEBUG)
-                       fprintf(stderr, "%s(%d): WARNING: shouldn't set read buffer length while data is still in the read buffer\n\n", __FUNCTION__, __LINE__);
+#if defined(LOG_CFSOCKET)
+            __socketLog("%s(%d): WARNING: shouldn't set read buffer length while data (%d bytes) is still in the read buffer (leftover total %d)", __FUNCTION__, __LINE__, ctBuffer, s->_leftoverBytes? CFDataGetLength(s->_leftoverBytes) : 0);
 #endif
+            
                        if (s->_leftoverBytes == NULL)
                                s->_leftoverBytes = CFDataCreateMutable(CFGetAllocator(s), 0);
                                
                        /* append the current buffered bytes over.  We'll keep draining _leftoverBytes while we have them... */
-                       CFDataAppendBytes(s->_leftoverBytes, CFDataGetBytePtr(s->_readBuffer) + s->_bytesToBufferPos, s->_bytesToBufferReadPos - s->_bytesToBufferPos);
+            CFDataAppendBytes(s->_leftoverBytes, CFDataGetBytePtr(s->_readBuffer) + s->_bytesToBufferReadPos, ctBuffer);
                        CFRelease(s->_readBuffer);
                        s->_readBuffer = NULL;
                                
@@ -665,6 +669,8 @@ void __CFSocketSetReadBufferLength(CFSocketRef s, CFIndex length)
                                CFRelease(s->_readBuffer);
                                s->_readBuffer = NULL;
                        }
+                       // Zero length buffer, smash the timeout
+                       timeoutVal = (struct timeval) { 0, 0 };
                } else {
                        /* if the buffer shrank, we can re-use the old one */
                        if (length > s->_bytesToBuffer) {
@@ -678,21 +684,52 @@ void __CFSocketSetReadBufferLength(CFSocketRef s, CFIndex length)
                        s->_bytesToBufferPos = 0;
                        s->_bytesToBufferReadPos = 0;
                        if (s->_readBuffer == NULL) {
-                               s->_readBuffer = CFDataCreateMutable(kCFAllocatorDefault, length);
+                s->_readBuffer = CFDataCreateMutable(kCFAllocatorSystemDefault, length);
                                CFDataSetLength(s->_readBuffer, length);
                        }
                }
        }
+    
+    if (timercmp(&s->_readBufferTimeout, &timeoutVal, !=)) {
+        s->_readBufferTimeout = timeoutVal;
+        __CFReadSocketsTimeoutInvalid = true;
+    }
+    
+    __CFSpinUnlock(&__CFActiveSocketsLock);
        __CFSocketUnlock(s);
-       if (length == 0)
-               __CFSocketSetReadBufferTimeout(s, 0.0);
 }
 
+void __CFSocketSetReadBufferTimeout(CFSocketRef s, CFTimeInterval timeout)
+{
+#if defined(LOG_CFSOCKET)
+    __socketLog("### (%s DEPRECATED) SET READ BUFFER TIMEOUT for %p (bufferSize %d, timeout %d.%d)\n", __FUNCTION__, s, s->_bytesToBuffer, s->_readBufferTimeout.tv_sec, s->_readBufferTimeout.tv_usec);
+#endif
+    
+    __CFSocketSetSocketReadBufferAttrs(s, timeout, s->_bytesToBuffer);
+}
+
+void __CFSocketSetReadBufferLength(CFSocketRef s, CFIndex length)
+{
+#if defined(LOG_CFSOCKET)
+    __socketLog("### (%s DEPRECATED) SET READ BUFFER LENGTH for %p (bufferSize %d, timeout %d.%d)\n", __FUNCTION__, s, s->_bytesToBuffer, s->_readBufferTimeout.tv_sec, s->_readBufferTimeout.tv_usec);
+#endif
+    
+    CFTimeInterval timeout;
+    
+    if (! timerisset(&s->_readBufferTimeout))
+        timeout = 0;
+    else
+        timeout = 0.1;
+    
+    __CFSocketSetSocketReadBufferAttrs(s, timeout, length);
+}
+
+
 CFIndex __CFSocketRead(CFSocketRef s, UInt8* buffer, CFIndex length, int* error)
 {
 #if defined(LOG_CFSOCKET)
        fprintf(stdout, "READING BYTES FOR SOCKET %d (%d buffered, out of %d desired, eof = %d, err = %d)\n", s->_socket, s->_bytesToBufferPos, s->_bytesToBuffer, s->_atEOF, s->_bufferedReadError);
-#endif /* LOG_CFSOCKET */
+#endif
 
     CFIndex result = -1;
 
@@ -704,7 +741,7 @@ CFIndex __CFSocketRead(CFSocketRef s, UInt8* buffer, CFIndex length, int* error)
        if (s->_leftoverBytes) {
                CFIndex ctBuffer = CFDataGetLength(s->_leftoverBytes);
 #if defined(DEBUG)
-               fprintf(stderr, "%s(%d): WARNING: Draining %d leftover bytes first\n\n", __FUNCTION__, __LINE__, ctBuffer);
+               fprintf(stderr, "%s(%ld): WARNING: Draining %d leftover bytes first\n\n", __FUNCTION__, __LINE__, (long)ctBuffer);
 #endif
                if (ctBuffer > length)
                        ctBuffer = length;
@@ -731,14 +768,14 @@ CFIndex __CFSocketRead(CFSocketRef s, UInt8* buffer, CFIndex length, int* error)
                        if (s->_bytesToBufferReadPos == s->_bytesToBufferPos) {
 #if defined(LOG_CFSOCKET)
                                fprintf(stdout, "DRAINED BUFFER - SHOULD START BUFFERING AGAIN!\n");
-#endif /* LOG_CFSOCKET */
+#endif
                                s->_bytesToBufferPos = 0;
                                s->_bytesToBufferReadPos = 0;
                        }
                        
 #if defined(LOG_CFSOCKET)
                        fprintf(stdout, "SLURPED %d BYTES FROM BUFFER %d LEFT TO READ!\n", ctBuffer, length);
-#endif /* LOG_CFSOCKET */
+#endif
 
                        result = ctBuffer;
             goto unlock;
@@ -750,7 +787,7 @@ CFIndex __CFSocketRead(CFSocketRef s, UInt8* buffer, CFIndex length, int* error)
        if (s->_bufferedReadError != 0) {
 #if defined(LOG_CFSOCKET)
                fprintf(stdout, "RETURNING ERROR %d\n", s->_bufferedReadError);
-#endif /* LOG_CFSOCKET */
+#endif
                *error = s->_bufferedReadError;
         result = -1;
         goto unlock;
@@ -760,7 +797,7 @@ CFIndex __CFSocketRead(CFSocketRef s, UInt8* buffer, CFIndex length, int* error)
        if (s->_atEOF) {
 #if defined(LOG_CFSOCKET)
                fprintf(stdout, "RETURNING EOF\n");
-#endif /* LOG_CFSOCKET */
+#endif
                result = 0;
         goto unlock;
        }
@@ -769,7 +806,7 @@ CFIndex __CFSocketRead(CFSocketRef s, UInt8* buffer, CFIndex length, int* error)
        result = read(CFSocketGetNative(s), buffer, length);
 #if defined(LOG_CFSOCKET)
        fprintf(stdout, "READ %d bytes", result);
-#endif /* LOG_CFSOCKET */
+#endif
 
     if (result == 0) {
         /* note that we hit EOF */
@@ -797,7 +834,7 @@ Boolean __CFSocketGetBytesAvailable(CFSocketRef s, CFIndex* ctBytesAvailable)
                return true;
        } else {
                int result;
-#if ! defined(__WIN32__)
+#if DEPLOYMENT_TARGET_WINDOWS
            int bytesAvailable, intLen = sizeof(bytesAvailable);
            result = getsockopt(CFSocketGetNative(s), SOL_SOCKET, SO_NREAD, &bytesAvailable, (void *)&intLen);
 #else
@@ -824,7 +861,7 @@ static void __CFSocketWriteSocketList(CFArrayRef sockets, CFDataRef fdSet, Boole
         }
     }
 }
-#endif /* LOG_CFSOCKET */
+#endif
 
 #ifdef __GNUC__
 __attribute__ ((noreturn))     // mostly interesting for shutting up a warning
@@ -859,7 +896,7 @@ static void __CFSocketManager(void * arg)
             __CFSocketWriteSocketList(__CFWriteSockets, __CFWriteSocketsFds, FALSE);
         }
         fprintf(stdout, "\n");
-#endif /* LOG_CFSOCKET */
+#endif
         rfds = __CFSocketFdGetSize(__CFReadSocketsFds);
         wfds = __CFSocketFdGetSize(__CFWriteSocketsFds);
         maxnrfds = __CFMax(rfds, wfds);
@@ -878,18 +915,18 @@ static void __CFSocketManager(void * arg)
             __CFReadSocketsTimeoutInvalid = false;
 #if defined(LOG_CFSOCKET)
                        fprintf(stdout, "Figuring out which sockets have timeouts...\n");
-#endif /* LOG_CFSOCKET */
+#endif
             CFArrayApplyFunction(__CFReadSockets, CFRangeMake(0, CFArrayGetCount(__CFReadSockets)), _calcMinTimeout_locked, (void*) &minTimeout);
 
             if (minTimeout == NULL) {
 #if defined(LOG_CFSOCKET)
                                fprintf(stdout, "No one wants a timeout!\n");
-#endif /* LOG_CFSOCKET */
+#endif
                 pTimeout = NULL;
             } else {
 #if defined(LOG_CFSOCKET)
                                fprintf(stdout, "timeout will be %d, %d!\n", minTimeout->tv_sec, minTimeout->tv_usec);
-#endif /* LOG_CFSOCKET */
+#endif
                 tv = *minTimeout;
                 pTimeout = &tv;
             }
@@ -898,7 +935,7 @@ static void __CFSocketManager(void * arg)
         if (pTimeout) {
 #if defined(LOG_CFSOCKET)
                        fprintf(stdout, "select will have a %d, %d timeout\n", pTimeout->tv_sec, pTimeout->tv_usec);
-#endif /* LOG_CFSOCKET */
+#endif
             gettimeofday(&timeBeforeSelect, NULL);
         }
                
@@ -908,7 +945,7 @@ static void __CFSocketManager(void * arg)
 
 #if defined(LOG_CFSOCKET)
                fprintf(stdout, "socket manager woke from select, ret=%ld\n", nrfds);
-#endif /* LOG_CFSOCKET */
+#endif
 
                /*
                 * select returned a timeout
@@ -922,7 +959,7 @@ static void __CFSocketManager(void * arg)
                        
 #if defined(LOG_CFSOCKET)
                        fprintf(stdout, "Socket manager received timeout - kicking off expired reads (expired delta %d, %d)\n", deltaTime.tv_sec, deltaTime.tv_usec);
-#endif /* LOG_CFSOCKET */
+#endif
                        
                        __CFSpinLock(&__CFActiveSocketsLock);
                        
@@ -930,17 +967,17 @@ static void __CFSocketManager(void * arg)
                        cnt = CFArrayGetCount(__CFReadSockets);
                        for (idx = 0; idx < cnt; idx++) {
                                CFSocketRef s = (CFSocketRef)CFArrayGetValueAtIndex(__CFReadSockets, idx);
-                               if (timerisset(&s->_readBufferTimeout)) {
+                               if (timerisset(&s->_readBufferTimeout) || s->_leftoverBytes) {
                                        CFSocketNativeHandle sock = s->_socket;
                                        // We might have an new element in __CFReadSockets that we weren't listening to,
                                        // in which case we must be sure not to test a bit in the fdset that is
                                        // outside our mask size.
                                        Boolean sockInBounds = (0 <= sock && sock < maxnrfds);
                                        /* if this sockets timeout is less than or equal elapsed time, then signal it */
-                                       if (INVALID_SOCKET != sock && sockInBounds && timercmp(&s->_readBufferTimeout, &deltaTime, <=)) {
+                                       if (INVALID_SOCKET != sock && sockInBounds) {
 #if defined(LOG_CFSOCKET)
                                                fprintf(stdout, "Expiring socket %d (delta %d, %d)\n", sock, s->_readBufferTimeout.tv_sec, s->_readBufferTimeout.tv_usec);
-#endif /* LOG_CFSOCKET */
+#endif
                                                CFArraySetValueAtIndex(selectedReadSockets, selectedReadSocketsIndex, s);
                                                selectedReadSocketsIndex++;
                                                /* socket is removed from fds here, will be restored in read handling or in perform function */
@@ -959,7 +996,7 @@ static void __CFSocketManager(void * arg)
             SInt32 selectError = __CFSocketLastError();
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "socket manager received error %ld from select\n", selectError);
-#endif /* LOG_CFSOCKET */
+#endif
             if (EBADF == selectError) {
                 CFMutableArrayRef invalidSockets = CFArrayCreateMutable(kCFAllocatorSystemDefault, 0, &kCFTypeArrayCallBacks);
                 __CFSpinLock(&__CFActiveSocketsLock);
@@ -969,7 +1006,7 @@ static void __CFSocketManager(void * arg)
                     if (!__CFNativeSocketIsValid(s->_socket)) {
 #if defined(LOG_CFSOCKET)
                         fprintf(stdout, "socket manager found write socket %d invalid\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
                         CFArrayAppendValue(invalidSockets, s);
                     }
                 }
@@ -979,7 +1016,7 @@ static void __CFSocketManager(void * arg)
                     if (!__CFNativeSocketIsValid(s->_socket)) {
 #if defined(LOG_CFSOCKET)
                         fprintf(stdout, "socket manager found read socket %d invalid\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
                         CFArrayAppendValue(invalidSockets, s);
                     }
                 }
@@ -997,7 +1034,7 @@ static void __CFSocketManager(void * arg)
             recv(__CFWakeupSocketPair[1], buffer, sizeof(buffer), 0);
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "socket manager received %c on wakeup socket\n", buffer[0]);
-#endif /* LOG_CFSOCKET */
+#endif
         }
         __CFSpinLock(&__CFActiveSocketsLock);
         tempfds = NULL;
@@ -1043,7 +1080,7 @@ static void __CFSocketManager(void * arg)
             if (kCFNull == (CFNullRef)s) continue;
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "socket manager signaling socket %d for write\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
             __CFSocketHandleWrite(s, FALSE);
             CFArraySetValueAtIndex(selectedWriteSockets, idx, kCFNull);
         }
@@ -1054,7 +1091,7 @@ static void __CFSocketManager(void * arg)
             if (kCFNull == (CFNullRef)s) continue;
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "socket manager signaling socket %d for read\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
             __CFSocketHandleRead(s, nrfds == 0);
             CFArraySetValueAtIndex(selectedReadSockets, idx, kCFNull);
         }
@@ -1132,6 +1169,7 @@ __private_extern__ void __CFSocketInitialize(void) {
 CFTypeID CFSocketGetTypeID(void) {
     return __kCFSocketTypeID;
 }
+
 static CFSocketRef _CFSocketCreateWithNative(CFAllocatorRef allocator, CFSocketNativeHandle sock, CFOptionFlags callBackTypes, CFSocketCallBack callout, const CFSocketContext *context, Boolean useExistingInstance) {
     CHECK_FOR_FORK();
     CFSocketRef memory;
@@ -1151,7 +1189,7 @@ static CFSocketRef _CFSocketCreateWithNative(CFAllocatorRef allocator, CFSocketN
                } else {
 #if defined(LOG_CFSOCKET)
                        fprintf(stdout, "useExistingInstance is FALSE, removing existing instance %d from __CFAllSockets\n", (int)memory);
-#endif /* LOG_CFSOCKET */
+#endif
                        __CFSpinUnlock(&__CFAllSocketsLock);
                        CFSocketInvalidate(memory);
                        __CFSpinLock(&__CFAllSocketsLock);
@@ -1199,6 +1237,7 @@ static CFSocketRef _CFSocketCreateWithNative(CFAllocatorRef allocator, CFSocketN
        memory->_bytesToBufferReadPos = 0;
        memory->_atEOF = false;
        memory->_bufferedReadError = 0;
+       memory->_leftoverBytes = NULL;
        
     if (INVALID_SOCKET != sock) CFDictionaryAddValue(__CFAllSockets, (void *)(uintptr_t)sock, memory);
     __CFSpinUnlock(&__CFAllSocketsLock);
@@ -1224,7 +1263,7 @@ void CFSocketInvalidate(CFSocketRef s) {
     __CFGenericValidateType(s, __kCFSocketTypeID);
 #if defined(LOG_CFSOCKET)
     fprintf(stdout, "invalidating socket %d with flags 0x%x disabled 0x%x connected 0x%x\n", s->_socket, s->_f.client, s->_f.disabled, s->_f.connected);
-#endif /* LOG_CFSOCKET */
+#endif
     CFRetain(s);
     __CFSpinLock(&__CFAllSocketsLock);
     __CFSocketLock(s);
@@ -1351,7 +1390,7 @@ void CFSocketSetSocketFlags(CFSocketRef s, CFOptionFlags flags) {
     __CFSocketLock(s);
 #if defined(LOG_CFSOCKET)
         fprintf(stdout, "setting flags for socket %d, from 0x%x to 0x%lx\n", s->_socket, s->_f.client, flags);
-#endif /* LOG_CFSOCKET */
+#endif
     s->_f.client = flags;
     __CFSocketUnlock(s);
 }
@@ -1368,7 +1407,7 @@ void CFSocketDisableCallBacks(CFSocketRef s, CFOptionFlags callBackTypes) {
         s->_f.disabled |= callBackTypes;
 #if defined(LOG_CFSOCKET)
         fprintf(stdout, "unscheduling socket %d with flags 0x%x disabled 0x%x connected 0x%x for types 0x%lx\n", s->_socket, s->_f.client, s->_f.disabled, s->_f.connected, callBackTypes);
-#endif /* LOG_CFSOCKET */
+#endif
         __CFSpinLock(&__CFActiveSocketsLock);
         if ((readCallBackType == kCFSocketAcceptCallBack) || !__CFSocketIsConnectionOriented(s)) s->_f.connected = TRUE;
         if (((callBackTypes & kCFSocketWriteCallBack) != 0) || (((callBackTypes & kCFSocketConnectCallBack) != 0) && !s->_f.connected)) {
@@ -1414,7 +1453,7 @@ void __CFSocketEnableCallBacks(CFSocketRef s, CFOptionFlags callBackTypes, Boole
         if (force) s->_f.disabled &= ~callBackTypes;
 #if defined(LOG_CFSOCKET)
         fprintf(stdout, "rescheduling socket %d with flags 0x%x disabled 0x%x connected 0x%x for types 0x%lx\n", s->_socket, s->_f.client, s->_f.disabled, s->_f.connected, callBackTypes);
-#endif /* LOG_CFSOCKET */
+#endif
         /* We will wait for connection only for connection-oriented, non-rendezvous sockets that are not already connected.  Mark others as already connected. */
         if ((readCallBackType == kCFSocketAcceptCallBack) || !__CFSocketIsConnectionOriented(s)) s->_f.connected = TRUE;
 
@@ -1474,7 +1513,7 @@ static void __CFSocketSchedule(void *info, CFRunLoopRef rl, CFStringRef mode) {
         if (1 == s->_socketSetCount) {
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "scheduling socket %d\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
             __CFSocketEnableCallBacks(s, __CFSocketCallBackTypes(s), TRUE, 's');  // unlocks s
         } else
             __CFSocketUnlock(s);
@@ -1528,7 +1567,7 @@ static void __CFSocketDoCallback(CFSocketRef s, CFDataRef data, CFDataRef addres
     contextInfo = s->_context.info;
 #if defined(LOG_CFSOCKET)
     fprintf(stdout, "entering perform for socket %d with read signalled %d write signalled %d connect signalled %d callback types %d\n", s->_socket, readSignalled, writeSignalled, connectSignalled, callBackTypes);
-#endif /* LOG_CFSOCKET */
+#endif
     if (writeSignalled) {
         errorCode = s->_errorCode;
         s->_f.connected = TRUE;
@@ -1539,13 +1578,13 @@ static void __CFSocketDoCallback(CFSocketRef s, CFDataRef data, CFDataRef addres
             if (errorCode) {
 #if defined(LOG_CFSOCKET)
                 fprintf(stdout, "perform calling out error %ld to socket %d\n", errorCode, s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
                 if (callout) callout(s, kCFSocketConnectCallBack, NULL, &errorCode, contextInfo);
                 calledOut = true;
             } else {
 #if defined(LOG_CFSOCKET)
                 fprintf(stdout, "perform calling out connect to socket %d\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
                 if (callout) callout(s, kCFSocketConnectCallBack, NULL, NULL, contextInfo);
                 calledOut = true;
             }
@@ -1556,7 +1595,7 @@ static void __CFSocketDoCallback(CFSocketRef s, CFDataRef data, CFDataRef addres
             SInt32 datalen = CFDataGetLength(data);
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "perform calling out data of length %ld to socket %d\n", datalen, s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
             if (callout) callout(s, kCFSocketDataCallBack, address, data, contextInfo);
             calledOut = true;
             if (0 == datalen) CFSocketInvalidate(s);
@@ -1565,7 +1604,7 @@ static void __CFSocketDoCallback(CFSocketRef s, CFDataRef data, CFDataRef addres
         if (INVALID_SOCKET != sock && (!calledOut || CFSocketIsValid(s))) {
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "perform calling out accept of socket %d to socket %d\n", sock, s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
             if (callout) callout(s, kCFSocketAcceptCallBack, address, &sock, contextInfo);
             calledOut = true;
         }
@@ -1573,7 +1612,7 @@ static void __CFSocketDoCallback(CFSocketRef s, CFDataRef data, CFDataRef addres
         if (readSignalled && (!calledOut || CFSocketIsValid(s))) {
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "perform calling out read to socket %d\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
             if (callout) callout(s, kCFSocketReadCallBack, NULL, NULL, contextInfo);
             calledOut = true;
         }
@@ -1582,7 +1621,7 @@ static void __CFSocketDoCallback(CFSocketRef s, CFDataRef data, CFDataRef addres
         if (writeSignalled && !errorCode && (!calledOut || CFSocketIsValid(s))) {
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "perform calling out write to socket %d\n", s->_socket);
-#endif /* LOG_CFSOCKET */
+#endif
             if (callout) callout(s, kCFSocketWriteCallBack, NULL, NULL, contextInfo);
             calledOut = true;
         }
@@ -1638,7 +1677,7 @@ static void __CFSocketPerformV0(void *info) {
             CFRunLoopSourceSignal(s->_source0);
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "perform short-circuit signaling source for socket %d with flags 0x%x disabled 0x%x connected 0x%x\n", s->_socket, s->_f.client, s->_f.disabled, s->_f.connected);
-#endif /* LOG_CFSOCKET */
+#endif
             rl = __CFSocketCopyRunLoopToWakeUp(s);
         }
     }
@@ -1719,7 +1758,7 @@ CFSocketError CFSocketSendData(CFSocketRef s, CFDataRef address, CFDataRef data,
         }
 #if defined(LOG_CFSOCKET)
         fprintf(stdout, "wrote %ld bytes to socket %d\n", size, sock);
-#endif /* LOG_CFSOCKET */
+#endif
         __CFSocketWriteUnlock(s);
         CFRelease(s);
     }
@@ -1769,7 +1808,7 @@ CFSocketError CFSocketConnectToAddress(CFSocketRef s, CFDataRef address, CFTimeI
         }
 #if defined(LOG_CFSOCKET)
         fprintf(stdout, "connection attempt returns %ld error %ld on socket %d (flags 0x%lx blocking %d)\n", result, connect_err, sock, flags, wasBlocking);
-#endif /* LOG_CFSOCKET */
+#endif
         if (EINPROGRESS == connect_err && timeout >= 0.0) {
             /* select on socket */
             SInt32 nrfds;
@@ -1792,14 +1831,14 @@ CFSocketError CFSocketConnectToAddress(CFSocketRef s, CFDataRef address, CFTimeI
             CFRelease(fds);
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "timed connection attempt %s on socket %d, result %ld, select returns %ld error %ld\n", (result == 0) ? "succeeds" : "fails", sock, result, nrfds, select_err);
-#endif /* LOG_CFSOCKET */
+#endif
         }
         if (wasBlocking && (timeout > 0.0 || timeout < 0.0)) ioctlsocket(sock, FIONBIO, &no);
         if (EINPROGRESS == connect_err && timeout < 0.0) {
             result = 0;
 #if defined(LOG_CFSOCKET)
             fprintf(stdout, "connection attempt continues in background on socket %d\n", sock);
-#endif /* LOG_CFSOCKET */
+#endif
         }
     }
     //??? should return errno
index 129023034a667cd96d1f7cea705ded203d7de593..d9154f677c1c0b99a753e0fee4d0e1e129ef7e54 100644 (file)
@@ -21,4 +21,4 @@
  * @APPLE_LICENSE_HEADER_END@
  */
 const unsigned char kCFCoreFoundationVersionString[] = "@(#)PROGRAM:CoreFoundation  PROJECT:CoreFoundation-476  SYSTEM:Darwin  DEVELOPER:unknown  BUILT:" __DATE__ " " __TIME__ "\n";
-const double kCFCoreFoundationVersionNumber = (double)476.10;
+const double kCFCoreFoundationVersionNumber = (double)476.17;