diff options
| author | Miles Bader | 2007-12-06 00:46:18 +0000 |
|---|---|---|
| committer | Miles Bader | 2007-12-06 00:46:18 +0000 |
| commit | e5e76c04310d287a56675876dd83e1089faba215 (patch) | |
| tree | a4b4f1cc134e4fd5af42671ec6689e07afe48ff2 /src/mac.c | |
| parent | b890d447fb56bfe9f2e4742eda4b3ab4b5f4b32a (diff) | |
| parent | a2afc99dbad3fa9a3170ad72c578451c3aea58a4 (diff) | |
| download | emacs-e5e76c04310d287a56675876dd83e1089faba215.tar.gz emacs-e5e76c04310d287a56675876dd83e1089faba215.zip | |
Merge from emacs--rel--22
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-943
Diffstat (limited to 'src/mac.c')
| -rw-r--r-- | src/mac.c | 51 |
1 files changed, 49 insertions, 2 deletions
| @@ -5004,6 +5004,10 @@ extern int noninteractive; | |||
| 5004 | #if SELECT_USE_CFSOCKET | 5004 | #if SELECT_USE_CFSOCKET |
| 5005 | #define SELECT_TIMEOUT_THRESHOLD_RUNLOOP 0.2 | 5005 | #define SELECT_TIMEOUT_THRESHOLD_RUNLOOP 0.2 |
| 5006 | 5006 | ||
| 5007 | /* Dictionary of file descriptors vs CFSocketRef's allocated in | ||
| 5008 | sys_select. */ | ||
| 5009 | static CFMutableDictionaryRef cfsockets_for_select; | ||
| 5010 | |||
| 5007 | static void | 5011 | static void |
| 5008 | socket_callback (s, type, address, data, info) | 5012 | socket_callback (s, type, address, data, info) |
| 5009 | CFSocketRef s; | 5013 | CFSocketRef s; |
| @@ -5089,6 +5093,43 @@ select_and_poll_event (nfds, rfds, wfds, efds, timeout) | |||
| 5089 | return 0; | 5093 | return 0; |
| 5090 | } | 5094 | } |
| 5091 | 5095 | ||
| 5096 | /* Clean up the CFSocket associated with the file descriptor FD in | ||
| 5097 | case the same descriptor is used in other threads later. If no | ||
| 5098 | CFSocket is associated with FD, then return 0 without closing FD. | ||
| 5099 | Otherwise, return 1 with closing FD. */ | ||
| 5100 | |||
| 5101 | int | ||
| 5102 | mac_try_close_socket (fd) | ||
| 5103 | int fd; | ||
| 5104 | { | ||
| 5105 | #if SELECT_USE_CFSOCKET | ||
| 5106 | if (cfsockets_for_select) | ||
| 5107 | { | ||
| 5108 | void *key = (void *) fd; | ||
| 5109 | CFSocketRef socket = | ||
| 5110 | (CFSocketRef) CFDictionaryGetValue (cfsockets_for_select, key); | ||
| 5111 | |||
| 5112 | if (socket) | ||
| 5113 | { | ||
| 5114 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020 | ||
| 5115 | CFOptionFlags flags = CFSocketGetSocketFlags (socket); | ||
| 5116 | |||
| 5117 | if (!(flags & kCFSocketCloseOnInvalidate)) | ||
| 5118 | CFSocketSetSocketFlags (socket, flags | kCFSocketCloseOnInvalidate); | ||
| 5119 | #endif | ||
| 5120 | BLOCK_INPUT; | ||
| 5121 | CFSocketInvalidate (socket); | ||
| 5122 | CFDictionaryRemoveValue (cfsockets_for_select, key); | ||
| 5123 | UNBLOCK_INPUT; | ||
| 5124 | |||
| 5125 | return 1; | ||
| 5126 | } | ||
| 5127 | } | ||
| 5128 | #endif | ||
| 5129 | |||
| 5130 | return 0; | ||
| 5131 | } | ||
| 5132 | |||
| 5092 | int | 5133 | int |
| 5093 | sys_select (nfds, rfds, wfds, efds, timeout) | 5134 | sys_select (nfds, rfds, wfds, efds, timeout) |
| 5094 | int nfds; | 5135 | int nfds; |
| @@ -5165,6 +5206,11 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5165 | CFDictionaryCreateMutable (NULL, 0, NULL, | 5206 | CFDictionaryCreateMutable (NULL, 0, NULL, |
| 5166 | &kCFTypeDictionaryValueCallBacks); | 5207 | &kCFTypeDictionaryValueCallBacks); |
| 5167 | 5208 | ||
| 5209 | if (cfsockets_for_select == NULL) | ||
| 5210 | cfsockets_for_select = | ||
| 5211 | CFDictionaryCreateMutable (NULL, 0, NULL, | ||
| 5212 | &kCFTypeDictionaryValueCallBacks); | ||
| 5213 | |||
| 5168 | for (minfd = 1; ; minfd++) /* nfds-1 works as a sentinel. */ | 5214 | for (minfd = 1; ; minfd++) /* nfds-1 works as a sentinel. */ |
| 5169 | if (FD_ISSET (minfd, rfds) || (wfds && FD_ISSET (minfd, wfds))) | 5215 | if (FD_ISSET (minfd, rfds) || (wfds && FD_ISSET (minfd, wfds))) |
| 5170 | break; | 5216 | break; |
| @@ -5176,7 +5222,7 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5176 | CFRunLoopSourceRef source = | 5222 | CFRunLoopSourceRef source = |
| 5177 | (CFRunLoopSourceRef) CFDictionaryGetValue (sources, key); | 5223 | (CFRunLoopSourceRef) CFDictionaryGetValue (sources, key); |
| 5178 | 5224 | ||
| 5179 | if (source == NULL) | 5225 | if (source == NULL || !CFRunLoopSourceIsValid (source)) |
| 5180 | { | 5226 | { |
| 5181 | CFSocketRef socket = | 5227 | CFSocketRef socket = |
| 5182 | CFSocketCreateWithNative (NULL, fd, | 5228 | CFSocketCreateWithNative (NULL, fd, |
| @@ -5186,11 +5232,12 @@ sys_select (nfds, rfds, wfds, efds, timeout) | |||
| 5186 | 5232 | ||
| 5187 | if (socket == NULL) | 5233 | if (socket == NULL) |
| 5188 | continue; | 5234 | continue; |
| 5235 | CFDictionarySetValue (cfsockets_for_select, key, socket); | ||
| 5189 | source = CFSocketCreateRunLoopSource (NULL, socket, 0); | 5236 | source = CFSocketCreateRunLoopSource (NULL, socket, 0); |
| 5190 | CFRelease (socket); | 5237 | CFRelease (socket); |
| 5191 | if (source == NULL) | 5238 | if (source == NULL) |
| 5192 | continue; | 5239 | continue; |
| 5193 | CFDictionaryAddValue (sources, key, source); | 5240 | CFDictionarySetValue (sources, key, source); |
| 5194 | CFRelease (source); | 5241 | CFRelease (source); |
| 5195 | } | 5242 | } |
| 5196 | CFRunLoopAddSource (runloop, source, kCFRunLoopDefaultMode); | 5243 | CFRunLoopAddSource (runloop, source, kCFRunLoopDefaultMode); |