aboutsummaryrefslogtreecommitdiffstats
path: root/src/mac.c
diff options
context:
space:
mode:
authorMiles Bader2007-12-06 00:46:18 +0000
committerMiles Bader2007-12-06 00:46:18 +0000
commite5e76c04310d287a56675876dd83e1089faba215 (patch)
treea4b4f1cc134e4fd5af42671ec6689e07afe48ff2 /src/mac.c
parentb890d447fb56bfe9f2e4742eda4b3ab4b5f4b32a (diff)
parenta2afc99dbad3fa9a3170ad72c578451c3aea58a4 (diff)
downloademacs-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.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/mac.c b/src/mac.c
index 75a606b60b3..9c1a08075f8 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -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. */
5009static CFMutableDictionaryRef cfsockets_for_select;
5010
5007static void 5011static void
5008socket_callback (s, type, address, data, info) 5012socket_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
5101int
5102mac_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
5092int 5133int
5093sys_select (nfds, rfds, wfds, efds, timeout) 5134sys_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);