*/
/* CFSocket.c
Copyright (c) 1999-2007 Apple Inc. All rights reserved.
- Responsibility: Doug Davidson
+ Responsibility: Christopher Kane
*/
#define _DARWIN_UNLIMITED_SELECT 1
// 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);
}
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;
__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 {
}
#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 */
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)
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;
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);
} else {
#if defined(LOG_CFSOCKET)
fprintf(stdout, "DONE READING (read %d bytes) - GOING TO SIGNAL\n", ctRead);
- #endif /* LOG_CFSOCKET */
+ #endif
}
}
}
}
#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);
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;
/* 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;
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) {
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;
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;
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;
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;
if (s->_atEOF) {
#if defined(LOG_CFSOCKET)
fprintf(stdout, "RETURNING EOF\n");
-#endif /* LOG_CFSOCKET */
+#endif
result = 0;
goto unlock;
}
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 */
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
}
}
}
-#endif /* LOG_CFSOCKET */
+#endif
#ifdef __GNUC__
__attribute__ ((noreturn)) // mostly interesting for shutting up a warning
__CFSocketWriteSocketList(__CFWriteSockets, __CFWriteSocketsFds, FALSE);
}
fprintf(stdout, "\n");
-#endif /* LOG_CFSOCKET */
+#endif
rfds = __CFSocketFdGetSize(__CFReadSocketsFds);
wfds = __CFSocketFdGetSize(__CFWriteSocketsFds);
maxnrfds = __CFMax(rfds, wfds);
__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;
}
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);
}
#if defined(LOG_CFSOCKET)
fprintf(stdout, "socket manager woke from select, ret=%ld\n", nrfds);
-#endif /* LOG_CFSOCKET */
+#endif
/*
* select returned a timeout
#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);
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 */
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);
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);
}
}
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);
}
}
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;
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);
}
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);
}
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;
} 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);
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);
__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);
__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);
}
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)) {
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;
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);
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;
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;
}
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);
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;
}
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;
}
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;
}
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);
}
}
}
#if defined(LOG_CFSOCKET)
fprintf(stdout, "wrote %ld bytes to socket %d\n", size, sock);
-#endif /* LOG_CFSOCKET */
+#endif
__CFSocketWriteUnlock(s);
CFRelease(s);
}
}
#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;
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