Lines Matching refs:sock

54 DISPATCH_HELPER_FUNCTIONS(sock, CFSocket)
142 CF_INLINE Boolean __CFSocketIsValid(CFSocketRef sock) {
143 return kCFSocketStateReady == sock->_state;
147 CFSocketRef sock = (CFSocketRef)cf;
149 if (NULL != sock->_context.info && NULL != sock->_context.copyDescription) {
150 contextDesc = sock->_context.copyDescription(sock->_context.info);
153 contextDesc = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("<CFSocket context %p>"), sock->_context.info);
156 void *addr = sock->_callout;
159 ioctlsocket(sock->_shared ? sock->_shared->_socket : -1, FIONREAD, &avail);
168 cf, CFGetAllocator(sock), __CFSocketIsValid(sock) ? "Yes" : "No", sock->_shared ? sock->_shared->_socket : -1,
169 sock->_wantConnect ? "Yes" : "No", sock->_connectDisabled ? "Yes" : "No",
170 sock->_wantWrite ? "Yes" : "No", sock->_reenableWrite ? "Yes" : "No", sock->_writeDisabled ? "Yes" : "No",
171 sock->_wantReadType ? "Yes" : "No", sock->_reenableRead ? "Yes" : "No", sock->_readDisabled? "Yes" : "No",
172 sock->_leaveErrors ? "Yes" : "No", sock->_closeOnInvalidate ? "Yes" : "No", sock->_connected ? "Yes" : "No",
173 sock->_error, avail,
174 sock->_shared ? sock->_shared->_source : NULL, name, addr, contextDesc);
183 CFSocketRef sock = (CFSocketRef)cf;
185 sock->_state = kCFSocketStateDeallocating;
186 if (sock->_peerAddress) {
187 CFRelease(sock->_peerAddress);
188 sock->_peerAddress = NULL;
190 if (sock->_address) {
191 CFRelease(sock->_address);
192 sock->_address = NULL;
280 __block CFSocketRef sock = NULL;
286 sock = s;
436 sock = memory;
438 // CFLog(5, CFSTR("CFSocketCreateWithNative(): created socket %p with callbacks 0x%x"), sock, callBackTypes);
439 if (sock && !CFSocketIsValid(sock)) { // must do this outside lock to avoid deadlock
440 CFRelease(sock);
441 sock = NULL;
443 return sock;
446 CFSocketNativeHandle CFSocketGetNative(CFSocketRef sock) {
448 __CFGenericValidateType(sock, CFSocketGetTypeID());
449 return sock->_shared ? sock->_shared->_socket : INVALID_SOCKET;
452 void CFSocketGetContext(CFSocketRef sock, CFSocketContext *context) {
453 __CFGenericValidateType(sock, CFSocketGetTypeID());
455 objc_memmove_collectable(context, &sock->_context, sizeof(CFSocketContext));
458 CFDataRef CFSocketCopyAddress(CFSocketRef sock) {
460 __CFGenericValidateType(sock, CFSocketGetTypeID());
463 if (!sock->_address) {
464 if (!__CFSocketIsValid(sock)) return;
467 int ret = getsockname(sock->_shared->_socket, (struct sockaddr *)name, (socklen_t *)&namelen);
469 sock->_address = CFDataCreate(CFGetAllocator(sock), name, namelen);
472 result = sock->_address ? (CFDataRef)CFRetain(sock->_address) : NULL;
477 CFDataRef CFSocketCopyPeerAddress(CFSocketRef sock) {
479 __CFGenericValidateType(sock, CFSocketGetTypeID());
482 if (!sock->_peerAddress) {
483 if (!__CFSocketIsValid(sock)) return;
486 int ret = getpeername(sock->_shared->_socket, (struct sockaddr *)name, (socklen_t *)&namelen);
488 sock->_peerAddress = CFDataCreate(CFGetAllocator(sock), name, namelen);
491 result = sock->_peerAddress ? (CFDataRef)CFRetain(sock->_peerAddress) : NULL;
496 CFOptionFlags CFSocketGetSocketFlags(CFSocketRef sock) {
498 __CFGenericValidateType(sock, CFSocketGetTypeID());
501 if (sock->_reenableRead) flags |= sock->_wantReadType; // flags are same as types here
502 if (sock->_reenableWrite) flags |= kCFSocketAutomaticallyReenableWriteCallBack;
503 if (sock->_leaveErrors) flags |= kCFSocketLeaveErrors;
504 if (sock->_closeOnInvalidate) flags |= kCFSocketCloseOnInvalidate;
509 void CFSocketSetSocketFlags(CFSocketRef sock, CFOptionFlags flags) {
511 // CFLog(5, CFSTR("CFSocketSetSocketFlags(%p, 0x%x) starting"), sock, flags);
512 __CFGenericValidateType(sock, CFSocketGetTypeID());
514 sock->_reenableRead = (sock->_wantReadType && ((flags & 0x3) == sock->_wantReadType)) ? true : false;
515 sock->_reenableWrite = (sock->_wantWrite && (flags & kCFSocketAutomaticallyReenableWriteCallBack)) ? true : false;
516 sock->_leaveErrors = (flags & kCFSocketLeaveErrors) ? true : false;
517 sock->_closeOnInvalidate = (flags & kCFSocketCloseOnInvalidate) ? true : false;
518 if (sock->_shared) sock->_shared->_closeFD = sock->_closeOnInvalidate;
520 // CFLog(5, CFSTR("CFSocketSetSocketFlags(%p, 0x%x) done"), sock, flags);
523 void CFSocketEnableCallBacks(CFSocketRef sock, CFOptionFlags callBackTypes) {
525 __CFGenericValidateType(sock, CFSocketGetTypeID());
526 // CFLog(5, CFSTR("CFSocketEnableCallBacks(%p, 0x%x) starting"), sock, callBackTypes);
528 if (!__CFSocketIsValid(sock)) return;
529 if (sock->_wantReadType && (callBackTypes & 0x3) == sock->_wantReadType) {
530 if (sockfd_is_readable(sock->_shared->_socket)) {
531 sock->_readable = true;
532 // CFLog(5, CFSTR("CFSocketEnableCallBacks(%p, 0x%x) socket is readable"), sock, callBackTypes);
533 if (!sock->_rsuspended) {
534 dispatch_suspend(sock->_shared->_rdsrc);
535 sock->_rsuspended = true;
538 if (sock->_shared->_source) {
539 CFRunLoopSourceSignal(sock->_shared->_source);
540 _CFRunLoopSourceWakeUpRunLoops(sock->_shared->_source);
542 } else if (sock->_rsuspended && sock->_shared->_rdsrc) {
543 sock->_rsuspended = false;
544 dispatch_resume(sock->_shared->_rdsrc);
546 sock->_readDisabled = false;
548 if (sock->_wantWrite && (callBackTypes & kCFSocketWriteCallBack)) {
549 if (sockfd_is_writeable(sock->_shared->_socket)) {
550 sock->_writeable = true;
551 if (!sock->_wsuspended) {
552 dispatch_suspend(sock->_shared->_wrsrc);
553 sock->_wsuspended = true;
556 if (sock->_shared->_source) {
557 CFRunLoopSourceSignal(sock->_shared->_source);
558 _CFRunLoopSourceWakeUpRunLoops(sock->_shared->_source);
560 } else if (sock->_wsuspended && sock->_shared->_wrsrc) {
561 sock->_wsuspended = false;
562 dispatch_resume(sock->_shared->_wrsrc);
564 sock->_writeDisabled = false;
566 if (sock->_wantConnect && !sock->_connected && (callBackTypes & kCFSocketConnectCallBack)) {
567 if (sockfd_is_writeable(sock->_shared->_socket)) {
568 sock->_writeable = true;
569 if (!sock->_wsuspended) {
570 dispatch_suspend(sock->_shared->_wrsrc);
571 sock->_wsuspended = true;
574 if (sock->_shared->_source) {
575 CFRunLoopSourceSignal(sock->_shared->_source);
576 _CFRunLoopSourceWakeUpRunLoops(sock->_shared->_source);
578 } else if (sock->_wsuspended && sock->_shared->_wrsrc) {
579 sock->_wsuspended = false;
580 dispatch_resume(sock->_shared->_wrsrc);
582 sock->_connectDisabled = false;
585 // CFLog(5, CFSTR("CFSocketEnableCallBacks(%p, 0x%x) done"), sock, callBackTypes);
588 void CFSocketDisableCallBacks(CFSocketRef sock, CFOptionFlags callBackTypes) {
590 __CFGenericValidateType(sock, CFSocketGetTypeID());
591 // CFLog(5, CFSTR("CFSocketDisableCallBacks(%p, 0x%x) starting"), sock, callBackTypes);
593 if (!__CFSocketIsValid(sock)) return;
594 if (sock->_wantReadType && (callBackTypes & 0x3) == sock->_wantReadType) {
595 if (!sock->_rsuspended && sock->_shared->_rdsrc) {
596 dispatch_suspend(sock->_shared->_rdsrc);
597 sock->_rsuspended = true;
599 sock->_readDisabled = true;
601 if (sock->_wantWrite && (callBackTypes & kCFSocketWriteCallBack)) {
602 if (!sock->_wsuspended && sock->_shared->_wrsrc) {
603 dispatch_suspend(sock->_shared->_wrsrc);
604 sock->_wsuspended = true;
606 sock->_writeDisabled = true;
608 if (sock->_wantConnect && !sock->_connected && (callBackTypes & kCFSocketConnectCallBack)) {
609 if (!sock->_wsuspended && sock->_shared->_wrsrc) {
610 dispatch_suspend(sock->_shared->_wrsrc);
611 sock->_wsuspended = true;
613 sock->_connectDisabled = true;
616 // CFLog(5, CFSTR("CFSocketDisableCallBacks(%p, 0x%x) done"), sock, callBackTypes);
619 void CFSocketInvalidate(CFSocketRef sock) {
621 __CFGenericValidateType(sock, CFSocketGetTypeID());
622 CFRetain(sock);
623 // CFLog(5, CFSTR("CFSocketInvalidate(%p) starting"), sock);
627 wasReady = (sock->_state == kCFSocketStateReady);
629 sock->_state = kCFSocketStateInvalidating;
633 if (s == sock) {
638 if (sock->_shared->_rdsrc) {
639 dispatch_source_cancel(sock->_shared->_rdsrc);
640 if (sock->_rsuspended) {
641 sock->_rsuspended = false;
642 dispatch_resume(sock->_shared->_rdsrc);
645 if (sock->_shared->_wrsrc) {
646 dispatch_source_cancel(sock->_shared->_wrsrc);
647 if (sock->_wsuspended) {
648 sock->_wsuspended = false;
649 dispatch_resume(sock->_shared->_wrsrc);
652 source = sock->_shared->_source;
653 sock->_shared->_source = NULL;
654 sock->_shared->_refCnt--;
655 if (0 == sock->_shared->_refCnt) {
656 if (sock->_shared->_closeFD) {
658 (void)shutdown(sock->_shared->_socket, SHUT_RDWR);
660 dup2(nullfd, sock->_shared->_socket);
662 close(sock->_shared->_socket);
664 free(sock->_shared);
666 sock->_shared = NULL;
674 void *info = sock->_context.info;
675 sock->_context.info = NULL;
676 if (sock->_context.release) {
677 sock->_context.release(info);
679 sock->_state = kCFSocketStateInvalid;
682 // CFLog(5, CFSTR("CFSocketInvalidate(%p) done%s"), sock, wasReady ? " -- done on this thread" : "");
683 CFRelease(sock);
686 Boolean CFSocketIsValid(CFSocketRef sock) {
687 __CFGenericValidateType(sock, CFSocketGetTypeID());
688 if (!__CFSocketIsValid(sock)) return false;
690 int ret = sock->_shared ? fstat(sock->_shared->_socket, &statbuf) : -1;
692 CFSocketInvalidate(sock);
701 CFSocketRef sock = (CFSocketRef)info;
703 // CFLog(5, CFSTR("__CFSocketPerform(%p) starting '%@'"), sock, sock);
713 isValid = __CFSocketIsValid(sock);
715 fd = sock->_shared->_socket;
716 doRead = sock->_readable && sock->_wantReadType && !sock->_readDisabled;
718 sock->_readable = false;
720 // if (!doRead) CFLog(5, CFSTR("__CFSocketPerform(%p) socket is not actually readable"), sock);
722 doWrite = sock->_writeable && sock->_wantWrite && !sock->_writeDisabled;
723 doConnect = sock->_writeable && sock->_wantConnect && !sock->_connectDisabled && !sock->_connected;
725 sock->_writeable = false;
729 if (!sock->_leaveErrors && (doWrite || doConnect)) { // not on read, for whatever reason
733 sock->_error = errorCode;
735 sock->_connected = true;
736 // CFLog(5, CFSTR("__CFSocketPerform(%p) doing %d %d %d"), sock, doRead, doWrite, doConnect);
738 switch (sock->_wantReadType) {
746 address = CFDataCreate(CFGetAllocator(sock), name, namelen);
757 data = CFDataCreateMutable(CFGetAllocator(sock), 0);
763 address = CFDataCreate(CFGetAllocator(sock), name, namelen);
764 } else if (sock->_connOriented) {
766 if (!sock->_peerAddress) {
769 int ret = getpeername(sock->_shared->_socket, (struct sockaddr *)name, (socklen_t *)&namelen);
771 sock->_peerAddress = CFDataCreate(CFGetAllocator(sock), name, namelen);
774 address = sock->_peerAddress ? (CFDataRef)CFRetain(sock->_peerAddress) : NULL;
777 address = CFDataCreate(CFGetAllocator(sock), NULL, 0);
783 if (sock->_reenableRead) {
784 // CFLog(5, CFSTR("__CFSocketPerform(%p) reenabling read %d %p"), sock, sock->_rsuspended, sock->_shared->_rdsrc);
785 if (sock->_rsuspended && sock->_shared->_rdsrc) {
786 sock->_rsuspended = false;
787 dispatch_resume(sock->_shared->_rdsrc);
790 if (sock->_reenableWrite) {
791 if (sock->_wsuspended && sock->_shared->_wrsrc) {
792 sock->_wsuspended = false;
793 dispatch_resume(sock->_shared->_wrsrc);
796 if (sock->_context.retain && (doConnect || doRead || doWrite)) {
797 context_info = (void *)sock->_context.retain(sock->_context.info);
798 context_release = sock->_context.release;
800 context_info = sock->_context.info;
803 // CFLog(5, CFSTR("__CFSocketPerform(%p) isValid:%d, doRead:%d, doWrite:%d, doConnect:%d error:%d"), sock, isValid, doRead, doWrite, doConnect, errorCode);
808 if (sock->_callout) sock->_callout(sock, kCFSocketConnectCallBack, NULL, (0 != errorCode) ? &errorCode : NULL, context_info);
811 if (doRead && (!calledOut || __CFSocketIsValid(sock))) {
812 switch (sock->_wantReadType) {
814 if (sock->_callout) sock->_callout(sock, kCFSocketReadCallBack, NULL, NULL, context_info);
819 if (sock->_callout) sock->_callout(sock, kCFSocketAcceptCallBack, address, &new_fd, context_info);
824 if (sock->_callout) sock->_callout(sock, kCFSocketDataCallBack, address, data, context_info);
829 if (doWrite && (!calledOut || __CFSocketIsValid(sock))) {
831 if (sock->_callout) sock->_callout(sock, kCFSocketWriteCallBack, NULL, NULL, context_info);
836 if (data && 0 == CFDataGetLength(data)) CFSocketInvalidate(sock);
844 // CFLog(5, CFSTR("__CFSocketPerform(%p) done"), sock);
848 CFSocketRef sock = (CFSocketRef)info;
849 int32_t newVal = OSAtomicIncrement32Barrier(&sock->_runLoopCounter);
851 CFOptionFlags types = sock->_wantReadType | (sock->_wantWrite ? kCFSocketWriteCallBack : 0) | (sock->_wantConnect ? kCFSocketConnectCallBack : 0);
852 CFSocketEnableCallBacks(sock, types);
858 CFSocketRef sock = (CFSocketRef)info;
859 OSAtomicDecrement32Barrier(&sock->_runLoopCounter);
863 CFRunLoopSourceRef CFSocketCreateRunLoopSource(CFAllocatorRef allocator, CFSocketRef sock, CFIndex order) {
865 __CFGenericValidateType(sock, CFSocketGetTypeID());
866 if (!CFSocketIsValid(sock)) return NULL;
869 if (!__CFSocketIsValid(sock)) return;
870 if (NULL != sock->_shared->_source && !CFRunLoopSourceIsValid(sock->_shared->_source)) {
871 CFRelease(sock->_shared->_source);
872 sock->_shared->_source = NULL;
874 if (NULL == sock->_shared->_source) {
877 context.info = (void *)sock;
886 sock->_shared->_source = CFRunLoopSourceCreate(allocator, order, (CFRunLoopSourceContext *)&context);
887 if (sock->_shared->_source) {
888 if (sock->_wantReadType) {
889 if (sockfd_is_readable(sock->_shared->_socket)) {
890 sock->_readable = true;
891 if (!sock->_rsuspended) {
892 dispatch_suspend(sock->_shared->_rdsrc);
893 sock->_rsuspended = true;
895 if (sock->_shared->_source) {
896 CFRunLoopSourceSignal(sock->_shared->_source);
897 _CFRunLoopSourceWakeUpRunLoops(sock->_shared->_source);
899 } else if (sock->_rsuspended && sock->_shared->_rdsrc) {
900 sock->_rsuspended = false;
901 dispatch_resume(sock->_shared->_rdsrc);
904 if (sock->_wantWrite || (sock->_wantConnect && !sock->_connected)) {
905 if (sockfd_is_writeable(sock->_shared->_socket)) {
906 sock->_writeable = true;
907 if (!sock->_wsuspended) {
908 dispatch_suspend(sock->_shared->_wrsrc);
909 sock->_wsuspended = true;
911 if (sock->_shared->_source) {
912 CFRunLoopSourceSignal(sock->_shared->_source);
913 _CFRunLoopSourceWakeUpRunLoops(sock->_shared->_source);
915 } else if (sock->_wsuspended && sock->_shared->_wrsrc) {
916 sock->_wsuspended = false;
917 dispatch_resume(sock->_shared->_wrsrc);
922 result = sock->_shared->_source ? (CFRunLoopSourceRef)CFRetain(sock->_shared->_source) : NULL;
924 // CFLog(5, CFSTR("CFSocketCreateRunLoopSource(%p) => %p"), sock, result);
1026 CF_INLINE Boolean __CFSocketFdSet(CFSocketNativeHandle sock, CFMutableDataRef fdSet) {
1029 if (INVALID_SOCKET != sock && 0 <= sock) {
1032 if (sock >= numFds) {
1033 CFIndex oldSize = numFds / NFDBITS, newSize = (sock + NFDBITS) / NFDBITS, changeInBytes = (newSize - oldSize) * sizeof(fd_mask);
1040 if (!FD_ISSET(sock, (fd_set *)fds_bits)) {
1042 FD_SET(sock, (fd_set *)fds_bits);
1072 static void __CFSocketDoCallback(CFSocketRef s, CFDataRef data, CFDataRef address, CFSocketNativeHandle sock);
1198 static Boolean __CFNativeSocketIsValid(CFSocketNativeHandle sock) {
1202 return !(0 != getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&errorCode, &errorSize) && __CFSocketLastError() == WSAENOTSOCK);
1204 SInt32 flags = fcntl(sock, F_GETFL, 0);
1209 CF_INLINE Boolean __CFSocketFdClr(CFSocketNativeHandle sock, CFMutableDataRef fdSet) {
1212 if (INVALID_SOCKET != sock && 0 <= sock) {
1215 if (sock < numFds) {
1217 if (FD_ISSET(sock, (fd_set *)fds_bits)) {
1219 FD_CLR(sock, (fd_set *)fds_bits);
1476 CFSocketNativeHandle sock = INVALID_SOCKET;
1540 sock = accept(s->_socket, (struct sockaddr *)name, (socklen_t *)&namelen);
1541 if (INVALID_SOCKET == sock) {
1552 closesocket(sock);
1564 CFArrayAppendValue(s->_dataQueue, (void *)(uintptr_t)sock);
2101 CFSocketNativeHandle sock = s->_socket;
2105 Boolean sockInBounds = (0 <= sock && sock < maxnrfds);
2107 if (INVALID_SOCKET != sock && sockInBounds) {
2109 fprintf(stdout, "Expiring socket %d (delta %ld, %d)\n", sock, s->_readBufferTimeout.tv_sec, s->_readBufferTimeout.tv_usec);
2115 FD_CLR(sock, tempfds);
2140 CFSocketNativeHandle sock = s->_socket;
2144 Boolean sockInBounds = (0 <= sock && sock < maxnrfds);
2145 if (INVALID_SOCKET != sock && sockInBounds) {
2146 if (FD_ISSET(sock, writefds)) {
2151 FD_CLR(sock, tempfds);
2160 CFSocketNativeHandle sock = s->_socket;
2164 Boolean sockInBounds = (0 <= sock && sock < maxnrfds);
2165 if (INVALID_SOCKET != sock && sockInBounds && FD_ISSET(sock, readfds)) {
2170 FD_CLR(sock, tempfds);
2291 static CFSocketRef _CFSocketCreateWithNative(CFAllocatorRef allocator, CFSocketNativeHandle sock, CFOptionFlags callBackTypes, CFSocketCallBack callout, const CFSocketContext *context, Boolean useExistingInstance) {
2302 if (INVALID_SOCKET != sock && CFDictionaryGetValueIfPresent(__CFAllSockets, (void *)(uintptr_t)sock, (const void **)&memory)) {
2322 if (INVALID_SOCKET != sock) __CFSocketSetValid(memory);
2332 memory->_socket = sock;
2333 if (INVALID_SOCKET == sock || 0 != getsockopt(sock, SOL_SOCKET, SO_TYPE, (char *)&(memory->_socketType), (socklen_t *)&typeSize)) memory->_socketType = 0; // cast for WinSock bad API
2339 if (INVALID_SOCKET != sock) {
2360 if (INVALID_SOCKET != sock) CFDictionaryAddValue(__CFAllSockets, (void *)(uintptr_t)sock, memory);
2378 CFSocketRef CFSocketCreateWithNative(CFAllocatorRef allocator, CFSocketNativeHandle sock, CFOptionFlags callBackTypes, CFSocketCallBack callout, const CFSocketContext *context) {
2379 return _CFSocketCreateWithNative(allocator, sock, callBackTypes, callout, context, TRUE);
2699 static void __CFSocketDoCallback(CFSocketRef s, CFDataRef data, CFDataRef address, CFSocketNativeHandle sock) {
2752 if (INVALID_SOCKET != sock && (!calledOut || CFSocketIsValid(s))) {
2754 fprintf(stdout, "perform calling out accept of socket %d to socket %d\n", sock, s->_socket);
2756 if (callout) callout(s, kCFSocketAcceptCallBack, address, &sock, contextInfo);
2785 CFSocketNativeHandle sock = INVALID_SOCKET;
2812 sock = (CFSocketNativeHandle)(uintptr_t)CFArrayGetValueAtIndex(s->_dataQueue, 0);
2820 __CFSocketDoCallback(s, data, address, sock); // does __CFSocketUnlock(s)
2925 CF_INLINE Boolean __CFSocketFdSet(CFSocketNativeHandle sock, CFMutableDataRef fdSet) {
2928 if (INVALID_SOCKET != sock && 0 <= sock) {
2931 if (sock >= numFds) {
2932 CFIndex oldSize = numFds / NFDBITS, newSize = (sock + NFDBITS) / NFDBITS, changeInBytes = (newSize - oldSize) * sizeof(fd_mask);
2939 if (!FD_ISSET(sock, (fd_set *)fds_bits)) {
2941 FD_SET(sock, (fd_set *)fds_bits);
2954 CFSocketNativeHandle sock = INVALID_SOCKET;
2963 if (CFSocketIsValid(s)) sock = CFSocketGetNative(s);
2964 if (INVALID_SOCKET != sock) {
2969 setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv)); // cast for WinSock bad API
2971 size = sendto(sock, (char *)dataptr, datalen, 0, (struct sockaddr *)addrptr, addrlen);
2973 size = send(sock, (char *)dataptr, datalen, 0);
2976 fprintf(stdout, "wrote %ld bytes to socket %d\n", (long)size, sock);
2996 CFSocketNativeHandle sock = CFSocketGetNative(s);
3019 int result = bind(sock, name, namelen);
3021 listen(sock, 256);
3040 CFSocketNativeHandle sock = CFSocketGetNative(s);
3043 SInt32 flags = fcntl(sock, F_GETFL, 0);
3045 if (wasBlocking && (timeout > 0.0 || timeout < 0.0)) ioctlsocket(sock, FIONBIO, (u_long *)&yes);
3051 if (timeout > 0.0 || timeout < 0.0) ioctlsocket(sock, FIONBIO, (u_long *)&yes);
3054 result = connect(sock, (struct sockaddr *)name, namelen);
3062 fprintf(stdout, "connection attempt returns %d error %d on socket %d (flags 0x%x blocking %d)\n", (int) result, (int) connect_err, sock, (int) flags, wasBlocking);
3070 __CFSocketFdSet(sock, fds);
3080 if (0 != getsockopt(sock, SOL_SOCKET, SO_ERROR, (char *)&select_err, (socklen_t *)&error_size)) select_err = 0;
3085 fprintf(stdout, "timed connection attempt %s on socket %d, result %d, select returns %d error %d\n", (result == 0) ? "succeeds" : "fails", sock, (int) result, (int) nrfds, (int) select_err);
3088 if (wasBlocking && (timeout > 0.0 || timeout < 0.0)) ioctlsocket(sock, FIONBIO, (u_long *)&no);
3092 fprintf(stdout, "connection attempt continues in background on socket %d\n", sock);
3102 CFSocketNativeHandle sock = INVALID_SOCKET;
3117 sock = socket(protocolFamily, socketType, protocol);
3118 if (INVALID_SOCKET != sock) {
3119 s = CFSocketCreateWithNative(allocator, sock, callBackTypes, callout, context);