zeroc-ice 3.6.5 → 3.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (777) hide show
  1. checksums.yaml +5 -5
  2. data/ICE_LICENSE +17 -17
  3. data/LICENSE +12 -12
  4. data/bin/slice2rb +1 -6
  5. data/ext/Communicator.cpp +223 -61
  6. data/ext/Communicator.h +1 -6
  7. data/ext/Config.h +23 -7
  8. data/ext/Connection.cpp +108 -76
  9. data/ext/Connection.h +4 -6
  10. data/ext/Endpoint.cpp +16 -54
  11. data/ext/Endpoint.h +1 -6
  12. data/ext/ImplicitContext.cpp +1 -10
  13. data/ext/ImplicitContext.h +1 -6
  14. data/ext/Init.cpp +4 -6
  15. data/ext/Logger.cpp +1 -6
  16. data/ext/Logger.h +1 -6
  17. data/ext/Operation.cpp +38 -54
  18. data/ext/Operation.h +1 -6
  19. data/ext/Properties.cpp +3 -8
  20. data/ext/Properties.h +1 -6
  21. data/ext/Proxy.cpp +111 -70
  22. data/ext/Proxy.h +1 -6
  23. data/ext/Slice.cpp +5 -20
  24. data/ext/Slice.h +1 -6
  25. data/ext/Types.cpp +313 -224
  26. data/ext/Types.h +118 -71
  27. data/ext/Util.cpp +69 -36
  28. data/ext/Util.h +117 -42
  29. data/ext/ValueFactoryManager.cpp +440 -0
  30. data/ext/ValueFactoryManager.h +95 -0
  31. data/ext/extconf.rb +52 -48
  32. data/ext/ice/cpp/include/Ice/Application.h +275 -105
  33. data/ext/ice/cpp/include/Ice/AsyncResult.h +124 -337
  34. data/ext/ice/cpp/include/Ice/AsyncResultF.h +4 -7
  35. data/ext/ice/cpp/include/Ice/BatchRequestInterceptor.h +39 -16
  36. data/ext/ice/cpp/include/Ice/BatchRequestQueueF.h +1 -6
  37. data/ext/ice/cpp/include/Ice/Buffer.h +10 -15
  38. data/ext/ice/cpp/include/Ice/CommunicatorAsync.h +56 -17
  39. data/ext/ice/cpp/include/Ice/Comparable.h +205 -0
  40. data/ext/ice/cpp/include/Ice/Config.h +16 -39
  41. data/ext/ice/cpp/include/Ice/ConnectionAsync.h +203 -16
  42. data/ext/ice/cpp/include/Ice/ConnectionIF.h +7 -6
  43. data/ext/ice/cpp/include/Ice/ConsoleUtil.h +23 -0
  44. data/ext/ice/cpp/include/Ice/DefaultValueFactory.h +57 -0
  45. data/ext/ice/cpp/include/Ice/DispatchInterceptor.h +20 -12
  46. data/ext/ice/cpp/include/Ice/Dispatcher.h +35 -19
  47. data/ext/ice/cpp/include/Ice/DynamicLibrary.h +7 -10
  48. data/ext/ice/cpp/include/Ice/DynamicLibraryF.h +1 -6
  49. data/ext/ice/cpp/include/Ice/Exception.h +110 -63
  50. data/ext/ice/cpp/include/Ice/ExceptionHelpers.h +74 -0
  51. data/ext/ice/cpp/include/Ice/FactoryTable.h +22 -18
  52. data/ext/ice/cpp/include/Ice/FactoryTableInit.h +28 -31
  53. data/ext/ice/cpp/include/Ice/Format.h +17 -18
  54. data/ext/ice/cpp/include/Ice/Functional.h +38 -38
  55. data/ext/ice/cpp/include/Ice/GCObject.h +9 -10
  56. data/ext/ice/cpp/include/Ice/Handle.h +6 -16
  57. data/ext/ice/cpp/include/Ice/Ice.h +9 -10
  58. data/ext/ice/cpp/include/Ice/IconvStringConverter.h +377 -0
  59. data/ext/ice/cpp/include/Ice/Incoming.h +132 -38
  60. data/ext/ice/cpp/include/Ice/IncomingAsync.h +109 -31
  61. data/ext/ice/cpp/include/Ice/IncomingAsyncF.h +7 -6
  62. data/ext/ice/cpp/include/Ice/Initialize.h +872 -60
  63. data/ext/ice/cpp/include/Ice/InputStream.h +1514 -0
  64. data/ext/ice/cpp/include/Ice/InstanceF.h +1 -7
  65. data/ext/ice/cpp/include/Ice/InterfaceByValue.h +57 -0
  66. data/ext/ice/cpp/include/Ice/LocalObject.h +13 -14
  67. data/ext/ice/cpp/include/Ice/LocalObjectF.h +1 -6
  68. data/ext/ice/cpp/include/Ice/LoggerUtil.h +56 -24
  69. data/ext/ice/cpp/include/Ice/MetricsAdminI.h +124 -71
  70. data/ext/ice/cpp/include/Ice/MetricsFunctional.h +25 -10
  71. data/ext/ice/cpp/include/Ice/MetricsObserverI.h +116 -32
  72. data/ext/ice/cpp/include/Ice/NativePropertiesAdmin.h +61 -30
  73. data/ext/ice/cpp/include/Ice/Object.h +413 -78
  74. data/ext/ice/cpp/include/Ice/ObjectF.h +12 -8
  75. data/ext/ice/cpp/include/Ice/ObserverHelper.h +18 -13
  76. data/ext/ice/cpp/include/Ice/Optional.h +1114 -0
  77. data/ext/ice/cpp/include/Ice/OutgoingAsync.h +684 -89
  78. data/ext/ice/cpp/include/Ice/OutgoingAsyncF.h +12 -11
  79. data/ext/ice/cpp/include/Ice/OutputStream.h +1092 -0
  80. data/ext/ice/cpp/include/Ice/Protocol.h +49 -17
  81. data/ext/ice/cpp/include/Ice/Proxy.h +3438 -745
  82. data/ext/ice/cpp/include/Ice/ProxyF.h +13 -38
  83. data/ext/ice/cpp/include/Ice/ProxyFactoryF.h +1 -6
  84. data/ext/ice/cpp/include/Ice/ProxyHandle.h +43 -55
  85. data/ext/ice/cpp/include/Ice/ReferenceF.h +1 -6
  86. data/ext/ice/cpp/include/Ice/RegisterPlugins.h +84 -12
  87. data/ext/ice/cpp/include/Ice/RequestHandlerF.h +10 -9
  88. data/ext/ice/cpp/include/Ice/ResponseHandlerF.h +6 -6
  89. data/ext/ice/cpp/include/Ice/SHA1.h +42 -0
  90. data/ext/ice/cpp/include/Ice/ServantManagerF.h +1 -6
  91. data/ext/ice/cpp/include/Ice/Service.h +273 -154
  92. data/ext/ice/cpp/include/Ice/SliceChecksums.h +5 -6
  93. data/ext/ice/cpp/include/Ice/SlicedData.h +121 -53
  94. data/ext/ice/cpp/include/Ice/SlicedDataF.h +17 -11
  95. data/ext/ice/cpp/include/Ice/StreamHelpers.h +453 -140
  96. data/ext/ice/cpp/include/Ice/StringConverter.h +78 -0
  97. data/ext/ice/cpp/include/Ice/ThreadPoolF.h +1 -6
  98. data/ext/ice/cpp/include/Ice/UUID.h +19 -0
  99. data/ext/ice/cpp/include/{IceUtil → Ice}/UniquePtr.h +22 -28
  100. data/ext/ice/cpp/include/Ice/UniqueRef.h +97 -0
  101. data/ext/ice/cpp/include/Ice/UserExceptionFactory.h +45 -13
  102. data/ext/ice/cpp/include/Ice/Value.h +139 -0
  103. data/ext/ice/cpp/include/Ice/ValueF.h +21 -0
  104. data/ext/ice/cpp/include/IceSSL/Config.h +8 -28
  105. data/ext/ice/cpp/include/IceSSL/IceSSL.h +17 -11
  106. data/ext/ice/cpp/include/IceSSL/OpenSSL.h +147 -0
  107. data/ext/ice/cpp/include/IceSSL/Plugin.h +461 -448
  108. data/ext/ice/cpp/include/IceSSL/SChannel.h +72 -0
  109. data/ext/ice/cpp/include/IceSSL/SecureTransport.h +72 -0
  110. data/ext/ice/cpp/include/IceSSL/UWP.h +62 -0
  111. data/ext/ice/cpp/include/IceUtil/Atomic.h +7 -14
  112. data/ext/ice/cpp/include/IceUtil/Cond.h +17 -23
  113. data/ext/ice/cpp/include/IceUtil/Config.h +166 -46
  114. data/ext/ice/cpp/include/IceUtil/ConsoleUtil.h +92 -0
  115. data/ext/ice/cpp/include/IceUtil/CountDownLatch.h +5 -10
  116. data/ext/ice/cpp/include/IceUtil/CtrlCHandler.h +63 -41
  117. data/ext/ice/cpp/include/IceUtil/DisableWarnings.h +5 -13
  118. data/ext/ice/cpp/include/IceUtil/Exception.h +284 -75
  119. data/ext/ice/cpp/include/IceUtil/FileUtil.h +143 -0
  120. data/ext/ice/cpp/include/IceUtil/Functional.h +4 -6
  121. data/ext/ice/cpp/include/IceUtil/Handle.h +11 -16
  122. data/ext/ice/cpp/include/IceUtil/IceUtil.h +4 -15
  123. data/ext/ice/cpp/include/IceUtil/InputUtil.h +3 -8
  124. data/ext/ice/cpp/include/IceUtil/Iterator.h +2 -7
  125. data/ext/ice/cpp/include/IceUtil/Lock.h +8 -15
  126. data/ext/ice/cpp/include/IceUtil/Monitor.h +1 -7
  127. data/ext/ice/cpp/include/IceUtil/Mutex.h +19 -23
  128. data/ext/ice/cpp/include/IceUtil/MutexProtocol.h +2 -7
  129. data/ext/ice/cpp/include/IceUtil/MutexPtrLock.h +4 -9
  130. data/ext/ice/cpp/include/IceUtil/MutexPtrTryLock.h +4 -9
  131. data/ext/ice/cpp/include/IceUtil/Optional.h +134 -23
  132. data/ext/ice/cpp/include/IceUtil/Options.h +17 -23
  133. data/ext/ice/cpp/include/IceUtil/OutputUtil.h +61 -37
  134. data/ext/ice/cpp/include/IceUtil/PopDisableWarnings.h +6 -11
  135. data/ext/ice/cpp/include/IceUtil/PushDisableWarnings.h +18 -15
  136. data/ext/ice/cpp/include/IceUtil/Random.h +39 -8
  137. data/ext/ice/cpp/include/IceUtil/RecMutex.h +7 -13
  138. data/ext/ice/cpp/include/IceUtil/ResourceConfig.h +53 -0
  139. data/ext/ice/cpp/include/IceUtil/ScannerConfig.h +10 -15
  140. data/ext/ice/cpp/include/IceUtil/ScopedArray.h +8 -7
  141. data/ext/ice/cpp/include/IceUtil/Shared.h +5 -12
  142. data/ext/ice/cpp/{src → include}/IceUtil/StopWatch.h +2 -7
  143. data/ext/ice/cpp/include/IceUtil/StringConverter.h +146 -126
  144. data/ext/ice/cpp/include/IceUtil/StringUtil.h +32 -26
  145. data/ext/ice/cpp/include/IceUtil/Thread.h +10 -17
  146. data/ext/ice/cpp/include/IceUtil/ThreadException.h +33 -47
  147. data/ext/ice/cpp/include/IceUtil/Time.h +3 -8
  148. data/ext/ice/cpp/include/IceUtil/Timer.h +18 -18
  149. data/ext/ice/cpp/include/IceUtil/UUID.h +6 -7
  150. data/ext/ice/cpp/include/IceUtil/UndefSysMacros.h +1 -6
  151. data/ext/ice/cpp/include/generated/Ice/BuiltinSequences.h +170 -0
  152. data/ext/ice/cpp/include/generated/Ice/Communicator.h +1156 -0
  153. data/ext/ice/cpp/include/{Ice → generated/Ice}/CommunicatorF.h +51 -16
  154. data/ext/ice/cpp/include/generated/Ice/Connection.h +1660 -0
  155. data/ext/ice/cpp/include/generated/Ice/ConnectionF.h +119 -0
  156. data/ext/ice/cpp/include/generated/Ice/Current.h +322 -0
  157. data/ext/ice/cpp/include/generated/Ice/Endpoint.h +943 -0
  158. data/ext/ice/cpp/include/generated/Ice/EndpointF.h +166 -0
  159. data/ext/ice/cpp/include/generated/Ice/EndpointTypes.h +118 -0
  160. data/ext/ice/cpp/include/{Ice → generated/Ice}/FacetMap.h +31 -15
  161. data/ext/ice/cpp/include/generated/Ice/Identity.h +264 -0
  162. data/ext/ice/cpp/include/generated/Ice/ImplicitContext.h +278 -0
  163. data/ext/ice/cpp/include/{Ice → generated/Ice}/ImplicitContextF.h +51 -16
  164. data/ext/ice/cpp/include/generated/Ice/Instrumentation.h +1143 -0
  165. data/ext/ice/cpp/include/generated/Ice/InstrumentationF.h +128 -0
  166. data/ext/ice/cpp/include/generated/Ice/LocalException.h +7041 -0
  167. data/ext/ice/cpp/include/generated/Ice/Locator.h +3850 -0
  168. data/ext/ice/cpp/include/generated/Ice/LocatorF.h +147 -0
  169. data/ext/ice/cpp/include/generated/Ice/Logger.h +231 -0
  170. data/ext/ice/cpp/include/{Ice → generated/Ice}/LoggerF.h +51 -16
  171. data/ext/ice/cpp/include/generated/Ice/Metrics.h +4717 -0
  172. data/ext/ice/cpp/include/generated/Ice/ObjectAdapter.h +1175 -0
  173. data/ext/ice/cpp/include/{Ice → generated/Ice}/ObjectAdapterF.h +51 -16
  174. data/ext/ice/cpp/include/generated/Ice/ObjectFactory.h +197 -0
  175. data/ext/ice/cpp/include/generated/Ice/Plugin.h +306 -0
  176. data/ext/ice/cpp/include/generated/Ice/PluginF.h +110 -0
  177. data/ext/ice/cpp/include/generated/Ice/Process.h +971 -0
  178. data/ext/ice/cpp/include/generated/Ice/ProcessF.h +125 -0
  179. data/ext/ice/cpp/include/generated/Ice/Properties.h +446 -0
  180. data/ext/ice/cpp/include/generated/Ice/PropertiesAdmin.h +1360 -0
  181. data/ext/ice/cpp/include/generated/Ice/PropertiesF.h +134 -0
  182. data/ext/ice/cpp/include/generated/Ice/RemoteLogger.h +2689 -0
  183. data/ext/ice/cpp/include/generated/Ice/Router.h +1838 -0
  184. data/ext/ice/cpp/include/generated/Ice/RouterF.h +125 -0
  185. data/ext/ice/cpp/include/generated/Ice/ServantLocator.h +299 -0
  186. data/ext/ice/cpp/include/{Ice → generated/Ice}/ServantLocatorF.h +51 -16
  187. data/ext/ice/cpp/include/{Ice → generated/Ice}/SliceChecksumDict.h +34 -14
  188. data/ext/ice/cpp/include/generated/Ice/ValueFactory.h +318 -0
  189. data/ext/ice/cpp/include/generated/Ice/Version.h +357 -0
  190. data/ext/ice/cpp/include/generated/IceSSL/ConnectionInfo.h +223 -0
  191. data/ext/ice/cpp/include/generated/IceSSL/ConnectionInfoF.h +101 -0
  192. data/ext/ice/cpp/include/generated/IceSSL/EndpointInfo.h +181 -0
  193. data/ext/ice/cpp/src/Ice/ACM.cpp +38 -27
  194. data/ext/ice/cpp/src/Ice/ACM.h +9 -7
  195. data/ext/ice/cpp/src/Ice/ACMF.h +30 -0
  196. data/ext/ice/cpp/src/Ice/Acceptor.cpp +6 -6
  197. data/ext/ice/cpp/src/Ice/Acceptor.h +4 -8
  198. data/ext/ice/cpp/src/Ice/AcceptorF.h +1 -6
  199. data/ext/ice/cpp/src/Ice/ArgVector.cpp +59 -0
  200. data/ext/ice/cpp/src/Ice/ArgVector.h +36 -0
  201. data/ext/ice/cpp/src/Ice/AsyncResult.cpp +15 -544
  202. data/ext/ice/cpp/src/Ice/Base64.cpp +22 -28
  203. data/ext/ice/cpp/src/Ice/Base64.h +1 -6
  204. data/ext/ice/cpp/src/Ice/BatchRequestQueue.cpp +41 -18
  205. data/ext/ice/cpp/src/Ice/BatchRequestQueue.h +15 -15
  206. data/ext/ice/cpp/src/Ice/Buffer.cpp +75 -18
  207. data/ext/ice/cpp/src/Ice/BuiltinSequences.cpp +21 -12
  208. data/ext/ice/cpp/src/Ice/CollocatedRequestHandler.cpp +86 -197
  209. data/ext/ice/cpp/src/Ice/CollocatedRequestHandler.h +17 -23
  210. data/ext/ice/cpp/src/Ice/Communicator.cpp +43 -15
  211. data/ext/ice/cpp/src/Ice/CommunicatorF.cpp +28 -11
  212. data/ext/ice/cpp/src/Ice/CommunicatorI.cpp +318 -117
  213. data/ext/ice/cpp/src/Ice/CommunicatorI.h +95 -40
  214. data/ext/ice/cpp/src/{IceUtil → Ice}/Cond.cpp +3 -8
  215. data/ext/ice/cpp/src/Ice/ConnectRequestHandler.cpp +55 -122
  216. data/ext/ice/cpp/src/Ice/ConnectRequestHandler.h +15 -31
  217. data/ext/ice/cpp/src/Ice/ConnectRequestHandlerF.h +6 -7
  218. data/ext/ice/cpp/src/Ice/Connection.cpp +111 -20
  219. data/ext/ice/cpp/src/Ice/ConnectionF.cpp +28 -11
  220. data/ext/ice/cpp/src/Ice/ConnectionFactory.cpp +300 -107
  221. data/ext/ice/cpp/src/Ice/ConnectionFactory.h +44 -28
  222. data/ext/ice/cpp/src/Ice/ConnectionFactoryF.h +30 -0
  223. data/ext/ice/cpp/src/Ice/ConnectionI.cpp +785 -713
  224. data/ext/ice/cpp/src/Ice/ConnectionI.h +105 -80
  225. data/ext/ice/cpp/src/Ice/ConnectionRequestHandler.cpp +2 -20
  226. data/ext/ice/cpp/src/Ice/ConnectionRequestHandler.h +5 -9
  227. data/ext/ice/cpp/src/Ice/Connector.cpp +6 -6
  228. data/ext/ice/cpp/src/Ice/Connector.h +4 -8
  229. data/ext/ice/cpp/src/Ice/ConnectorF.h +1 -6
  230. data/ext/ice/cpp/src/{IceUtil → Ice}/CountDownLatch.cpp +4 -9
  231. data/ext/ice/cpp/src/Ice/Current.cpp +30 -12
  232. data/ext/ice/cpp/src/Ice/DefaultsAndOverrides.cpp +10 -16
  233. data/ext/ice/cpp/src/Ice/DefaultsAndOverrides.h +1 -6
  234. data/ext/ice/cpp/src/Ice/DefaultsAndOverridesF.h +1 -6
  235. data/ext/ice/cpp/src/Ice/DispatchInterceptor.cpp +13 -25
  236. data/ext/ice/cpp/src/Ice/DynamicLibrary.cpp +34 -28
  237. data/ext/ice/cpp/src/Ice/Endpoint.cpp +107 -19
  238. data/ext/ice/cpp/src/Ice/EndpointF.cpp +28 -11
  239. data/ext/ice/cpp/src/Ice/EndpointFactory.cpp +152 -6
  240. data/ext/ice/cpp/src/Ice/EndpointFactory.h +72 -11
  241. data/ext/ice/cpp/src/Ice/EndpointFactoryF.h +1 -6
  242. data/ext/ice/cpp/src/Ice/EndpointFactoryManager.cpp +41 -36
  243. data/ext/ice/cpp/src/Ice/EndpointFactoryManager.h +10 -9
  244. data/ext/ice/cpp/src/Ice/EndpointFactoryManagerF.h +1 -6
  245. data/ext/ice/cpp/src/Ice/EndpointI.cpp +18 -7
  246. data/ext/ice/cpp/src/Ice/EndpointI.h +39 -18
  247. data/ext/ice/cpp/src/Ice/EndpointIF.h +18 -10
  248. data/ext/ice/cpp/src/Ice/EndpointTypes.cpp +19 -12
  249. data/ext/ice/cpp/src/Ice/EventHandler.cpp +6 -9
  250. data/ext/ice/cpp/src/Ice/EventHandler.h +13 -13
  251. data/ext/ice/cpp/src/Ice/EventHandlerF.h +5 -7
  252. data/ext/ice/cpp/src/Ice/Exception.cpp +102 -98
  253. data/ext/ice/cpp/src/Ice/FacetMap.cpp +21 -12
  254. data/ext/ice/cpp/src/Ice/FactoryTable.cpp +37 -33
  255. data/ext/ice/cpp/src/Ice/FactoryTableInit.cpp +2 -9
  256. data/ext/ice/cpp/src/Ice/GCObject.cpp +29 -31
  257. data/ext/ice/cpp/src/Ice/HashUtil.h +3 -9
  258. data/ext/ice/cpp/src/Ice/HttpParser.cpp +1 -7
  259. data/ext/ice/cpp/src/Ice/HttpParser.h +1 -6
  260. data/ext/ice/cpp/src/Ice/IPEndpointI.cpp +128 -111
  261. data/ext/ice/cpp/src/Ice/IPEndpointI.h +23 -19
  262. data/ext/ice/cpp/src/Ice/IPEndpointIF.h +6 -7
  263. data/ext/ice/cpp/src/Ice/IconvStringConverter.cpp +51 -0
  264. data/ext/ice/cpp/src/Ice/Identity.cpp +25 -16
  265. data/ext/ice/cpp/src/Ice/ImplicitContext.cpp +41 -13
  266. data/ext/ice/cpp/src/Ice/ImplicitContextF.cpp +28 -11
  267. data/ext/ice/cpp/src/Ice/ImplicitContextI.cpp +11 -28
  268. data/ext/ice/cpp/src/Ice/ImplicitContextI.h +7 -10
  269. data/ext/ice/cpp/src/Ice/Incoming.cpp +284 -255
  270. data/ext/ice/cpp/src/Ice/IncomingAsync.cpp +104 -214
  271. data/ext/ice/cpp/src/Ice/IncomingRequest.h +5 -9
  272. data/ext/ice/cpp/src/Ice/Initialize.cpp +309 -193
  273. data/ext/ice/cpp/src/Ice/InputStream.cpp +2726 -0
  274. data/ext/ice/cpp/src/Ice/Instance.cpp +243 -262
  275. data/ext/ice/cpp/src/Ice/Instance.h +30 -23
  276. data/ext/ice/cpp/src/Ice/Instrumentation.cpp +137 -23
  277. data/ext/ice/cpp/src/Ice/InstrumentationF.cpp +28 -11
  278. data/ext/ice/cpp/src/Ice/InstrumentationI.cpp +118 -105
  279. data/ext/ice/cpp/src/Ice/InstrumentationI.h +30 -36
  280. data/ext/ice/cpp/src/Ice/LocalException.cpp +1191 -422
  281. data/ext/ice/cpp/src/Ice/LocalObject.cpp +1 -7
  282. data/ext/ice/cpp/src/Ice/Locator.cpp +1282 -1222
  283. data/ext/ice/cpp/src/Ice/LocatorF.cpp +30 -12
  284. data/ext/ice/cpp/src/Ice/LocatorInfo.cpp +150 -186
  285. data/ext/ice/cpp/src/Ice/LocatorInfo.h +31 -36
  286. data/ext/ice/cpp/src/Ice/LocatorInfoF.h +1 -6
  287. data/ext/ice/cpp/src/Ice/Logger.cpp +39 -12
  288. data/ext/ice/cpp/src/Ice/LoggerAdminI.cpp +182 -88
  289. data/ext/ice/cpp/src/Ice/LoggerAdminI.h +4 -9
  290. data/ext/ice/cpp/src/Ice/LoggerF.cpp +28 -11
  291. data/ext/ice/cpp/src/Ice/LoggerI.cpp +26 -55
  292. data/ext/ice/cpp/src/Ice/LoggerI.h +7 -18
  293. data/ext/ice/cpp/src/Ice/LoggerUtil.cpp +10 -17
  294. data/ext/ice/cpp/src/Ice/Metrics.cpp +1280 -1107
  295. data/ext/ice/cpp/src/Ice/MetricsAdminI.cpp +58 -33
  296. data/ext/ice/cpp/src/Ice/MetricsObserverI.cpp +1 -7
  297. data/ext/ice/cpp/src/Ice/Network.cpp +753 -408
  298. data/ext/ice/cpp/src/Ice/Network.h +99 -36
  299. data/ext/ice/cpp/src/Ice/NetworkF.h +2 -7
  300. data/ext/ice/cpp/src/Ice/NetworkProxy.cpp +20 -19
  301. data/ext/ice/cpp/src/Ice/NetworkProxy.h +5 -7
  302. data/ext/ice/cpp/src/Ice/NetworkProxyF.h +1 -6
  303. data/ext/ice/cpp/src/Ice/OSLogLoggerI.cpp +57 -0
  304. data/ext/ice/cpp/src/Ice/OSLogLoggerI.h +40 -0
  305. data/ext/ice/cpp/src/Ice/Object.cpp +227 -232
  306. data/ext/ice/cpp/src/Ice/ObjectAdapter.cpp +45 -13
  307. data/ext/ice/cpp/src/Ice/ObjectAdapterF.cpp +28 -11
  308. data/ext/ice/cpp/src/Ice/ObjectAdapterFactory.cpp +83 -33
  309. data/ext/ice/cpp/src/Ice/ObjectAdapterFactory.h +13 -12
  310. data/ext/ice/cpp/src/Ice/ObjectAdapterFactoryF.h +25 -0
  311. data/ext/ice/cpp/src/Ice/ObjectAdapterI.cpp +298 -191
  312. data/ext/ice/cpp/src/Ice/ObjectAdapterI.h +44 -39
  313. data/ext/ice/cpp/src/Ice/ObjectFactory.cpp +41 -13
  314. data/ext/ice/cpp/src/Ice/ObserverHelper.cpp +9 -37
  315. data/ext/ice/cpp/src/Ice/OpaqueEndpointI.cpp +67 -67
  316. data/ext/ice/cpp/src/Ice/OpaqueEndpointI.h +15 -11
  317. data/ext/ice/cpp/src/Ice/OutgoingAsync.cpp +801 -366
  318. data/ext/ice/cpp/src/Ice/OutputStream.cpp +1367 -0
  319. data/ext/ice/cpp/src/Ice/Plugin.cpp +52 -14
  320. data/ext/ice/cpp/src/Ice/PluginF.cpp +28 -11
  321. data/ext/ice/cpp/src/Ice/PluginManagerI.cpp +27 -51
  322. data/ext/ice/cpp/src/Ice/PluginManagerI.h +7 -13
  323. data/ext/ice/cpp/src/Ice/Process.cpp +294 -128
  324. data/ext/ice/cpp/src/Ice/ProcessF.cpp +30 -12
  325. data/ext/ice/cpp/src/Ice/Properties.cpp +42 -15
  326. data/ext/ice/cpp/src/Ice/PropertiesAdmin.cpp +382 -340
  327. data/ext/ice/cpp/src/Ice/PropertiesAdminI.cpp +83 -24
  328. data/ext/ice/cpp/src/Ice/PropertiesAdminI.h +29 -10
  329. data/ext/ice/cpp/src/Ice/PropertiesF.cpp +30 -12
  330. data/ext/ice/cpp/src/Ice/PropertiesI.cpp +46 -57
  331. data/ext/ice/cpp/src/Ice/PropertiesI.h +18 -26
  332. data/ext/ice/cpp/src/Ice/PropertyNames.cpp +112 -19
  333. data/ext/ice/cpp/src/Ice/PropertyNames.h +4 -7
  334. data/ext/ice/cpp/src/Ice/Protocol.cpp +6 -19
  335. data/ext/ice/cpp/src/Ice/ProtocolInstance.cpp +37 -7
  336. data/ext/ice/cpp/src/Ice/ProtocolInstance.h +9 -25
  337. data/ext/ice/cpp/src/Ice/ProtocolInstanceF.h +1 -6
  338. data/ext/ice/cpp/src/Ice/ProtocolPluginFacade.cpp +6 -6
  339. data/ext/ice/cpp/src/Ice/ProtocolPluginFacade.h +3 -6
  340. data/ext/ice/cpp/src/Ice/ProtocolPluginFacadeF.h +1 -6
  341. data/ext/ice/cpp/src/Ice/Proxy.cpp +729 -957
  342. data/ext/ice/cpp/src/Ice/ProxyFactory.cpp +33 -38
  343. data/ext/ice/cpp/src/Ice/ProxyFactory.h +16 -16
  344. data/ext/ice/cpp/src/Ice/Reference.cpp +190 -106
  345. data/ext/ice/cpp/src/Ice/Reference.h +39 -28
  346. data/ext/ice/cpp/src/Ice/ReferenceFactory.cpp +69 -118
  347. data/ext/ice/cpp/src/Ice/ReferenceFactory.h +12 -17
  348. data/ext/ice/cpp/src/Ice/ReferenceFactoryF.h +1 -6
  349. data/ext/ice/cpp/src/Ice/RegisterPluginsInit.cpp +19 -9
  350. data/ext/ice/cpp/src/Ice/RegisterPluginsInit.h +1 -6
  351. data/ext/ice/cpp/src/Ice/RemoteLogger.cpp +766 -565
  352. data/ext/ice/cpp/src/Ice/ReplyStatus.h +1 -6
  353. data/ext/ice/cpp/src/Ice/RequestHandler.cpp +5 -8
  354. data/ext/ice/cpp/src/Ice/RequestHandler.h +10 -18
  355. data/ext/ice/cpp/src/Ice/RequestHandlerFactory.cpp +10 -11
  356. data/ext/ice/cpp/src/Ice/RequestHandlerFactory.h +2 -7
  357. data/ext/ice/cpp/src/Ice/ResponseHandler.cpp +3 -11
  358. data/ext/ice/cpp/src/Ice/ResponseHandler.h +16 -12
  359. data/ext/ice/cpp/src/Ice/RetryQueue.cpp +12 -20
  360. data/ext/ice/cpp/src/Ice/RetryQueue.h +7 -11
  361. data/ext/ice/cpp/src/Ice/RetryQueueF.h +1 -6
  362. data/ext/ice/cpp/src/Ice/Router.cpp +614 -492
  363. data/ext/ice/cpp/src/Ice/RouterF.cpp +30 -12
  364. data/ext/ice/cpp/src/Ice/RouterInfo.cpp +93 -99
  365. data/ext/ice/cpp/src/Ice/RouterInfo.h +42 -38
  366. data/ext/ice/cpp/src/Ice/RouterInfoF.h +1 -6
  367. data/ext/ice/cpp/src/{IceUtil → Ice}/SHA1.cpp +23 -28
  368. data/ext/ice/cpp/src/Ice/Selector.cpp +948 -855
  369. data/ext/ice/cpp/src/Ice/Selector.h +100 -152
  370. data/ext/ice/cpp/src/Ice/ServantLocator.cpp +41 -13
  371. data/ext/ice/cpp/src/Ice/ServantLocatorF.cpp +28 -11
  372. data/ext/ice/cpp/src/Ice/ServantManager.cpp +24 -45
  373. data/ext/ice/cpp/src/Ice/ServantManager.h +1 -6
  374. data/ext/ice/cpp/src/Ice/SharedContext.h +2 -7
  375. data/ext/ice/cpp/src/Ice/SliceChecksumDict.cpp +21 -12
  376. data/ext/ice/cpp/src/Ice/SliceChecksums.cpp +2 -7
  377. data/ext/ice/cpp/src/Ice/SlicedData.cpp +72 -25
  378. data/ext/ice/cpp/src/Ice/StreamSocket.cpp +208 -76
  379. data/ext/ice/cpp/src/Ice/StreamSocket.h +13 -9
  380. data/ext/ice/cpp/src/Ice/StringConverterPlugin.cpp +57 -22
  381. data/ext/ice/cpp/src/Ice/StringUtil.h +30 -0
  382. data/ext/ice/cpp/src/Ice/SysLoggerI.cpp +6 -7
  383. data/ext/ice/cpp/src/Ice/SysLoggerI.h +2 -8
  384. data/ext/ice/cpp/src/Ice/SystemdJournalI.cpp +66 -0
  385. data/ext/ice/cpp/src/Ice/SystemdJournalI.h +39 -0
  386. data/ext/ice/cpp/src/Ice/TcpAcceptor.cpp +169 -49
  387. data/ext/ice/cpp/src/Ice/TcpAcceptor.h +12 -10
  388. data/ext/ice/cpp/src/Ice/TcpConnector.cpp +6 -12
  389. data/ext/ice/cpp/src/Ice/TcpConnector.h +1 -7
  390. data/ext/ice/cpp/src/Ice/TcpEndpointI.cpp +51 -46
  391. data/ext/ice/cpp/src/Ice/TcpEndpointI.h +12 -14
  392. data/ext/ice/cpp/src/Ice/TcpTransceiver.cpp +17 -32
  393. data/ext/ice/cpp/src/Ice/TcpTransceiver.h +7 -15
  394. data/ext/ice/cpp/src/{IceUtil → Ice}/Thread.cpp +41 -54
  395. data/ext/ice/cpp/src/Ice/ThreadPool.cpp +242 -274
  396. data/ext/ice/cpp/src/Ice/ThreadPool.h +46 -48
  397. data/ext/ice/cpp/src/{IceUtil → Ice}/Timer.cpp +38 -26
  398. data/ext/ice/cpp/src/Ice/TraceLevels.cpp +2 -7
  399. data/ext/ice/cpp/src/Ice/TraceLevels.h +1 -6
  400. data/ext/ice/cpp/src/Ice/TraceLevelsF.h +2 -7
  401. data/ext/ice/cpp/src/Ice/TraceUtil.cpp +53 -36
  402. data/ext/ice/cpp/src/Ice/TraceUtil.h +13 -11
  403. data/ext/ice/cpp/src/Ice/Transceiver.cpp +1 -7
  404. data/ext/ice/cpp/src/Ice/Transceiver.h +8 -12
  405. data/ext/ice/cpp/src/Ice/TransceiverF.h +3 -8
  406. data/ext/ice/cpp/src/Ice/UdpConnector.cpp +5 -13
  407. data/ext/ice/cpp/src/Ice/UdpConnector.h +1 -7
  408. data/ext/ice/cpp/src/Ice/UdpEndpointI.cpp +118 -60
  409. data/ext/ice/cpp/src/Ice/UdpEndpointI.h +13 -10
  410. data/ext/ice/cpp/src/Ice/UdpTransceiver.cpp +177 -236
  411. data/ext/ice/cpp/src/Ice/UdpTransceiver.h +15 -22
  412. data/ext/ice/cpp/src/Ice/Value.cpp +76 -0
  413. data/ext/ice/cpp/src/Ice/ValueFactory.cpp +83 -0
  414. data/ext/ice/cpp/src/Ice/ValueFactoryManagerI.cpp +61 -0
  415. data/ext/ice/cpp/src/Ice/ValueFactoryManagerI.h +37 -0
  416. data/ext/ice/cpp/src/Ice/Version.cpp +25 -20
  417. data/ext/ice/cpp/src/Ice/VirtualShared.h +38 -0
  418. data/ext/ice/cpp/src/Ice/WSAcceptor.cpp +3 -14
  419. data/ext/ice/cpp/src/Ice/WSAcceptor.h +3 -12
  420. data/ext/ice/cpp/src/Ice/WSConnector.cpp +5 -16
  421. data/ext/ice/cpp/src/Ice/WSConnector.h +3 -11
  422. data/ext/ice/cpp/src/Ice/WSEndpoint.cpp +188 -89
  423. data/ext/ice/cpp/src/Ice/WSEndpoint.h +22 -37
  424. data/ext/ice/cpp/src/Ice/WSTransceiver.cpp +65 -66
  425. data/ext/ice/cpp/src/Ice/WSTransceiver.h +7 -27
  426. data/ext/ice/cpp/src/IceDiscovery/IceDiscovery.cpp +596 -281
  427. data/ext/ice/cpp/src/IceDiscovery/IceDiscovery.h +1383 -543
  428. data/ext/ice/cpp/src/IceDiscovery/LocatorI.cpp +89 -32
  429. data/ext/ice/cpp/src/IceDiscovery/LocatorI.h +59 -28
  430. data/ext/ice/cpp/src/IceDiscovery/LookupI.cpp +315 -66
  431. data/ext/ice/cpp/src/IceDiscovery/LookupI.h +83 -41
  432. data/ext/ice/cpp/src/IceDiscovery/PluginI.cpp +57 -64
  433. data/ext/ice/cpp/src/IceDiscovery/PluginI.h +3 -8
  434. data/ext/ice/cpp/src/IceLocatorDiscovery/IceLocatorDiscovery.cpp +450 -172
  435. data/ext/ice/cpp/src/IceLocatorDiscovery/IceLocatorDiscovery.h +863 -406
  436. data/ext/ice/cpp/src/IceLocatorDiscovery/Plugin.h +47 -0
  437. data/ext/ice/cpp/src/IceLocatorDiscovery/PluginI.cpp +636 -144
  438. data/ext/ice/cpp/src/IceSSL/AcceptorI.cpp +20 -173
  439. data/ext/ice/cpp/src/IceSSL/AcceptorI.h +8 -22
  440. data/ext/ice/cpp/src/IceSSL/CertificateI.cpp +279 -0
  441. data/ext/ice/cpp/src/IceSSL/CertificateI.h +64 -0
  442. data/ext/ice/cpp/src/IceSSL/ConnectionInfo.cpp +42 -17
  443. data/ext/ice/cpp/src/IceSSL/ConnectionInfoF.cpp +61 -0
  444. data/ext/ice/cpp/src/IceSSL/ConnectorI.cpp +15 -64
  445. data/ext/ice/cpp/src/IceSSL/ConnectorI.h +6 -18
  446. data/ext/ice/cpp/src/IceSSL/EndpointI.cpp +207 -204
  447. data/ext/ice/cpp/src/IceSSL/EndpointI.h +43 -40
  448. data/ext/ice/cpp/src/IceSSL/EndpointInfo.cpp +42 -16
  449. data/ext/ice/cpp/src/IceSSL/Instance.cpp +1 -11
  450. data/ext/ice/cpp/src/IceSSL/Instance.h +7 -12
  451. data/ext/ice/cpp/src/IceSSL/InstanceF.h +11 -12
  452. data/ext/ice/cpp/src/IceSSL/OpenSSLCertificateI.cpp +583 -0
  453. data/ext/ice/cpp/src/IceSSL/OpenSSLEngine.cpp +134 -115
  454. data/ext/ice/cpp/src/IceSSL/OpenSSLEngine.h +59 -0
  455. data/ext/ice/cpp/src/IceSSL/OpenSSLEngineF.h +27 -0
  456. data/ext/ice/cpp/src/IceSSL/OpenSSLPluginI.cpp +127 -0
  457. data/ext/ice/cpp/src/IceSSL/OpenSSLTransceiverI.cpp +477 -182
  458. data/ext/ice/cpp/src/IceSSL/OpenSSLTransceiverI.h +32 -26
  459. data/ext/ice/cpp/src/IceSSL/OpenSSLUtil.cpp +286 -0
  460. data/ext/ice/cpp/src/IceSSL/OpenSSLUtil.h +58 -0
  461. data/ext/ice/cpp/src/IceSSL/PluginI.cpp +71 -46
  462. data/ext/ice/cpp/src/IceSSL/PluginI.h +13 -23
  463. data/ext/ice/cpp/src/IceSSL/RFC2253.cpp +9 -60
  464. data/ext/ice/cpp/src/IceSSL/RFC2253.h +7 -12
  465. data/ext/ice/cpp/src/IceSSL/SChannelCertificateI.cpp +580 -0
  466. data/ext/ice/cpp/src/IceSSL/SChannelEngine.cpp +523 -74
  467. data/ext/ice/cpp/src/IceSSL/SChannelEngine.h +123 -0
  468. data/ext/ice/cpp/src/IceSSL/SChannelEngineF.h +31 -0
  469. data/ext/ice/cpp/src/IceSSL/SChannelPluginI.cpp +73 -0
  470. data/ext/ice/cpp/src/IceSSL/SChannelTransceiverI.cpp +187 -221
  471. data/ext/ice/cpp/src/IceSSL/SChannelTransceiverI.h +24 -26
  472. data/ext/ice/cpp/src/IceSSL/SSLEngine.cpp +97 -94
  473. data/ext/ice/cpp/src/IceSSL/SSLEngine.h +26 -192
  474. data/ext/ice/cpp/src/IceSSL/SSLEngineF.h +4 -24
  475. data/ext/ice/cpp/src/IceSSL/SecureTransportCertificateI.cpp +868 -0
  476. data/ext/ice/cpp/src/IceSSL/SecureTransportEngine.cpp +69 -201
  477. data/ext/ice/cpp/src/IceSSL/SecureTransportEngine.h +59 -0
  478. data/ext/ice/cpp/src/IceSSL/SecureTransportEngineF.h +29 -0
  479. data/ext/ice/cpp/src/IceSSL/SecureTransportPluginI.cpp +75 -0
  480. data/ext/ice/cpp/src/IceSSL/SecureTransportTransceiverI.cpp +174 -161
  481. data/ext/ice/cpp/src/IceSSL/SecureTransportTransceiverI.h +29 -33
  482. data/ext/ice/cpp/src/IceSSL/SecureTransportUtil.cpp +864 -0
  483. data/ext/ice/cpp/src/IceSSL/SecureTransportUtil.h +45 -0
  484. data/ext/ice/cpp/src/IceSSL/TrustManager.cpp +12 -22
  485. data/ext/ice/cpp/src/IceSSL/TrustManager.h +4 -9
  486. data/ext/ice/cpp/src/IceSSL/TrustManagerF.h +3 -8
  487. data/ext/ice/cpp/src/IceSSL/UWPCertificateI.cpp +266 -0
  488. data/ext/ice/cpp/src/IceSSL/UWPEngine.cpp +338 -0
  489. data/ext/ice/cpp/src/IceSSL/UWPEngine.h +41 -0
  490. data/ext/ice/cpp/src/IceSSL/UWPEngineF.h +26 -0
  491. data/ext/ice/cpp/src/IceSSL/UWPPluginI.cpp +89 -0
  492. data/ext/ice/cpp/src/IceSSL/UWPTransceiverI.cpp +383 -0
  493. data/ext/ice/cpp/src/IceSSL/UWPTransceiverI.h +71 -0
  494. data/ext/ice/cpp/src/IceSSL/Util.cpp +71 -1260
  495. data/ext/ice/cpp/src/IceSSL/Util.h +48 -142
  496. data/ext/ice/cpp/src/IceUtil/ConsoleUtil.cpp +157 -0
  497. data/ext/ice/cpp/src/IceUtil/ConvertUTF.cpp +22 -27
  498. data/ext/ice/cpp/src/IceUtil/ConvertUTF.h +34 -31
  499. data/ext/ice/cpp/src/IceUtil/CtrlCHandler.cpp +22 -36
  500. data/ext/ice/cpp/src/IceUtil/FileUtil.cpp +30 -126
  501. data/ext/ice/cpp/src/IceUtil/InputUtil.cpp +1 -6
  502. data/ext/ice/cpp/src/IceUtil/MutexProtocol.cpp +1 -6
  503. data/ext/ice/cpp/src/IceUtil/Options.cpp +20 -33
  504. data/ext/ice/cpp/src/IceUtil/OutputUtil.cpp +47 -21
  505. data/ext/ice/cpp/src/IceUtil/Random.cpp +15 -20
  506. data/ext/ice/cpp/src/IceUtil/RecMutex.cpp +4 -19
  507. data/ext/ice/cpp/src/IceUtil/Shared.cpp +8 -8
  508. data/ext/ice/cpp/src/IceUtil/StringConverter.cpp +501 -269
  509. data/ext/ice/cpp/src/IceUtil/StringUtil.cpp +582 -244
  510. data/ext/ice/cpp/src/IceUtil/ThreadException.cpp +37 -79
  511. data/ext/ice/cpp/src/IceUtil/Time.cpp +6 -11
  512. data/ext/ice/cpp/src/IceUtil/UUID.cpp +17 -22
  513. data/ext/ice/cpp/src/IceUtil/Unicode.cpp +97 -101
  514. data/ext/ice/cpp/src/IceUtil/Unicode.h +21 -40
  515. data/ext/ice/cpp/src/IceUtil/UtilException.cpp +839 -0
  516. data/ext/ice/cpp/src/Slice/CPlusPlusUtil.cpp +894 -234
  517. data/ext/ice/cpp/src/Slice/CPlusPlusUtil.h +72 -0
  518. data/ext/ice/cpp/src/Slice/Checksum.cpp +2 -7
  519. data/ext/ice/cpp/src/Slice/Checksum.h +21 -0
  520. data/ext/ice/cpp/src/Slice/FileTracker.cpp +25 -83
  521. data/ext/ice/cpp/{include → src}/Slice/FileTracker.h +9 -14
  522. data/ext/ice/cpp/src/Slice/Grammar.cpp +1981 -1944
  523. data/ext/ice/cpp/src/Slice/Grammar.h +39 -19
  524. data/ext/ice/cpp/src/Slice/GrammarUtil.h +14 -20
  525. data/ext/ice/cpp/src/Slice/JavaUtil.cpp +2752 -1948
  526. data/ext/ice/cpp/src/Slice/JavaUtil.h +398 -0
  527. data/ext/ice/cpp/src/Slice/MD5.cpp +1 -6
  528. data/ext/ice/cpp/src/Slice/MD5.h +1 -6
  529. data/ext/ice/cpp/src/Slice/MD5I.cpp +8 -1
  530. data/ext/ice/cpp/src/Slice/MD5I.h +1 -1
  531. data/ext/ice/cpp/src/Slice/PHPUtil.cpp +17 -20
  532. data/ext/ice/cpp/src/Slice/PHPUtil.h +36 -0
  533. data/ext/ice/cpp/src/Slice/Parser.cpp +1190 -426
  534. data/ext/ice/cpp/{include → src}/Slice/Parser.h +143 -91
  535. data/ext/ice/cpp/src/Slice/Preprocessor.cpp +67 -36
  536. data/ext/ice/cpp/{include → src}/Slice/Preprocessor.h +8 -18
  537. data/ext/ice/cpp/src/Slice/Python.cpp +218 -111
  538. data/ext/ice/cpp/src/Slice/PythonUtil.cpp +787 -699
  539. data/ext/ice/cpp/src/Slice/PythonUtil.h +70 -0
  540. data/ext/ice/cpp/src/Slice/Ruby.cpp +42 -43
  541. data/ext/ice/cpp/src/Slice/RubyUtil.cpp +175 -445
  542. data/ext/ice/cpp/{include → src}/Slice/RubyUtil.h +6 -11
  543. data/ext/ice/cpp/src/Slice/Scanner.cpp +390 -399
  544. data/ext/ice/cpp/src/Slice/{Util.cpp → SliceUtil.cpp} +36 -69
  545. data/ext/ice/cpp/src/Slice/StringLiteralUtil.cpp +456 -0
  546. data/ext/ice/cpp/src/Slice/Util.h +50 -0
  547. data/ice.gemspec +2 -9
  548. data/lib/Glacier2.rb +1 -6
  549. data/lib/Glacier2/Metrics.rb +6 -50
  550. data/lib/Glacier2/PermissionsVerifier.rb +23 -99
  551. data/lib/Glacier2/PermissionsVerifierF.rb +2 -7
  552. data/lib/Glacier2/Router.rb +31 -78
  553. data/lib/Glacier2/RouterF.rb +2 -7
  554. data/lib/Glacier2/SSLInfo.rb +3 -11
  555. data/lib/Glacier2/Session.rb +87 -311
  556. data/lib/Ice.rb +84 -58
  557. data/lib/Ice/BuiltinSequences.rb +3 -8
  558. data/lib/Ice/Communicator.rb +54 -61
  559. data/lib/Ice/CommunicatorF.rb +2 -7
  560. data/lib/Ice/Connection.rb +152 -166
  561. data/lib/Ice/ConnectionF.rb +2 -7
  562. data/lib/Ice/Current.rb +3 -15
  563. data/lib/Ice/Endpoint.rb +56 -137
  564. data/lib/Ice/EndpointF.rb +2 -7
  565. data/lib/Ice/EndpointTypes.rb +2 -11
  566. data/lib/Ice/FacetMap.rb +3 -8
  567. data/lib/Ice/Identity.rb +4 -12
  568. data/lib/Ice/ImplicitContext.rb +4 -38
  569. data/lib/Ice/ImplicitContextF.rb +2 -7
  570. data/lib/Ice/Instrumentation.rb +22 -279
  571. data/lib/Ice/InstrumentationF.rb +2 -7
  572. data/lib/Ice/LocalException.rb +94 -145
  573. data/lib/Ice/Locator.rb +50 -169
  574. data/lib/Ice/LocatorF.rb +2 -7
  575. data/lib/Ice/Logger.rb +4 -38
  576. data/lib/Ice/LoggerF.rb +2 -7
  577. data/lib/Ice/Metrics.rb +60 -420
  578. data/lib/Ice/ObjectAdapter.rb +29 -0
  579. data/lib/Ice/ObjectAdapterF.rb +2 -7
  580. data/lib/Ice/ObjectFactory.rb +4 -34
  581. data/lib/Ice/Plugin.rb +6 -64
  582. data/lib/Ice/PluginF.rb +2 -7
  583. data/lib/Ice/Process.rb +15 -56
  584. data/lib/Ice/ProcessF.rb +2 -7
  585. data/lib/Ice/Properties.rb +4 -45
  586. data/lib/Ice/PropertiesAdmin.rb +18 -60
  587. data/lib/Ice/PropertiesF.rb +2 -7
  588. data/lib/Ice/RemoteLogger.rb +33 -119
  589. data/lib/Ice/Router.rb +28 -105
  590. data/lib/Ice/RouterF.rb +2 -7
  591. data/lib/Ice/ServantLocator.rb +26 -0
  592. data/lib/Ice/ServantLocatorF.rb +24 -0
  593. data/lib/Ice/SliceChecksumDict.rb +2 -7
  594. data/lib/Ice/ValueFactory.rb +28 -0
  595. data/lib/Ice/Version.rb +4 -15
  596. data/lib/IceBox.rb +1 -6
  597. data/lib/IceBox/IceBox.rb +43 -152
  598. data/lib/IceGrid.rb +1 -9
  599. data/lib/IceGrid/Admin.rb +550 -431
  600. data/lib/IceGrid/Descriptor.rb +61 -533
  601. data/lib/IceGrid/Exception.rb +23 -49
  602. data/lib/IceGrid/FileParser.rb +13 -54
  603. data/lib/IceGrid/PluginFacade.rb +35 -0
  604. data/lib/IceGrid/Registry.rb +150 -62
  605. data/lib/IceGrid/Session.rb +24 -68
  606. data/lib/IceGrid/UserAccountMapper.rb +13 -54
  607. data/lib/IcePatch2.rb +1 -6
  608. data/lib/IcePatch2/FileInfo.rb +4 -15
  609. data/lib/IcePatch2/FileServer.rb +32 -80
  610. data/lib/IceStorm.rb +1 -6
  611. data/lib/IceStorm/IceStorm.rb +78 -210
  612. data/lib/IceStorm/Metrics.rb +10 -93
  613. data/slice/Glacier2/Metrics.ice +20 -10
  614. data/slice/Glacier2/PermissionsVerifier.ice +19 -12
  615. data/slice/Glacier2/PermissionsVerifierF.ice +16 -9
  616. data/slice/Glacier2/Router.ice +19 -13
  617. data/slice/Glacier2/RouterF.ice +16 -9
  618. data/slice/Glacier2/SSLInfo.ice +17 -10
  619. data/slice/Glacier2/Session.ice +24 -18
  620. data/slice/Ice/BuiltinSequences.ice +18 -9
  621. data/slice/Ice/Communicator.ice +180 -64
  622. data/slice/Ice/CommunicatorF.ice +18 -9
  623. data/slice/Ice/Connection.ice +208 -75
  624. data/slice/Ice/ConnectionF.ice +18 -9
  625. data/slice/Ice/Current.ice +37 -28
  626. data/slice/Ice/Endpoint.ice +73 -21
  627. data/slice/Ice/EndpointF.ice +19 -10
  628. data/slice/Ice/EndpointTypes.ice +21 -13
  629. data/slice/Ice/FacetMap.ice +19 -10
  630. data/slice/Ice/Identity.ice +24 -10
  631. data/slice/Ice/ImplicitContext.ice +41 -33
  632. data/slice/Ice/ImplicitContextF.ice +17 -9
  633. data/slice/Ice/Instrumentation.ice +37 -30
  634. data/slice/Ice/InstrumentationF.ice +19 -10
  635. data/slice/Ice/LocalException.ice +118 -112
  636. data/slice/Ice/Locator.ice +28 -21
  637. data/slice/Ice/LocatorF.ice +18 -9
  638. data/slice/Ice/Logger.ice +26 -18
  639. data/slice/Ice/LoggerF.ice +18 -9
  640. data/slice/Ice/Metrics.ice +42 -30
  641. data/slice/Ice/ObjectAdapter.ice +88 -53
  642. data/slice/Ice/ObjectAdapterF.ice +18 -9
  643. data/slice/Ice/ObjectFactory.ice +28 -17
  644. data/slice/Ice/Plugin.ice +25 -13
  645. data/slice/Ice/PluginF.ice +22 -9
  646. data/slice/Ice/Process.ice +20 -11
  647. data/slice/Ice/ProcessF.ice +18 -9
  648. data/slice/Ice/Properties.ice +42 -28
  649. data/slice/Ice/PropertiesAdmin.ice +20 -10
  650. data/slice/Ice/PropertiesF.ice +18 -9
  651. data/slice/Ice/RemoteLogger.ice +23 -19
  652. data/slice/Ice/Router.ice +28 -13
  653. data/slice/Ice/RouterF.ice +18 -9
  654. data/slice/Ice/ServantLocator.ice +40 -29
  655. data/slice/Ice/ServantLocatorF.ice +18 -9
  656. data/slice/Ice/SliceChecksumDict.ice +18 -9
  657. data/slice/Ice/ValueFactory.ice +132 -0
  658. data/slice/Ice/Version.ice +20 -10
  659. data/slice/IceBT/ConnectionInfo.ice +58 -0
  660. data/slice/IceBT/EndpointInfo.ice +56 -0
  661. data/slice/IceBT/Types.ice +44 -0
  662. data/slice/IceBox/IceBox.ice +45 -27
  663. data/slice/IceDiscovery/IceDiscovery.ice +75 -10
  664. data/slice/IceGrid/Admin.ice +410 -44
  665. data/slice/IceGrid/Descriptor.ice +47 -34
  666. data/slice/IceGrid/Exception.ice +43 -32
  667. data/slice/IceGrid/FileParser.ice +21 -12
  668. data/slice/IceGrid/PluginFacade.ice +26 -18
  669. data/slice/IceGrid/Registry.ice +150 -21
  670. data/slice/IceGrid/Session.ice +25 -17
  671. data/slice/IceGrid/UserAccountMapper.ice +23 -14
  672. data/slice/IceIAP/ConnectionInfo.ice +73 -0
  673. data/slice/IceIAP/EndpointInfo.ice +67 -0
  674. data/slice/IceLocatorDiscovery/IceLocatorDiscovery.ice +19 -12
  675. data/slice/IcePatch2/FileInfo.ice +19 -13
  676. data/slice/IcePatch2/FileServer.ice +27 -18
  677. data/slice/IceSSL/ConnectionInfo.ice +27 -23
  678. data/slice/IceSSL/ConnectionInfoF.ice +30 -0
  679. data/slice/IceSSL/EndpointInfo.ice +21 -36
  680. data/slice/IceStorm/IceStorm.ice +33 -24
  681. data/slice/IceStorm/Metrics.ice +19 -11
  682. metadata +148 -120
  683. data/ext/ObjectFactory.cpp +0 -140
  684. data/ext/ObjectFactory.h +0 -50
  685. data/ext/ice/cpp/include/Ice/ACMF.h +0 -30
  686. data/ext/ice/cpp/include/Ice/BasicStream.h +0 -1335
  687. data/ext/ice/cpp/include/Ice/BuiltinSequences.h +0 -82
  688. data/ext/ice/cpp/include/Ice/Communicator.h +0 -200
  689. data/ext/ice/cpp/include/Ice/Connection.h +0 -497
  690. data/ext/ice/cpp/include/Ice/ConnectionF.h +0 -74
  691. data/ext/ice/cpp/include/Ice/ConnectionFactoryF.h +0 -30
  692. data/ext/ice/cpp/include/Ice/Current.h +0 -102
  693. data/ext/ice/cpp/include/Ice/DefaultObjectFactory.h +0 -48
  694. data/ext/ice/cpp/include/Ice/DeprecatedStringConverter.h +0 -62
  695. data/ext/ice/cpp/include/Ice/Endpoint.h +0 -341
  696. data/ext/ice/cpp/include/Ice/EndpointF.h +0 -93
  697. data/ext/ice/cpp/include/Ice/EndpointTypes.h +0 -82
  698. data/ext/ice/cpp/include/Ice/Identity.h +0 -168
  699. data/ext/ice/cpp/include/Ice/ImplicitContext.h +0 -102
  700. data/ext/ice/cpp/include/Ice/Instrumentation.h +0 -365
  701. data/ext/ice/cpp/include/Ice/InstrumentationF.h +0 -75
  702. data/ext/ice/cpp/include/Ice/LocalException.h +0 -1030
  703. data/ext/ice/cpp/include/Ice/Locator.h +0 -2193
  704. data/ext/ice/cpp/include/Ice/LocatorF.h +0 -93
  705. data/ext/ice/cpp/include/Ice/Logger.h +0 -100
  706. data/ext/ice/cpp/include/Ice/Metrics.h +0 -2974
  707. data/ext/ice/cpp/include/Ice/ObjectAdapter.h +0 -168
  708. data/ext/ice/cpp/include/Ice/ObjectAdapterFactoryF.h +0 -26
  709. data/ext/ice/cpp/include/Ice/ObjectFactory.h +0 -92
  710. data/ext/ice/cpp/include/Ice/ObjectFactoryF.h +0 -66
  711. data/ext/ice/cpp/include/Ice/ObjectFactoryManagerF.h +0 -26
  712. data/ext/ice/cpp/include/Ice/Outgoing.h +0 -225
  713. data/ext/ice/cpp/include/Ice/Plugin.h +0 -125
  714. data/ext/ice/cpp/include/Ice/PluginF.h +0 -70
  715. data/ext/ice/cpp/include/Ice/Process.h +0 -574
  716. data/ext/ice/cpp/include/Ice/ProcessF.h +0 -83
  717. data/ext/ice/cpp/include/Ice/Properties.h +0 -136
  718. data/ext/ice/cpp/include/Ice/PropertiesAdmin.h +0 -830
  719. data/ext/ice/cpp/include/Ice/PropertiesF.h +0 -87
  720. data/ext/ice/cpp/include/Ice/RemoteLogger.h +0 -1500
  721. data/ext/ice/cpp/include/Ice/Router.h +0 -1159
  722. data/ext/ice/cpp/include/Ice/RouterF.h +0 -83
  723. data/ext/ice/cpp/include/Ice/ServantLocator.h +0 -96
  724. data/ext/ice/cpp/include/Ice/Stream.h +0 -447
  725. data/ext/ice/cpp/include/Ice/StreamF.h +0 -30
  726. data/ext/ice/cpp/include/Ice/Version.h +0 -262
  727. data/ext/ice/cpp/include/IceSSL/ConnectionInfo.h +0 -158
  728. data/ext/ice/cpp/include/IceSSL/EndpointInfo.h +0 -142
  729. data/ext/ice/cpp/include/IceUtil/AbstractMutex.h +0 -119
  730. data/ext/ice/cpp/include/IceUtil/Cache.h +0 -362
  731. data/ext/ice/cpp/include/IceUtil/IconvStringConverter.h +0 -302
  732. data/ext/ice/cpp/include/IceUtil/SHA1.h +0 -47
  733. data/ext/ice/cpp/include/Slice/CPlusPlusUtil.h +0 -65
  734. data/ext/ice/cpp/include/Slice/Checksum.h +0 -26
  735. data/ext/ice/cpp/include/Slice/CsUtil.h +0 -92
  736. data/ext/ice/cpp/include/Slice/DotNetNames.h +0 -34
  737. data/ext/ice/cpp/include/Slice/JavaUtil.h +0 -279
  738. data/ext/ice/cpp/include/Slice/ObjCUtil.h +0 -127
  739. data/ext/ice/cpp/include/Slice/PHPUtil.h +0 -50
  740. data/ext/ice/cpp/include/Slice/PythonUtil.h +0 -64
  741. data/ext/ice/cpp/include/Slice/Util.h +0 -56
  742. data/ext/ice/cpp/src/Ice/BasicStream.cpp +0 -3428
  743. data/ext/ice/cpp/src/Ice/DeprecatedStringConverter.cpp +0 -62
  744. data/ext/ice/cpp/src/Ice/ObjectFactoryF.cpp +0 -44
  745. data/ext/ice/cpp/src/Ice/ObjectFactoryManager.cpp +0 -139
  746. data/ext/ice/cpp/src/Ice/ObjectFactoryManager.h +0 -43
  747. data/ext/ice/cpp/src/Ice/Outgoing.cpp +0 -694
  748. data/ext/ice/cpp/src/Ice/Stream.cpp +0 -53
  749. data/ext/ice/cpp/src/Ice/StreamI.cpp +0 -832
  750. data/ext/ice/cpp/src/Ice/StreamI.h +0 -198
  751. data/ext/ice/cpp/src/IceSSL/Certificate.cpp +0 -1336
  752. data/ext/ice/cpp/src/IceUtil/ArgVector.cpp +0 -64
  753. data/ext/ice/cpp/src/IceUtil/ArgVector.h +0 -41
  754. data/ext/ice/cpp/src/IceUtil/Exception.cpp +0 -792
  755. data/ext/ice/cpp/src/IceUtil/FileUtil.h +0 -185
  756. data/ext/ice/cpp/src/Slice/CsUtil.cpp +0 -2660
  757. data/ext/ice/cpp/src/Slice/DotNetNames.cpp +0 -146
  758. data/ext/ice/cpp/src/Slice/ObjCUtil.cpp +0 -1310
  759. data/lib/Ice/ObjectFactoryF.rb +0 -29
  760. data/lib/IceGrid/Locator.rb +0 -106
  761. data/lib/IceGrid/Observer.rb +0 -572
  762. data/lib/IceGrid/Query.rb +0 -169
  763. data/slice/Freeze/BackgroundSaveEvictor.ice +0 -111
  764. data/slice/Freeze/CatalogData.ice +0 -49
  765. data/slice/Freeze/Connection.ice +0 -121
  766. data/slice/Freeze/ConnectionF.ice +0 -20
  767. data/slice/Freeze/DB.ice +0 -37
  768. data/slice/Freeze/Evictor.ice +0 -346
  769. data/slice/Freeze/EvictorF.ice +0 -22
  770. data/slice/Freeze/EvictorStorage.ice +0 -72
  771. data/slice/Freeze/Exception.ice +0 -100
  772. data/slice/Freeze/Transaction.ice +0 -58
  773. data/slice/Freeze/TransactionalEvictor.ice +0 -50
  774. data/slice/Ice/ObjectFactoryF.ice +0 -21
  775. data/slice/IceGrid/Locator.ice +0 -57
  776. data/slice/IceGrid/Observer.ice +0 -395
  777. data/slice/IceGrid/Query.ice +0 -131
@@ -1,11 +1,6 @@
1
- // **********************************************************************
2
1
  //
3
- // Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
2
+ // Copyright (c) ZeroC, Inc. All rights reserved.
4
3
  //
5
- // This copy of Ice is licensed to you under the terms described in the
6
- // ICE_LICENSE file included in this distribution.
7
- //
8
- // **********************************************************************
9
4
 
10
5
  #ifndef ICE_ROUTER_INFO_F_H
11
6
  #define ICE_ROUTER_INFO_F_H
@@ -1,15 +1,10 @@
1
- // **********************************************************************
2
1
  //
3
- // Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
2
+ // Copyright (c) ZeroC, Inc. All rights reserved.
4
3
  //
5
- // This copy of Ice is licensed to you under the terms described in the
6
- // ICE_LICENSE file included in this distribution.
7
- //
8
- // **********************************************************************
9
4
 
10
- #include <IceUtil/SHA1.h>
5
+ #include <Ice/SHA1.h>
11
6
 
12
- #ifndef ICE_OS_WINRT
7
+ #ifndef ICE_OS_UWP
13
8
  # if defined(_WIN32)
14
9
  # include <Wincrypt.h>
15
10
  # include <IceUtil/Exception.h>
@@ -23,29 +18,29 @@
23
18
  using namespace std;
24
19
  using namespace IceUtil;
25
20
 
26
- #ifndef ICE_OS_WINRT
21
+ #ifndef ICE_OS_UWP
27
22
 
28
- namespace IceUtilInternal
23
+ namespace IceInternal
29
24
  {
30
25
 
31
26
  class SHA1::Hasher
32
27
  {
33
28
  public:
34
-
29
+
35
30
  Hasher();
36
31
  # ifdef _WIN32
37
32
  ~Hasher();
38
33
  #endif
39
-
34
+
40
35
  void update(const unsigned char*, std::size_t);
41
36
  void finalize(std::vector<unsigned char>&);
42
-
37
+
43
38
  private:
44
39
 
45
40
  // noncopyable
46
41
  Hasher(const Hasher&);
47
42
  Hasher operator=(const Hasher&);
48
-
43
+
49
44
  # if defined (_WIN32)
50
45
  HCRYPTPROV _ctx;
51
46
  HCRYPTHASH _hash;
@@ -65,7 +60,7 @@ namespace
65
60
  const int SHA_DIGEST_LENGTH = 20;
66
61
  }
67
62
 
68
- IceUtilInternal::SHA1::Hasher::Hasher() :
63
+ IceInternal::SHA1::Hasher::Hasher() :
69
64
  _ctx(0),
70
65
  _hash(0)
71
66
  {
@@ -80,7 +75,7 @@ IceUtilInternal::SHA1::Hasher::Hasher() :
80
75
  }
81
76
  }
82
77
 
83
- IceUtilInternal::SHA1::Hasher::~Hasher()
78
+ IceInternal::SHA1::Hasher::~Hasher()
84
79
  {
85
80
  if(_hash)
86
81
  {
@@ -93,19 +88,19 @@ IceUtilInternal::SHA1::Hasher::~Hasher()
93
88
  }
94
89
  }
95
90
  # elif defined(__APPLE__)
96
- IceUtilInternal::SHA1::Hasher::Hasher()
91
+ IceInternal::SHA1::Hasher::Hasher()
97
92
  {
98
93
  CC_SHA1_Init(&_ctx);
99
94
  }
100
95
  # else
101
- IceUtilInternal::SHA1::Hasher::Hasher()
96
+ IceInternal::SHA1::Hasher::Hasher()
102
97
  {
103
98
  SHA1_Init(&_ctx);
104
99
  }
105
100
  # endif
106
101
 
107
102
  void
108
- IceUtilInternal::SHA1::Hasher::update(const unsigned char* data, size_t length)
103
+ IceInternal::SHA1::Hasher::update(const unsigned char* data, size_t length)
109
104
  {
110
105
  # if defined(_WIN32)
111
106
  if(!CryptHashData(_hash, data, static_cast<DWORD>(length), 0))
@@ -113,14 +108,14 @@ IceUtilInternal::SHA1::Hasher::update(const unsigned char* data, size_t length)
113
108
  throw IceUtil::SyscallException(__FILE__, __LINE__, GetLastError());
114
109
  }
115
110
  # elif defined(__APPLE__)
116
- CC_SHA1_Update(&_ctx, reinterpret_cast<const void*>(data), length);
111
+ CC_SHA1_Update(&_ctx, reinterpret_cast<const void*>(data), static_cast<CC_LONG>(length));
117
112
  # else
118
113
  SHA1_Update(&_ctx, reinterpret_cast<const void*>(data), length);
119
114
  # endif
120
115
  }
121
116
 
122
117
  void
123
- IceUtilInternal::SHA1::Hasher::finalize(vector<unsigned char>& md)
118
+ IceInternal::SHA1::Hasher::finalize(vector<unsigned char>& md)
124
119
  {
125
120
  # if defined(_WIN32)
126
121
  md.resize(SHA_DIGEST_LENGTH);
@@ -138,32 +133,32 @@ IceUtilInternal::SHA1::Hasher::finalize(vector& md)
138
133
  # endif
139
134
  }
140
135
 
141
- IceUtilInternal::SHA1::SHA1() :
136
+ IceInternal::SHA1::SHA1() :
142
137
  _hasher(new Hasher())
143
138
  {
144
139
  }
145
140
 
146
- IceUtilInternal::SHA1::~SHA1()
141
+ IceInternal::SHA1::~SHA1()
147
142
  {
148
143
  }
149
144
 
150
145
  void
151
- IceUtilInternal::SHA1::update(const unsigned char* data, std::size_t length)
146
+ IceInternal::SHA1::update(const unsigned char* data, std::size_t length)
152
147
  {
153
148
  _hasher->update(data, length);
154
149
  }
155
150
 
156
151
  void
157
- IceUtilInternal::SHA1::finalize(std::vector<unsigned char>& md)
152
+ IceInternal::SHA1::finalize(std::vector<unsigned char>& md)
158
153
  {
159
154
  _hasher->finalize(md);
160
155
  }
161
156
  #endif
162
157
 
163
158
  void
164
- IceUtilInternal::sha1(const unsigned char* data, size_t length, vector<unsigned char>& md)
159
+ IceInternal::sha1(const unsigned char* data, size_t length, vector<unsigned char>& md)
165
160
  {
166
- #if defined(ICE_OS_WINRT)
161
+ #if defined(ICE_OS_UWP)
167
162
  auto dataA =
168
163
  ref new Platform::Array<unsigned char>(const_cast<unsigned char*>(data), static_cast<unsigned int>(length));
169
164
  auto hasher = Windows::Security::Cryptography::Core::HashAlgorithmProvider::OpenAlgorithm("SHA1");
@@ -180,7 +175,7 @@ IceUtilInternal::sha1(const unsigned char* data, size_t length, vector
180
175
  hasher.finalize(md);
181
176
  #elif defined(__APPLE__)
182
177
  md.resize(CC_SHA1_DIGEST_LENGTH);
183
- CC_SHA1(&data[0], length, &md[0]);
178
+ CC_SHA1(&data[0], static_cast<CC_LONG>(length), &md[0]);
184
179
  #else
185
180
  md.resize(SHA_DIGEST_LENGTH);
186
181
  ::SHA1(&data[0], length, &md[0]);
@@ -1,11 +1,6 @@
1
- // **********************************************************************
2
1
  //
3
- // Copyright (c) 2003-2018 ZeroC, Inc. All rights reserved.
2
+ // Copyright (c) ZeroC, Inc. All rights reserved.
4
3
  //
5
- // This copy of Ice is licensed to you under the terms described in the
6
- // ICE_LICENSE file included in this distribution.
7
- //
8
- // **********************************************************************
9
4
 
10
5
  #include <Ice/Selector.h>
11
6
  #include <Ice/EventHandler.h>
@@ -29,98 +24,13 @@ struct timespec zeroTimeout = { 0, 0 };
29
24
  }
30
25
  #endif
31
26
 
32
- #ifdef ICE_OS_WINRT
33
- using namespace Windows::Foundation;
27
+ #if defined(ICE_OS_UWP)
34
28
  using namespace Windows::Storage::Streams;
35
29
  using namespace Windows::Networking;
36
30
  using namespace Windows::Networking::Sockets;
31
+ #endif
37
32
 
38
- Selector::Selector(const InstancePtr& instance) : _instance(instance)
39
- {
40
- }
41
-
42
- void
43
- Selector::destroy()
44
- {
45
- }
46
-
47
- void
48
- Selector::initialize(IceInternal::EventHandler* handler)
49
- {
50
- EventHandlerPtr h = handler;
51
- handler->__incRef();
52
- handler->getNativeInfo()->setCompletedHandler(
53
- ref new SocketOperationCompletedHandler([=](int operation)
54
- {
55
- //
56
- // Use the reference counted handler to ensure it's not
57
- // destroyed as long as the callback lambda exists.
58
- //
59
- completed(h, static_cast<SocketOperation>(operation));
60
- }));
61
- }
62
-
63
- void
64
- Selector::update(IceInternal::EventHandler* handler, SocketOperation remove, SocketOperation add)
65
- {
66
- handler->_registered = static_cast<SocketOperation>(handler->_registered & ~remove);
67
- handler->_registered = static_cast<SocketOperation>(handler->_registered | add);
68
- if(add & SocketOperationRead && !(handler->_pending & SocketOperationRead))
69
- {
70
- handler->_pending = static_cast<SocketOperation>(handler->_pending | SocketOperationRead);
71
- completed(handler, SocketOperationRead); // Start an asynchrnous read
72
- }
73
- else if(add & SocketOperationWrite && !(handler->_pending & SocketOperationWrite))
74
- {
75
- handler->_pending = static_cast<SocketOperation>(handler->_pending | SocketOperationWrite);
76
- completed(handler, SocketOperationWrite); // Start an asynchrnous write
77
- }
78
- }
79
-
80
- void
81
- Selector::finish(IceInternal::EventHandler* handler)
82
- {
83
- handler->_registered = SocketOperationNone;
84
- handler->_finish = false; // Ensures that finished() is only called once on the event handler.
85
- handler->__decRef();
86
- }
87
-
88
- IceInternal::EventHandlerPtr
89
- Selector::getNextHandler(SocketOperation& status, int timeout)
90
- {
91
- Lock lock(*this);
92
- while(_events.empty())
93
- {
94
- if(timeout > 0)
95
- {
96
- timedWait(IceUtil::Time::seconds(timeout));
97
- if(_events.empty())
98
- {
99
- throw SelectorTimeoutException();
100
- }
101
- }
102
- else
103
- {
104
- wait();
105
- }
106
- }
107
- assert(!_events.empty());
108
- IceInternal::EventHandlerPtr handler = _events.front().handler;
109
- const SelectEvent& event = _events.front();
110
- status = event.status;
111
- _events.pop_front();
112
- return handler;
113
- }
114
-
115
- void
116
- Selector::completed(const IceInternal::EventHandlerPtr& handler, SocketOperation op)
117
- {
118
- Lock lock(*this);
119
- _events.push_back(SelectEvent(handler, op));
120
- notify();
121
- }
122
-
123
- #elif defined(ICE_USE_IOCP)
33
+ #if defined(ICE_USE_IOCP) || defined(ICE_OS_UWP)
124
34
 
125
35
  Selector::Selector(const InstancePtr& instance) : _instance(instance)
126
36
  {
@@ -130,36 +40,60 @@ Selector::~Selector()
130
40
  {
131
41
  }
132
42
 
43
+ #ifdef ICE_USE_IOCP
133
44
  void
134
45
  Selector::setup(int sizeIO)
135
46
  {
136
- _handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, sizeIO);
137
- if(_handle == NULL)
47
+ _handle = CreateIoCompletionPort(INVALID_HANDLE_VALUE, ICE_NULLPTR, 0, sizeIO);
48
+ if(_handle == ICE_NULLPTR)
138
49
  {
139
- Ice::SocketException ex(__FILE__, __LINE__);
140
- ex.error = GetLastError();
141
- throw ex;
50
+ throw Ice::SocketException(__FILE__, __LINE__, GetLastError());
142
51
  }
143
52
  }
53
+ #endif
144
54
 
145
55
  void
146
56
  Selector::destroy()
147
57
  {
58
+ #ifdef ICE_USE_IOCP
148
59
  CloseHandle(_handle);
60
+ #endif
149
61
  }
150
62
 
151
63
  void
152
64
  Selector::initialize(EventHandler* handler)
153
65
  {
154
- HANDLE socket = reinterpret_cast<HANDLE>(handler->getNativeInfo()->fd());
155
- if(CreateIoCompletionPort(socket, _handle, reinterpret_cast<ULONG_PTR>(handler), 0) == NULL)
66
+ if(!handler->getNativeInfo())
67
+ {
68
+ return;
69
+ }
70
+
71
+ #ifdef ICE_USE_IOCP
72
+ SOCKET socket = handler->getNativeInfo()->fd();
73
+ if(socket != INVALID_SOCKET)
156
74
  {
157
- Ice::SocketException ex(__FILE__, __LINE__);
158
- ex.error = GetLastError();
159
- throw ex;
75
+ if(CreateIoCompletionPort(reinterpret_cast<HANDLE>(socket),
76
+ _handle,
77
+ reinterpret_cast<ULONG_PTR>(handler),
78
+ 0) == ICE_NULLPTR)
79
+ {
80
+ throw Ice::SocketException(__FILE__, __LINE__, GetLastError());
81
+ }
160
82
  }
161
- handler->__incRef();
162
83
  handler->getNativeInfo()->initialize(_handle, reinterpret_cast<ULONG_PTR>(handler));
84
+ #else
85
+ EventHandlerPtr h = ICE_GET_SHARED_FROM_THIS(handler);
86
+ handler->getNativeInfo()->setCompletedHandler(
87
+ ref new SocketOperationCompletedHandler(
88
+ [=](int operation)
89
+ {
90
+ //
91
+ // Use the reference counted handler to ensure it's not
92
+ // destroyed as long as the callback lambda exists.
93
+ //
94
+ completed(h.get(), static_cast<SocketOperation>(operation));
95
+ }));
96
+ #endif
163
97
  }
164
98
 
165
99
  void
@@ -167,42 +101,60 @@ Selector::update(EventHandler* handler, SocketOperation remove, SocketOperation
167
101
  {
168
102
  handler->_registered = static_cast<SocketOperation>(handler->_registered & ~remove);
169
103
  handler->_registered = static_cast<SocketOperation>(handler->_registered | add);
170
- AsyncInfo* info = 0;
171
104
  if(add & SocketOperationRead && !(handler->_pending & SocketOperationRead))
172
105
  {
173
106
  handler->_pending = static_cast<SocketOperation>(handler->_pending | SocketOperationRead);
174
- info = handler->getNativeInfo()->getAsyncInfo(SocketOperationRead);
107
+ completed(handler, SocketOperationRead); // Start an asynchrnous read
175
108
  }
176
109
  else if(add & SocketOperationWrite && !(handler->_pending & SocketOperationWrite))
177
110
  {
178
111
  handler->_pending = static_cast<SocketOperation>(handler->_pending | SocketOperationWrite);
179
- info = handler->getNativeInfo()->getAsyncInfo(SocketOperationWrite);
180
- }
181
-
182
- if(info)
183
- {
184
- if(!PostQueuedCompletionStatus(_handle, 0, reinterpret_cast<ULONG_PTR>(handler), info))
185
- {
186
- Ice::SocketException ex(__FILE__, __LINE__);
187
- ex.error = GetLastError();
188
- throw ex;
189
- }
112
+ completed(handler, SocketOperationWrite); // Start an asynchrnous write
190
113
  }
191
114
  }
192
115
 
193
116
  void
194
117
  Selector::finish(IceInternal::EventHandler* handler)
195
118
  {
119
+ #ifdef ICE_OS_UWP
120
+ // If async operations are no longer pending, clear the completion handler to break
121
+ // the cyclic reference count.
122
+ assert(!handler->_started && !handler->_pending);
123
+ handler->getNativeInfo()->setCompletedHandler(nullptr);
124
+ #endif
196
125
  handler->_registered = SocketOperationNone;
197
- handler->__decRef();
126
+ handler->_finish = false; // Ensures that finished() is only called once on the event handler.
127
+ }
128
+
129
+ void
130
+ Selector::ready(EventHandler* handler, SocketOperation status, bool value)
131
+ {
132
+ if(((handler->_ready & status) != 0) == value)
133
+ {
134
+ return; // Nothing to do if ready state already correctly set.
135
+ }
136
+
137
+ if(value)
138
+ {
139
+ handler->_ready = static_cast<SocketOperation>(handler->_ready | status);
140
+ }
141
+ else
142
+ {
143
+ handler->_ready = static_cast<SocketOperation>(handler->_ready & ~status);
144
+ }
198
145
  }
199
146
 
200
147
  EventHandler*
148
+ #ifdef ICE_USE_IOCP
201
149
  Selector::getNextHandler(SocketOperation& status, DWORD& count, int& error, int timeout)
150
+ #else
151
+ Selector::getNextHandler(SocketOperation& status, int timeout)
152
+ #endif
202
153
  {
154
+ #ifdef ICE_USE_IOCP
203
155
  ULONG_PTR key;
204
156
  LPOVERLAPPED ol;
205
- error = 0;
157
+ error = ERROR_SUCCESS;
206
158
 
207
159
  if(!GetQueuedCompletionStatus(_handle, &count, &key, &ol, timeout > 0 ? timeout * 1000 : INFINITE))
208
160
  {
@@ -215,49 +167,132 @@ Selector::getNextHandler(SocketOperation& status, DWORD& count, int& error, int
215
167
  }
216
168
  else
217
169
  {
218
- {
219
- Ice::SocketException ex(__FILE__, __LINE__, err);
220
- Ice::Error out(_instance->initializationData().logger);
221
- out << "fatal error: couldn't dequeue packet from completion port:\n" << ex;
222
- }
223
- abort();
170
+ Ice::SocketException ex(__FILE__, __LINE__, err);
171
+ Ice::Error out(_instance->initializationData().logger);
172
+ out << "couldn't dequeue packet from completion port:\n" << ex;
173
+ IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(5)); // Sleep 5s to avoid looping
224
174
  }
225
175
  }
226
176
  AsyncInfo* info = static_cast<AsyncInfo*>(ol);
227
- status = info->status;
228
- count = SOCKET_ERROR;
177
+ if(info)
178
+ {
179
+ status = info->status;
180
+ }
181
+ count = 0;
229
182
  error = WSAGetLastError();
230
183
  return reinterpret_cast<EventHandler*>(key);
231
184
  }
232
185
 
233
- assert(ol);
234
186
  AsyncInfo* info = static_cast<AsyncInfo*>(ol);
235
- status = info->status;
187
+ if(info)
188
+ {
189
+ status = info->status;
190
+ }
191
+ else
192
+ {
193
+ status = reinterpret_cast<EventHandler*>(key)->_ready;
194
+ }
236
195
  return reinterpret_cast<EventHandler*>(key);
196
+ #else
197
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor);
198
+ while(_events.empty())
199
+ {
200
+ if(timeout > 0)
201
+ {
202
+ _monitor.timedWait(IceUtil::Time::seconds(timeout));
203
+ if(_events.empty())
204
+ {
205
+ throw SelectorTimeoutException();
206
+ }
207
+ }
208
+ else
209
+ {
210
+ _monitor.wait();
211
+ }
212
+ }
213
+ assert(!_events.empty());
214
+ IceInternal::EventHandlerPtr handler = _events.front().handler;
215
+ const SelectEvent& event = _events.front();
216
+ status = event.status;
217
+ _events.pop_front();
218
+ return handler.get();
219
+ #endif
220
+ }
221
+
222
+ void
223
+ Selector::completed(EventHandler* handler, SocketOperation op)
224
+ {
225
+ #ifdef ICE_USE_IOCP
226
+ AsyncInfo* info = 0;
227
+ NativeInfoPtr nativeInfo = handler->getNativeInfo();
228
+ if(nativeInfo)
229
+ {
230
+ info = nativeInfo->getAsyncInfo(op);
231
+ }
232
+ if(!PostQueuedCompletionStatus(_handle, 0, reinterpret_cast<ULONG_PTR>(handler), info))
233
+ {
234
+ throw Ice::SocketException(__FILE__, __LINE__, GetLastError());
235
+ }
236
+ #else
237
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor);
238
+ _events.push_back(SelectEvent(handler->shared_from_this(), op));
239
+ _monitor.notify();
240
+ #endif
237
241
  }
238
242
 
239
- #elif defined(ICE_USE_KQUEUE) || defined(ICE_USE_EPOLL)
243
+ #elif defined(ICE_USE_KQUEUE) || defined(ICE_USE_EPOLL) || defined(ICE_USE_SELECT) || defined(ICE_USE_POLL)
240
244
 
241
- Selector::Selector(const InstancePtr& instance) : _instance(instance)
245
+ Selector::Selector(const InstancePtr& instance) : _instance(instance), _interrupted(false)
242
246
  {
243
- _events.resize(256);
247
+ SOCKET fds[2];
248
+ createPipe(fds);
249
+ _fdIntrRead = fds[0];
250
+ _fdIntrWrite = fds[1];
251
+ _selecting = false;
252
+
244
253
  #if defined(ICE_USE_EPOLL)
254
+ _events.resize(256);
245
255
  _queueFd = epoll_create(1);
246
256
  if(_queueFd < 0)
247
257
  {
248
- Ice::SocketException ex(__FILE__, __LINE__);
249
- ex.error = IceInternal::getSocketErrno();
250
- throw ex;
258
+ throw Ice::SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
251
259
  }
252
- #else
260
+
261
+ epoll_event event;
262
+ memset(&event, 0, sizeof(epoll_event));
263
+ event.data.ptr = 0;
264
+ event.events = EPOLLIN;
265
+ if(epoll_ctl(_queueFd, EPOLL_CTL_ADD, _fdIntrRead, &event) != 0)
266
+ {
267
+ Ice::Error out(_instance->initializationData().logger);
268
+ out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
269
+ }
270
+ #elif defined(ICE_USE_KQUEUE)
271
+ _events.resize(256);
253
272
  _queueFd = kqueue();
254
273
  if(_queueFd < 0)
255
274
  {
256
- Ice::SocketException ex(__FILE__, __LINE__);
257
- ex.error = getSocketErrno();
258
- throw ex;
275
+ throw Ice::SocketException(__FILE__, __LINE__, getSocketErrno());
259
276
  }
260
- _selecting = false;
277
+
278
+ struct kevent ev;
279
+ EV_SET(&ev, _fdIntrRead, EVFILT_READ, EV_ADD, 0, 0, 0);
280
+ int rs = kevent(_queueFd, &ev, 1, 0, 0, 0);
281
+ if(rs < 0)
282
+ {
283
+ Ice::Error out(_instance->initializationData().logger);
284
+ out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
285
+ }
286
+ #elif defined(ICE_USE_SELECT)
287
+ FD_ZERO(&_readFdSet);
288
+ FD_ZERO(&_writeFdSet);
289
+ FD_ZERO(&_errorFdSet);
290
+ FD_SET(_fdIntrRead, &_readFdSet);
291
+ #else
292
+ struct pollfd pollFd;
293
+ pollFd.fd = _fdIntrRead;
294
+ pollFd.events = POLLIN;
295
+ _pollFdSet.push_back(pollFd);
261
296
  #endif
262
297
  }
263
298
 
@@ -268,6 +303,7 @@ Selector::~Selector()
268
303
  void
269
304
  Selector::destroy()
270
305
  {
306
+ #if defined(ICE_USE_KQUEUE) || defined(ICE_USE_EPOLL)
271
307
  try
272
308
  {
273
309
  closeSocket(_queueFd);
@@ -277,6 +313,27 @@ Selector::destroy()
277
313
  Ice::Error out(_instance->initializationData().logger);
278
314
  out << "exception in selector while calling closeSocket():\n" << ex;
279
315
  }
316
+ #endif
317
+
318
+ try
319
+ {
320
+ closeSocket(_fdIntrWrite);
321
+ }
322
+ catch(const Ice::LocalException& ex)
323
+ {
324
+ Ice::Error out(_instance->initializationData().logger);
325
+ out << "exception in selector while calling closeSocket():\n" << ex;
326
+ }
327
+
328
+ try
329
+ {
330
+ closeSocket(_fdIntrRead);
331
+ }
332
+ catch(const Ice::LocalException& ex)
333
+ {
334
+ Ice::Error out(_instance->initializationData().logger);
335
+ out << "exception in selector while calling closeSocket():\n" << ex;
336
+ }
280
337
  }
281
338
 
282
339
  void
@@ -289,109 +346,65 @@ Selector::update(EventHandler* handler, SocketOperation remove, SocketOperation
289
346
  {
290
347
  return;
291
348
  }
349
+ checkReady(handler);
292
350
 
293
- SOCKET fd = handler->getNativeInfo()->fd();
294
- #if defined(ICE_USE_EPOLL)
295
- epoll_event event;
296
- memset(&event, 0, sizeof(epoll_event));
297
- event.data.ptr = handler;
298
- SocketOperation status = handler->_registered;
299
- if(handler->_disabled)
300
- {
301
- status = static_cast<SocketOperation>(status & ~handler->_disabled);
302
- previous = static_cast<SocketOperation>(previous & ~handler->_disabled);
303
- }
304
- event.events |= status & SocketOperationRead ? EPOLLIN : 0;
305
- event.events |= status & SocketOperationWrite ? EPOLLOUT : 0;
306
- int op;
307
- if(!previous && status)
351
+ NativeInfoPtr nativeInfo = handler->getNativeInfo();
352
+ if(nativeInfo && nativeInfo->fd() != INVALID_SOCKET)
308
353
  {
309
- op = EPOLL_CTL_ADD;
310
- }
311
- else if(previous && !status)
312
- {
313
- op = EPOLL_CTL_DEL;
354
+ updateSelectorForEventHandler(handler, remove, add);
314
355
  }
315
- else if(previous == status)
356
+ }
357
+
358
+ void
359
+ Selector::enable(EventHandler* handler, SocketOperation status)
360
+ {
361
+ if(!(handler->_disabled & status))
316
362
  {
317
363
  return;
318
364
  }
319
- else
320
- {
321
- op = EPOLL_CTL_MOD;
322
- }
323
- if(epoll_ctl(_queueFd, op, fd, &event) != 0)
365
+ handler->_disabled = static_cast<SocketOperation>(handler->_disabled & ~status);
366
+ checkReady(handler);
367
+
368
+ NativeInfoPtr nativeInfo = handler->getNativeInfo();
369
+ if(!nativeInfo || nativeInfo->fd() == INVALID_SOCKET)
324
370
  {
325
- Ice::Error out(_instance->initializationData().logger);
326
- out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
371
+ return;
327
372
  }
328
- #else // ICE_USE_KQUEUE
329
- if(remove & SocketOperationRead)
373
+
374
+ if(handler->_registered & status)
330
375
  {
376
+ #if defined(ICE_USE_EPOLL)
377
+ SOCKET fd = nativeInfo->fd();
378
+ SocketOperation previous = static_cast<SocketOperation>(handler->_registered & ~(handler->_disabled | status));
379
+ SocketOperation newStatus = static_cast<SocketOperation>(handler->_registered & ~handler->_disabled);
380
+ epoll_event event;
381
+ memset(&event, 0, sizeof(epoll_event));
382
+ event.data.ptr = handler;
383
+ if(newStatus & SocketOperationRead)
384
+ {
385
+ event.events |= EPOLLIN;
386
+ }
387
+ if(newStatus & SocketOperationWrite)
388
+ {
389
+ event.events |= EPOLLOUT;
390
+ }
391
+ if(epoll_ctl(_queueFd, previous ? EPOLL_CTL_MOD : EPOLL_CTL_ADD, fd, &event) != 0)
392
+ {
393
+ Ice::Error out(_instance->initializationData().logger);
394
+ out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
395
+ }
396
+ #elif defined(ICE_USE_KQUEUE)
331
397
  struct kevent ev;
332
- EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, handler);
333
- _changes.push_back(ev);
334
- }
335
- if(remove & SocketOperationWrite)
336
- {
337
- struct kevent ev;
338
- EV_SET(&ev, fd, EVFILT_WRITE, EV_DELETE, 0, 0, handler);
339
- _changes.push_back(ev);
340
- }
341
- if(add & SocketOperationRead)
342
- {
343
- struct kevent ev;
344
- EV_SET(&ev, fd, EVFILT_READ, EV_ADD | (handler->_disabled & SocketOperationRead ? EV_DISABLE : 0), 0, 0,
345
- handler);
346
- _changes.push_back(ev);
347
- }
348
- if(add & SocketOperationWrite)
349
- {
350
- struct kevent ev;
351
- EV_SET(&ev, fd, EVFILT_WRITE, EV_ADD | (handler->_disabled & SocketOperationWrite ? EV_DISABLE : 0), 0, 0,
352
- handler);
353
- _changes.push_back(ev);
354
- }
355
- if(_selecting)
356
- {
357
- updateSelector();
358
- }
359
- #endif
360
- }
361
-
362
- void
363
- Selector::enable(EventHandler* handler, SocketOperation status)
364
- {
365
- if(!(handler->_disabled & status))
366
- {
367
- return;
368
- }
369
- handler->_disabled = static_cast<SocketOperation>(handler->_disabled & ~status);
370
-
371
- if(handler->_registered & status)
372
- {
373
398
  SOCKET fd = handler->getNativeInfo()->fd();
374
- #if defined(ICE_USE_EPOLL)
375
- SocketOperation previous = static_cast<SocketOperation>(handler->_registered & ~(handler->_disabled | status));
376
- SocketOperation newStatus = static_cast<SocketOperation>(handler->_registered & ~handler->_disabled);
377
- epoll_event event;
378
- memset(&event, 0, sizeof(epoll_event));
379
- event.data.ptr = handler;
380
- event.events |= newStatus & SocketOperationRead ? EPOLLIN : 0;
381
- event.events |= newStatus & SocketOperationWrite ? EPOLLOUT : 0;
382
- if(epoll_ctl(_queueFd, previous ? EPOLL_CTL_MOD : EPOLL_CTL_ADD, fd, &event) != 0)
383
- {
384
- Ice::Error out(_instance->initializationData().logger);
385
- out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
386
- }
387
- #else // ICE_USE_KQUEUE
388
- struct kevent ev;
389
399
  EV_SET(&ev, fd, status == SocketOperationRead ? EVFILT_READ : EVFILT_WRITE, EV_ENABLE, 0, 0, handler);
390
400
  _changes.push_back(ev);
391
401
  if(_selecting)
392
402
  {
393
403
  updateSelector();
394
404
  }
405
+ #else
406
+ _changes.push_back(make_pair(handler, static_cast<SocketOperation>(handler->_registered & ~handler->_disabled)));
407
+ wakeup();
395
408
  #endif
396
409
  }
397
410
  }
@@ -404,23 +417,37 @@ Selector::disable(EventHandler* handler, SocketOperation status)
404
417
  return;
405
418
  }
406
419
  handler->_disabled = static_cast<SocketOperation>(handler->_disabled | status);
420
+ checkReady(handler);
421
+
422
+ NativeInfoPtr nativeInfo = handler->getNativeInfo();
423
+ if(!nativeInfo || nativeInfo->fd() == INVALID_SOCKET)
424
+ {
425
+ return;
426
+ }
407
427
 
408
428
  if(handler->_registered & status)
409
429
  {
410
- SOCKET fd = handler->getNativeInfo()->fd();
411
430
  #if defined(ICE_USE_EPOLL)
431
+ SOCKET fd = nativeInfo->fd();
412
432
  SocketOperation newStatus = static_cast<SocketOperation>(handler->_registered & ~handler->_disabled);
413
433
  epoll_event event;
414
434
  memset(&event, 0, sizeof(epoll_event));
415
435
  event.data.ptr = handler;
416
- event.events |= newStatus & SocketOperationRead ? EPOLLIN : 0;
417
- event.events |= newStatus & SocketOperationWrite ? EPOLLOUT : 0;
436
+ if(newStatus & SocketOperationRead)
437
+ {
438
+ event.events |= EPOLLIN;
439
+ }
440
+ if(newStatus & SocketOperationWrite)
441
+ {
442
+ event.events |= EPOLLOUT;
443
+ }
418
444
  if(epoll_ctl(_queueFd, newStatus ? EPOLL_CTL_MOD : EPOLL_CTL_DEL, fd, &event) != 0)
419
445
  {
420
446
  Ice::Error out(_instance->initializationData().logger);
421
447
  out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
422
448
  }
423
- #else // ICE_USE_KQUEUE
449
+ #elif defined(ICE_USE_KQUEUE)
450
+ SOCKET fd = nativeInfo->fd();
424
451
  struct kevent ev;
425
452
  EV_SET(&ev, fd, status == SocketOperationRead ? EVFILT_READ : EVFILT_WRITE, EV_DISABLE, 0, 0, handler);
426
453
  _changes.push_back(ev);
@@ -428,6 +455,9 @@ Selector::disable(EventHandler* handler, SocketOperation status)
428
455
  {
429
456
  updateSelector();
430
457
  }
458
+ #else
459
+ _changes.push_back(make_pair(handler, static_cast<SocketOperation>(handler->_registered & ~handler->_disabled)));
460
+ wakeup();
431
461
  #endif
432
462
  }
433
463
  }
@@ -438,7 +468,11 @@ Selector::finish(EventHandler* handler, bool closeNow)
438
468
  if(handler->_registered)
439
469
  {
440
470
  update(handler, handler->_registered, SocketOperationNone);
471
+ #if !defined(ICE_USE_EPOLL) && !defined(ICE_USE_KQUEUE)
472
+ return false; // Don't close now if selecting
473
+ #endif
441
474
  }
475
+
442
476
  #if defined(ICE_USE_KQUEUE)
443
477
  if(closeNow && !_changes.empty())
444
478
  {
@@ -449,98 +483,127 @@ Selector::finish(EventHandler* handler, bool closeNow)
449
483
  //
450
484
  updateSelector();
451
485
  }
486
+ #elif !defined(ICE_USE_EPOLL)
487
+ if(!_changes.empty())
488
+ {
489
+ return false;
490
+ }
452
491
  #endif
492
+
453
493
  return closeNow;
454
494
  }
455
495
 
456
- #if defined(ICE_USE_KQUEUE)
457
496
  void
458
- Selector::updateSelector()
497
+ Selector::ready(EventHandler* handler, SocketOperation status, bool value)
459
498
  {
460
- int rs = kevent(_queueFd, &_changes[0], _changes.size(), &_changes[0], _changes.size(), &zeroTimeout);
461
- if(rs < 0)
499
+ if(((handler->_ready & status) != 0) == value)
462
500
  {
463
- Ice::Error out(_instance->initializationData().logger);
464
- out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
501
+ return; // Nothing to do if ready state already correctly set.
465
502
  }
466
- else
503
+
504
+ if(status & SocketOperationConnect)
467
505
  {
468
- for(int i = 0; i < rs; ++i)
506
+ NativeInfoPtr nativeInfo = handler->getNativeInfo();
507
+ if(nativeInfo && nativeInfo->newFd() && handler->_registered)
469
508
  {
470
- //
471
- // Check for errors, we ignore EINPROGRESS that started showing up with macOS Sierra
472
- // and which occurs when another thread removes the FD from the kqueue (see ICE-7419).
473
- //
474
- if(_changes[i].flags & EV_ERROR && _changes[i].data != EINPROGRESS)
475
- {
476
- Ice::Error out(_instance->initializationData().logger);
477
- out << "error while updating selector:\n" << IceUtilInternal::errorToString(_changes[i].data);
478
- }
509
+ // If new FD is set after connect, register the FD with the selector.
510
+ updateSelectorForEventHandler(handler, SocketOperationNone, handler->_registered);
479
511
  }
480
512
  }
481
- _changes.clear();
513
+
514
+ if(value)
515
+ {
516
+ handler->_ready = static_cast<SocketOperation>(handler->_ready | status);
517
+ }
518
+ else
519
+ {
520
+ handler->_ready = static_cast<SocketOperation>(handler->_ready & ~status);
521
+ }
522
+ checkReady(handler);
482
523
  }
483
- #endif
484
524
 
485
525
  void
486
- Selector::select(vector<pair<EventHandler*, SocketOperation> >& handlers, int timeout)
526
+ Selector::wakeup()
487
527
  {
488
- int ret = 0;
489
- int spuriousWakeup = 0;
490
- while(true)
528
+ if(_selecting && !_interrupted)
491
529
  {
492
- #if defined(ICE_USE_EPOLL)
493
- ret = epoll_wait(_queueFd, &_events[0], _events.size(), timeout > 0 ? timeout * 1000 : -1);
494
- #else
495
- assert(!_events.empty());
496
- if(timeout > 0)
497
- {
498
- struct timespec ts;
499
- ts.tv_sec = timeout;
500
- ts.tv_nsec = 0;
501
- ret = kevent(_queueFd, 0, 0, &_events[0], _events.size(), &ts);
502
- }
503
- else
504
- {
505
- ret = kevent(_queueFd, 0, 0, &_events[0], _events.size(), 0);
506
- }
507
- #endif
508
- if(ret == SOCKET_ERROR)
530
+ char c = 0;
531
+ while(true)
509
532
  {
510
- if(interrupted())
533
+ if(::write(_fdIntrWrite, &c, 1) == SOCKET_ERROR)
511
534
  {
512
- continue;
513
- }
535
+ if(interrupted())
536
+ {
537
+ continue;
538
+ }
514
539
 
515
- {
516
- Ice::SocketException ex(__FILE__, __LINE__, IceInternal::getSocketErrno());
517
- Ice::Error out(_instance->initializationData().logger);
518
- out << "fatal error: selector failed:\n" << ex;
540
+ throw Ice::SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
519
541
  }
520
- abort();
542
+ break;
521
543
  }
522
- else if(ret == 0 && timeout <= 0)
544
+ _interrupted = true;
545
+ }
546
+ }
547
+
548
+ void
549
+ Selector::startSelect()
550
+ {
551
+ if(_interrupted)
552
+ {
553
+ char c;
554
+ while(true)
523
555
  {
524
- if(++spuriousWakeup > 100)
556
+ ssize_t ret = ::read(_fdIntrRead, &c, 1);
557
+ if(ret == SOCKET_ERROR)
525
558
  {
526
- spuriousWakeup = 0;
527
- _instance->initializationData().logger->warning("spurious selector wakeup");
559
+ if(interrupted())
560
+ {
561
+ continue;
562
+ }
563
+ throw Ice::SocketException(__FILE__, __LINE__, IceInternal::getSocketErrno());
528
564
  }
529
- IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1));
530
- continue;
565
+ break;
531
566
  }
532
- break;
567
+ _interrupted = false;
568
+ }
569
+
570
+ #if !defined(ICE_USE_EPOLL)
571
+ if(!_changes.empty())
572
+ {
573
+ updateSelector();
533
574
  }
575
+ #endif
576
+ _selecting = true;
577
+
578
+ //
579
+ // If there are ready handlers, don't block in select, just do a non-blocking
580
+ // select to retrieve new ready handlers from the Java selector.
581
+ //
582
+ _selectNow = !_readyHandlers.empty();
583
+ }
584
+
585
+ void
586
+ Selector::finishSelect(vector<pair<EventHandler*, SocketOperation> >& handlers)
587
+ {
588
+ _selecting = false;
534
589
 
535
- if(ret == 0)
590
+ assert(handlers.empty());
591
+
592
+ #if defined(ICE_USE_POLL) || defined(ICE_USE_SELECT)
593
+ if(_interrupted) // Interrupted, we have to process the interrupt before returning any handlers
536
594
  {
537
- throw SelectorTimeoutException();
595
+ return;
538
596
  }
597
+ #endif
539
598
 
540
- assert(ret > 0);
541
- for(int i = 0; i < ret; ++i)
599
+ #if defined(ICE_USE_POLL)
600
+ for(vector<struct pollfd>::const_iterator r = _pollFdSet.begin(); r != _pollFdSet.end(); ++r)
601
+ #else
602
+ for(int i = 0; i < _count; ++i)
603
+ #endif
542
604
  {
543
605
  pair<EventHandler*, SocketOperation> p;
606
+
544
607
  #if defined(ICE_USE_EPOLL)
545
608
  struct epoll_event& ev = _events[i];
546
609
  p.first = reinterpret_cast<EventHandler*>(ev.data.ptr);
@@ -548,67 +611,468 @@ Selector::select(vector >& handlers, int ti
548
611
  SocketOperationRead : SocketOperationNone) |
549
612
  ((ev.events & (EPOLLOUT | EPOLLERR)) ?
550
613
  SocketOperationWrite : SocketOperationNone));
551
- #else
552
- struct kevent& ev = _events[i];
614
+ #elif defined(ICE_USE_KQUEUE)
615
+ struct kevent& ev = _events[static_cast<size_t>(i)];
553
616
  if(ev.flags & EV_ERROR)
554
617
  {
555
618
  Ice::Error out(_instance->initializationData().logger);
556
- out << "selector returned error:\n" << IceUtilInternal::errorToString(ev.data);
619
+ out << "selector returned error:\n" << IceUtilInternal::errorToString(static_cast<int>(ev.data));
557
620
  continue;
558
621
  }
559
622
  p.first = reinterpret_cast<EventHandler*>(ev.udata);
560
623
  p.second = (ev.filter == EVFILT_READ) ? SocketOperationRead : SocketOperationWrite;
561
- #endif
562
- handlers.push_back(p);
563
- }
564
- }
624
+ #elif defined(ICE_USE_SELECT)
625
+ //
626
+ // Round robin for the filedescriptors.
627
+ //
628
+ SOCKET fd;
629
+ p.second = SocketOperationNone;
630
+ if(i < _selectedReadFdSet.fd_count)
631
+ {
632
+ fd = _selectedReadFdSet.fd_array[i];
633
+ p.second = static_cast<SocketOperation>(p.second | SocketOperationRead);
634
+ }
635
+ else if(i < _selectedWriteFdSet.fd_count + _selectedReadFdSet.fd_count)
636
+ {
637
+ fd = _selectedWriteFdSet.fd_array[i - _selectedReadFdSet.fd_count];
638
+ p.second = static_cast<SocketOperation>(p.second | SocketOperationWrite);
639
+ }
640
+ else
641
+ {
642
+ fd = _selectedErrorFdSet.fd_array[i - _selectedReadFdSet.fd_count - _selectedWriteFdSet.fd_count];
643
+ p.second = static_cast<SocketOperation>(p.second | SocketOperationConnect);
644
+ }
565
645
 
566
- #elif defined(ICE_USE_CFSTREAM)
646
+ assert(fd != _fdIntrRead);
647
+ p.first = _handlers[fd];
648
+ #else
649
+ if(r->revents == 0)
650
+ {
651
+ continue;
652
+ }
567
653
 
568
- namespace
569
- {
654
+ SOCKET fd = r->fd;
655
+ assert(_handlers.find(fd) != _handlers.end());
656
+ p.first = _handlers[fd];
657
+ p.second = SocketOperationNone;
658
+ if(r->revents & (POLLIN | POLLERR | POLLHUP))
659
+ {
660
+ p.second = static_cast<SocketOperation>(p.second | SocketOperationRead);
661
+ }
662
+ if(r->revents & (POLLOUT | POLLERR | POLLHUP))
663
+ {
664
+ p.second = static_cast<SocketOperation>(p.second | SocketOperationWrite);
665
+ }
666
+ assert(p.second);
667
+ #endif
668
+ if(!p.first)
669
+ {
670
+ continue; // Interrupted
671
+ }
570
672
 
571
- void selectorInterrupt(void* info)
572
- {
573
- reinterpret_cast<Selector*>(info)->processInterrupt();
574
- }
673
+ map<EventHandlerPtr, SocketOperation>::iterator q = _readyHandlers.find(ICE_GET_SHARED_FROM_THIS(p.first));
575
674
 
576
- void eventHandlerSocketCallback(CFSocketRef, CFSocketCallBackType callbackType, CFDataRef, const void* d, void* info)
577
- {
578
- if(callbackType == kCFSocketReadCallBack)
579
- {
580
- reinterpret_cast<EventHandlerWrapper*>(info)->readyCallback(SocketOperationRead);
581
- }
582
- else if(callbackType == kCFSocketWriteCallBack)
583
- {
584
- reinterpret_cast<EventHandlerWrapper*>(info)->readyCallback(SocketOperationWrite);
675
+ if(q != _readyHandlers.end()) // Handler will be added by the loop below
676
+ {
677
+ q->second = p.second; // We just remember which operations are ready here.
678
+ }
679
+ else
680
+ {
681
+ handlers.push_back(p);
682
+ }
585
683
  }
586
- else if(callbackType == kCFSocketConnectCallBack)
684
+
685
+ for(map<EventHandlerPtr, SocketOperation>::iterator q = _readyHandlers.begin(); q != _readyHandlers.end(); ++q)
587
686
  {
588
- reinterpret_cast<EventHandlerWrapper*>(info)->readyCallback(SocketOperationConnect,
589
- d ? *reinterpret_cast<const SInt32*>(d) : 0);
687
+ pair<EventHandler*, SocketOperation> p;
688
+ p.first = q->first.get();
689
+ p.second = static_cast<SocketOperation>(p.first->_ready & ~p.first->_disabled & p.first->_registered);
690
+ p.second = static_cast<SocketOperation>(p.second | q->second);
691
+ if(p.second)
692
+ {
693
+ handlers.push_back(p);
694
+ }
695
+
696
+ //
697
+ // Reset the operation, it's only used by this method to temporarly store the socket status
698
+ // return by the select operation above.
699
+ //
700
+ q->second = SocketOperationNone;
590
701
  }
591
702
  }
592
703
 
593
- class SelectorHelperThread : public IceUtil::Thread
704
+ void
705
+ Selector::select(int timeout)
594
706
  {
595
- public:
596
-
597
- SelectorHelperThread(Selector& selector) : _selector(selector)
707
+ if(_selectNow)
598
708
  {
709
+ timeout = 0;
599
710
  }
600
-
601
- virtual void run()
711
+ else if(timeout > 0)
602
712
  {
603
- _selector.run();
713
+ timeout = timeout * 1000;
714
+ }
715
+ else
716
+ {
717
+ timeout = -1;
604
718
  }
605
719
 
606
- private:
607
-
608
- Selector& _selector;
609
- };
610
-
611
- CFOptionFlags
720
+ int spuriousWakeup = 0;
721
+ while(true)
722
+ {
723
+ #if defined(ICE_USE_EPOLL)
724
+ _count = epoll_wait(_queueFd, &_events[0], _events.size(), timeout);
725
+ #elif defined(ICE_USE_KQUEUE)
726
+ assert(!_events.empty());
727
+ if(timeout >= 0)
728
+ {
729
+ struct timespec ts;
730
+ ts.tv_sec = timeout;
731
+ ts.tv_nsec = 0;
732
+ _count = kevent(_queueFd, 0, 0, &_events[0], static_cast<int>(_events.size()), &ts);
733
+ }
734
+ else
735
+ {
736
+ _count = kevent(_queueFd, 0, 0, &_events[0], static_cast<int>(_events.size()), 0);
737
+ }
738
+ #elif defined(ICE_USE_SELECT)
739
+ fd_set* rFdSet = fdSetCopy(_selectedReadFdSet, _readFdSet);
740
+ fd_set* wFdSet = fdSetCopy(_selectedWriteFdSet, _writeFdSet);
741
+ fd_set* eFdSet = fdSetCopy(_selectedErrorFdSet, _errorFdSet);
742
+ if(timeout >= 0)
743
+ {
744
+ struct timeval tv;
745
+ tv.tv_sec = timeout;
746
+ tv.tv_usec = 0;
747
+ _count = ::select(0, rFdSet, wFdSet, eFdSet, &tv); // The first parameter is ignored on Windows
748
+ }
749
+ else
750
+ {
751
+ _count = ::select(0, rFdSet, wFdSet, eFdSet, 0); // The first parameter is ignored on Windows
752
+ }
753
+ #else
754
+ _count = poll(&_pollFdSet[0], _pollFdSet.size(), timeout);
755
+ #endif
756
+
757
+ if(_count == SOCKET_ERROR)
758
+ {
759
+ if(interrupted())
760
+ {
761
+ continue;
762
+ }
763
+
764
+ Ice::SocketException ex(__FILE__, __LINE__, IceInternal::getSocketErrno());
765
+ Ice::Error out(_instance->initializationData().logger);
766
+ out << "selector failed:\n" << ex;
767
+ IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(5)); // Sleep 5s to avoid looping
768
+ }
769
+ else if(_count == 0 && timeout < 0)
770
+ {
771
+ if(++spuriousWakeup > 100)
772
+ {
773
+ spuriousWakeup = 0;
774
+ _instance->initializationData().logger->warning("spurious selector wakeup");
775
+ }
776
+ IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(1));
777
+ continue;
778
+ }
779
+ break;
780
+ }
781
+
782
+ if(_count == 0 && !_selectNow)
783
+ {
784
+ throw SelectorTimeoutException();
785
+ }
786
+ }
787
+
788
+ void
789
+ Selector::checkReady(EventHandler* handler)
790
+ {
791
+ if(handler->_ready & ~handler->_disabled & handler->_registered)
792
+ {
793
+ _readyHandlers.insert(make_pair(ICE_GET_SHARED_FROM_THIS(handler), SocketOperationNone));
794
+ wakeup();
795
+ }
796
+ else
797
+ {
798
+ map<EventHandlerPtr, SocketOperation>::iterator p = _readyHandlers.find(ICE_GET_SHARED_FROM_THIS(handler));
799
+ if(p != _readyHandlers.end())
800
+ {
801
+ _readyHandlers.erase(p);
802
+ }
803
+ }
804
+ }
805
+
806
+ void
807
+ Selector::updateSelector()
808
+ {
809
+ #if defined(ICE_USE_KQUEUE)
810
+ int rs = kevent(_queueFd, &_changes[0], static_cast<int>(_changes.size()),
811
+ &_changes[0], static_cast<int>(_changes.size()), &zeroTimeout);
812
+ if(rs < 0)
813
+ {
814
+ Ice::Error out(_instance->initializationData().logger);
815
+ out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
816
+ }
817
+ else
818
+ {
819
+ for(int i = 0; i < rs; ++i)
820
+ {
821
+ //
822
+ // Check for errors, we ignore EINPROGRESS that started showing up with macOS Sierra
823
+ // and which occurs when another thread removes the FD from the kqueue (see ICE-7419).
824
+ //
825
+ if(_changes[static_cast<size_t>(i)].flags & EV_ERROR &&
826
+ _changes[static_cast<size_t>(i)].data != EINPROGRESS)
827
+ {
828
+ Ice::Error out(_instance->initializationData().logger);
829
+ out << "error while updating selector:\n"
830
+ << IceUtilInternal::errorToString(static_cast<int>(_changes[static_cast<size_t>(i)].data));
831
+ }
832
+ }
833
+ }
834
+ _changes.clear();
835
+ #elif !defined(ICE_USE_EPOLL)
836
+ assert(!_selecting);
837
+
838
+ for(vector<pair<EventHandler*, SocketOperation> >::const_iterator p = _changes.begin(); p != _changes.end(); ++p)
839
+ {
840
+ EventHandler* handler = p->first;
841
+ SocketOperation status = p->second;
842
+
843
+ SOCKET fd = handler->getNativeInfo()->fd();
844
+ if(status)
845
+ {
846
+ #if defined(ICE_USE_SELECT)
847
+ if(status & SocketOperationRead)
848
+ {
849
+ FD_SET(fd, &_readFdSet);
850
+ }
851
+ else
852
+ {
853
+ FD_CLR(fd, &_readFdSet);
854
+ }
855
+ if(status & SocketOperationWrite)
856
+ {
857
+ FD_SET(fd, &_writeFdSet);
858
+ }
859
+ else
860
+ {
861
+ FD_CLR(fd, &_writeFdSet);
862
+ }
863
+ if(status & SocketOperationConnect)
864
+ {
865
+ FD_SET(fd, &_writeFdSet);
866
+ FD_SET(fd, &_errorFdSet);
867
+ }
868
+ else
869
+ {
870
+ FD_CLR(fd, &_writeFdSet);
871
+ FD_CLR(fd, &_errorFdSet);
872
+ }
873
+ _handlers[fd] = handler;
874
+ #else
875
+ short events = 0;
876
+ if(status & SocketOperationRead)
877
+ {
878
+ events |= POLLIN;
879
+ }
880
+ if(status & SocketOperationWrite)
881
+ {
882
+ events |= POLLOUT;
883
+ }
884
+ map<SOCKET, EventHandler*>::const_iterator q = _handlers.find(fd);
885
+ if(q == _handlers.end())
886
+ {
887
+ struct pollfd pollFd;
888
+ pollFd.fd = fd;
889
+ pollFd.events = events;
890
+ pollFd.revents = 0;
891
+ _pollFdSet.push_back(pollFd);
892
+ _handlers.insert(make_pair(fd, handler));
893
+ }
894
+ else
895
+ {
896
+ for(vector<struct pollfd>::iterator r = _pollFdSet.begin(); r != _pollFdSet.end(); ++r)
897
+ {
898
+ if(r->fd == fd)
899
+ {
900
+ r->events = events;
901
+ break;
902
+ }
903
+ }
904
+ }
905
+ #endif
906
+ }
907
+ else
908
+ {
909
+ #if defined(ICE_USE_SELECT)
910
+ FD_CLR(fd, &_readFdSet);
911
+ FD_CLR(fd, &_writeFdSet);
912
+ FD_CLR(fd, &_errorFdSet);
913
+ #else
914
+ for(vector<struct pollfd>::iterator r = _pollFdSet.begin(); r != _pollFdSet.end(); ++r)
915
+ {
916
+ if(r->fd == fd)
917
+ {
918
+ _pollFdSet.erase(r);
919
+ break;
920
+ }
921
+ }
922
+ #endif
923
+ _handlers.erase(fd);
924
+ }
925
+ }
926
+ _changes.clear();
927
+ #endif
928
+ }
929
+
930
+ void
931
+ Selector::updateSelectorForEventHandler(EventHandler* handler,
932
+ ICE_MAYBE_UNUSED SocketOperation remove,
933
+ ICE_MAYBE_UNUSED SocketOperation add)
934
+ {
935
+ #if defined(ICE_USE_EPOLL)
936
+ SocketOperation previous = handler->_registered;
937
+ previous = static_cast<SocketOperation>(previous & ~add);
938
+ previous = static_cast<SocketOperation>(previous | remove);
939
+ SOCKET fd = handler->getNativeInfo()->fd();
940
+ assert(fd != INVALID_SOCKET);
941
+ epoll_event event;
942
+ memset(&event, 0, sizeof(epoll_event));
943
+ event.data.ptr = handler;
944
+ SocketOperation status = handler->_registered;
945
+ if(handler->_disabled)
946
+ {
947
+ status = static_cast<SocketOperation>(status & ~handler->_disabled);
948
+ previous = static_cast<SocketOperation>(previous & ~handler->_disabled);
949
+ }
950
+ if(status & SocketOperationRead)
951
+ {
952
+ event.events |= EPOLLIN;
953
+ }
954
+ if(status & SocketOperationWrite)
955
+ {
956
+ event.events |= EPOLLOUT;
957
+ }
958
+ int op;
959
+ if(!previous && status)
960
+ {
961
+ op = EPOLL_CTL_ADD;
962
+ }
963
+ else if(previous && !status)
964
+ {
965
+ op = EPOLL_CTL_DEL;
966
+ }
967
+ else if(previous == status)
968
+ {
969
+ return;
970
+ }
971
+ else
972
+ {
973
+ op = EPOLL_CTL_MOD;
974
+ }
975
+ if(epoll_ctl(_queueFd, op, fd, &event) != 0)
976
+ {
977
+ Ice::Error out(_instance->initializationData().logger);
978
+ out << "error while updating selector:\n" << IceUtilInternal::errorToString(IceInternal::getSocketErrno());
979
+ }
980
+ #elif defined(ICE_USE_KQUEUE)
981
+ SOCKET fd = handler->getNativeInfo()->fd();
982
+ assert(fd != INVALID_SOCKET);
983
+ if(remove & SocketOperationRead)
984
+ {
985
+ struct kevent ev;
986
+ EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, handler);
987
+ _changes.push_back(ev);
988
+ }
989
+ if(remove & SocketOperationWrite)
990
+ {
991
+ struct kevent ev;
992
+ EV_SET(&ev, fd, EVFILT_WRITE, EV_DELETE, 0, 0, handler);
993
+ _changes.push_back(ev);
994
+ }
995
+ if(add & SocketOperationRead)
996
+ {
997
+ struct kevent ev;
998
+ EV_SET(&ev, fd, EVFILT_READ, EV_ADD | (handler->_disabled & SocketOperationRead ? EV_DISABLE : 0), 0, 0,
999
+ handler);
1000
+ _changes.push_back(ev);
1001
+ }
1002
+ if(add & SocketOperationWrite)
1003
+ {
1004
+ struct kevent ev;
1005
+ EV_SET(&ev, fd, EVFILT_WRITE, EV_ADD | (handler->_disabled & SocketOperationWrite ? EV_DISABLE : 0), 0, 0,
1006
+ handler);
1007
+ _changes.push_back(ev);
1008
+ }
1009
+ if(_selecting)
1010
+ {
1011
+ updateSelector();
1012
+ }
1013
+ #else
1014
+ _changes.push_back(make_pair(handler, static_cast<SocketOperation>(handler->_registered & ~handler->_disabled)));
1015
+ wakeup();
1016
+ #endif
1017
+ checkReady(handler);
1018
+ }
1019
+
1020
+ #elif defined(ICE_USE_CFSTREAM)
1021
+
1022
+ namespace
1023
+ {
1024
+
1025
+ void selectorInterrupt(void* info)
1026
+ {
1027
+ reinterpret_cast<Selector*>(info)->processInterrupt();
1028
+ }
1029
+
1030
+ void eventHandlerSocketCallback(CFSocketRef, CFSocketCallBackType callbackType, CFDataRef, const void* d, void* info)
1031
+ {
1032
+ if(callbackType == kCFSocketReadCallBack)
1033
+ {
1034
+ reinterpret_cast<EventHandlerWrapper*>(info)->readyCallback(SocketOperationRead);
1035
+ }
1036
+ else if(callbackType == kCFSocketWriteCallBack)
1037
+ {
1038
+ reinterpret_cast<EventHandlerWrapper*>(info)->readyCallback(SocketOperationWrite);
1039
+ }
1040
+ else if(callbackType == kCFSocketConnectCallBack)
1041
+ {
1042
+ reinterpret_cast<EventHandlerWrapper*>(info)->readyCallback(SocketOperationConnect,
1043
+ d ? *reinterpret_cast<const SInt32*>(d) : 0);
1044
+ }
1045
+ }
1046
+
1047
+ class SelectorHelperThread : public IceUtil::Thread
1048
+ {
1049
+ public:
1050
+
1051
+ SelectorHelperThread(Selector& selector) : _selector(selector)
1052
+ {
1053
+ }
1054
+
1055
+ virtual void run()
1056
+ {
1057
+ _selector.run();
1058
+
1059
+ #if TARGET_IPHONE_SIMULATOR != 0
1060
+ //
1061
+ // Workaround for CFSocket bug where the CFSocketManager thread crashes if an
1062
+ // invalidated socket is being processed for reads/writes. We add this sleep
1063
+ // mostly to prevent spurious crashes with testing. This bug is very unlikely
1064
+ // to be hit otherwise.
1065
+ //
1066
+ IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(100));
1067
+ #endif
1068
+ }
1069
+
1070
+ private:
1071
+
1072
+ Selector& _selector;
1073
+ };
1074
+
1075
+ CFOptionFlags
612
1076
  toCFCallbacks(SocketOperation op)
613
1077
  {
614
1078
  CFOptionFlags cbs = 0;
@@ -629,45 +1093,38 @@ toCFCallbacks(SocketOperation op)
629
1093
 
630
1094
  }
631
1095
 
632
- EventHandlerWrapper::EventHandlerWrapper(const EventHandlerPtr& handler, Selector& selector) :
633
- _handler(handler),
634
- _nativeInfo(StreamNativeInfoPtr::dynamicCast(handler->getNativeInfo())),
1096
+ EventHandlerWrapper::EventHandlerWrapper(EventHandler* handler, Selector& selector) :
1097
+ _handler(ICE_GET_SHARED_FROM_THIS(handler)),
1098
+ _streamNativeInfo(StreamNativeInfoPtr::dynamicCast(handler->getNativeInfo())),
635
1099
  _selector(selector),
636
1100
  _ready(SocketOperationNone),
637
1101
  _finish(false)
638
1102
  {
639
- if(!StreamNativeInfoPtr::dynamicCast(handler->getNativeInfo()))
1103
+ if(_streamNativeInfo)
1104
+ {
1105
+ _streamNativeInfo->initStreams(this);
1106
+ }
1107
+ else if(handler->getNativeInfo())
640
1108
  {
641
1109
  SOCKET fd = handler->getNativeInfo()->fd();
642
1110
  CFSocketContext ctx = { 0, this, 0, 0, 0 };
643
- _socket = CFSocketCreateWithNative(kCFAllocatorDefault,
644
- fd,
645
- kCFSocketReadCallBack |
646
- kCFSocketWriteCallBack |
647
- kCFSocketConnectCallBack,
648
- eventHandlerSocketCallback,
649
- &ctx);
1111
+ _socket.reset(CFSocketCreateWithNative(kCFAllocatorDefault,
1112
+ fd,
1113
+ kCFSocketReadCallBack |
1114
+ kCFSocketWriteCallBack |
1115
+ kCFSocketConnectCallBack,
1116
+ eventHandlerSocketCallback,
1117
+ &ctx));
650
1118
 
651
1119
  // Disable automatic re-enabling of callbacks and closing of the native socket.
652
- CFSocketSetSocketFlags(_socket, 0);
653
- CFSocketDisableCallBacks(_socket, kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack);
654
- _source = CFSocketCreateRunLoopSource(kCFAllocatorDefault, _socket, 0);
655
- }
656
- else
657
- {
658
- _socket = 0;
659
- _source = 0;
660
- _nativeInfo->initStreams(this);
1120
+ CFSocketSetSocketFlags(_socket.get(), 0);
1121
+ CFSocketDisableCallBacks(_socket.get(), kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack);
1122
+ _source.reset(CFSocketCreateRunLoopSource(kCFAllocatorDefault, _socket.get(), 0));
661
1123
  }
662
1124
  }
663
1125
 
664
1126
  EventHandlerWrapper::~EventHandlerWrapper()
665
1127
  {
666
- if(_socket)
667
- {
668
- CFRelease(_socket);
669
- CFRelease(_source);
670
- }
671
1128
  }
672
1129
 
673
1130
  void
@@ -678,37 +1135,37 @@ EventHandlerWrapper::updateRunLoop()
678
1135
 
679
1136
  if(_socket)
680
1137
  {
681
- CFSocketDisableCallBacks(_socket, kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack);
1138
+ CFSocketDisableCallBacks(_socket.get(), kCFSocketReadCallBack | kCFSocketWriteCallBack | kCFSocketConnectCallBack);
682
1139
  if(op)
683
1140
  {
684
- CFSocketEnableCallBacks(_socket, toCFCallbacks(op));
1141
+ CFSocketEnableCallBacks(_socket.get(), toCFCallbacks(op));
685
1142
  }
686
1143
 
687
- if(op && !CFRunLoopContainsSource(CFRunLoopGetCurrent(), _source, kCFRunLoopDefaultMode))
1144
+ if(op && !CFRunLoopContainsSource(CFRunLoopGetCurrent(), _source.get(), kCFRunLoopDefaultMode))
688
1145
  {
689
- CFRunLoopAddSource(CFRunLoopGetCurrent(), _source, kCFRunLoopDefaultMode);
1146
+ CFRunLoopAddSource(CFRunLoopGetCurrent(), _source.get(), kCFRunLoopDefaultMode);
690
1147
  }
691
- else if(!op && CFRunLoopContainsSource(CFRunLoopGetCurrent(), _source, kCFRunLoopDefaultMode))
1148
+ else if(!op && CFRunLoopContainsSource(CFRunLoopGetCurrent(), _source.get(), kCFRunLoopDefaultMode))
692
1149
  {
693
- CFRunLoopRemoveSource(CFRunLoopGetCurrent(), _source, kCFRunLoopDefaultMode);
1150
+ CFRunLoopRemoveSource(CFRunLoopGetCurrent(), _source.get(), kCFRunLoopDefaultMode);
694
1151
  }
695
1152
 
696
1153
  if(_finish)
697
1154
  {
698
- CFSocketInvalidate(_socket);
1155
+ CFSocketInvalidate(_socket.get());
699
1156
  }
700
1157
  }
701
1158
  else
702
1159
  {
703
- SocketOperation readyOp = _nativeInfo->registerWithRunLoop(op);
1160
+ SocketOperation readyOp = _streamNativeInfo->registerWithRunLoop(op);
704
1161
  if(!(op & (SocketOperationWrite | SocketOperationConnect)) || _ready & SocketOperationWrite)
705
1162
  {
706
- _nativeInfo->unregisterFromRunLoop(SocketOperationWrite, false);
1163
+ _streamNativeInfo->unregisterFromRunLoop(SocketOperationWrite, false);
707
1164
  }
708
1165
 
709
1166
  if(!(op & (SocketOperationRead | SocketOperationConnect)) || _ready & SocketOperationRead)
710
1167
  {
711
- _nativeInfo->unregisterFromRunLoop(SocketOperationRead, false);
1168
+ _streamNativeInfo->unregisterFromRunLoop(SocketOperationRead, false);
712
1169
  }
713
1170
 
714
1171
  if(readyOp)
@@ -718,7 +1175,7 @@ EventHandlerWrapper::updateRunLoop()
718
1175
 
719
1176
  if(_finish)
720
1177
  {
721
- _nativeInfo->closeStreams();
1178
+ _streamNativeInfo->closeStreams();
722
1179
  }
723
1180
  }
724
1181
  }
@@ -740,7 +1197,7 @@ EventHandlerWrapper::ready(SocketOperation op, int error)
740
1197
  // stream (which can't be used from another thread than the run loop thread if
741
1198
  // it's registered with a run loop).
742
1199
  //
743
- op = _nativeInfo->unregisterFromRunLoop(op, error != 0);
1200
+ op = _streamNativeInfo->unregisterFromRunLoop(op, error != 0);
744
1201
  }
745
1202
 
746
1203
  op = static_cast<SocketOperation>(_handler->_registered & op);
@@ -753,23 +1210,25 @@ EventHandlerWrapper::ready(SocketOperation op, int error)
753
1210
  {
754
1211
  if(op & SocketOperationConnect)
755
1212
  {
756
- _nativeInfo->setConnectError(error);
1213
+ _streamNativeInfo->setConnectError(error);
757
1214
  }
758
1215
  }
759
1216
 
760
1217
  _ready = static_cast<SocketOperation>(_ready | op);
761
- if(!(_handler->_disabled & op))
762
- {
763
- _selector.addReadyHandler(this);
764
- }
1218
+ checkReady();
765
1219
  }
766
1220
 
767
- void
1221
+ bool
768
1222
  EventHandlerWrapper::checkReady()
769
1223
  {
770
- if(_ready & _handler->_registered)
1224
+ if((_ready | _handler->_ready) & ~_handler->_disabled & _handler->_registered)
771
1225
  {
772
1226
  _selector.addReadyHandler(this);
1227
+ return false;
1228
+ }
1229
+ else
1230
+ {
1231
+ return _handler->getNativeInfo() && !_finish;
773
1232
  }
774
1233
  }
775
1234
 
@@ -777,7 +1236,7 @@ SocketOperation
777
1236
  EventHandlerWrapper::readyOp()
778
1237
  {
779
1238
  assert(!(~_handler->_registered & _ready));
780
- SocketOperation op = static_cast<SocketOperation>(~_handler->_disabled & _ready);
1239
+ SocketOperation op = static_cast<SocketOperation>(~_handler->_disabled & (_ready | _handler->_ready));
781
1240
  _ready = static_cast<SocketOperation>(~op & _ready);
782
1241
  return op;
783
1242
  }
@@ -795,15 +1254,16 @@ EventHandlerWrapper::update(SocketOperation remove, SocketOperation add)
795
1254
 
796
1255
  // Clear ready flags which might not be valid anymore.
797
1256
  _ready = static_cast<SocketOperation>(_ready & _handler->_registered);
798
- return true;
1257
+ return _handler->getNativeInfo();
799
1258
  }
800
1259
 
801
- void
1260
+ bool
802
1261
  EventHandlerWrapper::finish()
803
1262
  {
804
1263
  _finish = true;
805
1264
  _ready = SocketOperationNone;
806
1265
  _handler->_registered = SocketOperationNone;
1266
+ return _handler->getNativeInfo();
807
1267
  }
808
1268
 
809
1269
  Selector::Selector(const InstancePtr& instance) : _instance(instance), _destroyed(false)
@@ -812,7 +1272,7 @@ Selector::Selector(const InstancePtr& instance) : _instance(instance), _destroye
812
1272
  memset(&ctx, 0, sizeof(CFRunLoopSourceContext));
813
1273
  ctx.info = this;
814
1274
  ctx.perform = selectorInterrupt;
815
- _source = CFRunLoopSourceCreate(0, 0, &ctx);
1275
+ _source.reset(CFRunLoopSourceCreate(0, 0, &ctx));
816
1276
  _runLoop = 0;
817
1277
 
818
1278
  _thread = new SelectorHelperThread(*this);
@@ -832,27 +1292,33 @@ Selector::~Selector()
832
1292
  void
833
1293
  Selector::destroy()
834
1294
  {
835
- Lock sync(*this);
836
-
837
- //
838
- // Make sure any pending changes are processed to ensure remaining
839
- // streams/sockets are closed.
840
- //
841
- _destroyed = true;
842
- while(!_changes.empty())
843
1295
  {
844
- CFRunLoopSourceSignal(_source);
1296
+ Lock sync(*this);
1297
+
1298
+ //
1299
+ // Make sure any pending changes are processed to ensure remaining
1300
+ // streams/sockets are closed.
1301
+ //
1302
+ _destroyed = true;
1303
+ CFRunLoopSourceSignal(_source.get());
845
1304
  CFRunLoopWakeUp(_runLoop);
846
1305
 
847
- wait();
1306
+ while(!_changes.empty())
1307
+ {
1308
+ CFRunLoopSourceSignal(_source.get());
1309
+ CFRunLoopWakeUp(_runLoop);
1310
+
1311
+ wait();
1312
+ }
848
1313
  }
849
1314
 
850
1315
  _thread->getThreadControl().join();
851
1316
  _thread = 0;
852
1317
 
853
- CFRelease(_source);
1318
+ Lock sync(*this);
1319
+ _source.reset(0);
854
1320
 
855
- assert(_wrappers.empty());
1321
+ //assert(_wrappers.empty());
856
1322
  _readyHandlers.clear();
857
1323
  _selectedHandlers.clear();
858
1324
  }
@@ -869,7 +1335,6 @@ Selector::update(EventHandler* handler, SocketOperation remove, SocketOperation
869
1335
  {
870
1336
  Lock sync(*this);
871
1337
  const EventHandlerWrapperPtr& wrapper = _wrappers[handler];
872
- assert(wrapper);
873
1338
  if(wrapper->update(remove, add))
874
1339
  {
875
1340
  _changes.insert(wrapper);
@@ -911,534 +1376,162 @@ Selector::finish(EventHandler* handler, bool closeNow)
911
1376
  std::map<EventHandler*, EventHandlerWrapperPtr>::iterator p = _wrappers.find(handler);
912
1377
  assert(p != _wrappers.end());
913
1378
  EventHandlerWrapperPtr wrapper = p->second;
914
- wrapper->finish();
915
- _wrappers.erase(p);
916
- _changes.insert(wrapper);
917
- notify();
918
- return closeNow;
919
- }
920
-
921
- void
922
- Selector::select(std::vector<std::pair<EventHandler*, SocketOperation> >& handlers, int timeout)
923
- {
924
- Lock sync(*this);
925
-
926
- //
927
- // Re-enable callbacks for previously selected handlers.
928
- //
929
- if(!_selectedHandlers.empty())
930
- {
931
- vector<pair<EventHandlerWrapperPtr, SocketOperation> >::const_iterator p;
932
- for(p = _selectedHandlers.begin(); p != _selectedHandlers.end(); ++p)
933
- {
934
- if(!p->first->_finish)
935
- {
936
- _changes.insert(p->first);
937
- }
938
- }
939
- _selectedHandlers.clear();
940
- }
941
-
942
- //
943
- // Wait for handlers to be ready.
944
- //
945
- handlers.clear();
946
- while(_selectedHandlers.empty())
947
- {
948
- while(!_changes.empty())
949
- {
950
- CFRunLoopSourceSignal(_source);
951
- CFRunLoopWakeUp(_runLoop);
952
-
953
- wait();
954
- }
955
-
956
- if(_readyHandlers.empty())
957
- {
958
- if(timeout > 0)
959
- {
960
- if(!timedWait(IceUtil::Time::seconds(timeout)))
961
- {
962
- break;
963
- }
964
- }
965
- else
966
- {
967
- wait();
968
- }
969
- }
970
-
971
- if(!_changes.empty())
972
- {
973
- continue; // Make sure to process the changes first.
974
- }
975
-
976
- for(vector<EventHandlerWrapperPtr>::const_iterator p = _readyHandlers.begin(); p != _readyHandlers.end(); ++p)
977
- {
978
- SocketOperation op = (*p)->readyOp();
979
- if(op)
980
- {
981
- _selectedHandlers.push_back(pair<EventHandlerWrapperPtr, SocketOperation>(*p, op));
982
- handlers.push_back(pair<EventHandler*, SocketOperation>((*p)->_handler.get(), op));
983
- }
984
- }
985
- _readyHandlers.clear();
986
- }
987
- }
988
-
989
- void
990
- Selector::processInterrupt()
991
- {
992
- Lock sync(*this);
993
- if(!_changes.empty())
994
- {
995
- for(set<EventHandlerWrapperPtr>::const_iterator p = _changes.begin(); p != _changes.end(); ++p)
996
- {
997
- (*p)->updateRunLoop();
998
- }
999
- _changes.clear();
1000
- notify();
1001
- }
1002
- if(_destroyed)
1003
- {
1004
- CFRunLoopStop(_runLoop);
1005
- }
1006
- }
1007
-
1008
- void
1009
- Selector::ready(EventHandlerWrapper* wrapper, SocketOperation op, int error)
1010
- {
1011
- Lock sync(*this);
1012
- wrapper->ready(op, error);
1013
- }
1014
-
1015
- void
1016
- Selector::addReadyHandler(EventHandlerWrapper* wrapper)
1017
- {
1018
- // Called from ready()
1019
- _readyHandlers.push_back(wrapper);
1020
- if(_readyHandlers.size() == 1)
1021
- {
1022
- notify();
1023
- }
1024
- }
1025
-
1026
- void
1027
- Selector::run()
1028
- {
1379
+ if(wrapper->finish())
1029
1380
  {
1030
- Lock sync(*this);
1031
- _runLoop = CFRunLoopGetCurrent();
1381
+ _changes.insert(wrapper);
1032
1382
  notify();
1033
1383
  }
1034
-
1035
- CFRunLoopAddSource(CFRunLoopGetCurrent(), _source, kCFRunLoopDefaultMode);
1036
- CFRunLoopRun();
1037
- CFRunLoopRemoveSource(CFRunLoopGetCurrent(), _source, kCFRunLoopDefaultMode);
1038
- }
1039
-
1040
- #elif defined(ICE_USE_SELECT) || defined(ICE_USE_POLL)
1041
-
1042
- Selector::Selector(const InstancePtr& instance) : _instance(instance), _selecting(false), _interrupted(false)
1043
- {
1044
- SOCKET fds[2];
1045
- createPipe(fds);
1046
- _fdIntrRead = fds[0];
1047
- _fdIntrWrite = fds[1];
1048
- #if defined(ICE_USE_SELECT)
1049
- FD_ZERO(&_readFdSet);
1050
- FD_ZERO(&_writeFdSet);
1051
- FD_ZERO(&_errorFdSet);
1052
- FD_SET(_fdIntrRead, &_readFdSet);
1053
- #else
1054
- struct pollfd pollFd;
1055
- pollFd.fd = _fdIntrRead;
1056
- pollFd.events = POLLIN;
1057
- _pollFdSet.push_back(pollFd);
1058
- #endif
1059
- }
1060
-
1061
- Selector::~Selector()
1062
- {
1063
- try
1064
- {
1065
- closeSocket(_fdIntrWrite);
1066
- }
1067
- catch(const Ice::LocalException& ex)
1068
- {
1069
- Ice::Error out(_instance->initializationData().logger);
1070
- out << "exception in selector while calling closeSocket():\n" << ex;
1071
- }
1072
-
1073
- try
1074
- {
1075
- closeSocket(_fdIntrRead);
1076
- }
1077
- catch(const Ice::LocalException& ex)
1078
- {
1079
- Ice::Error out(_instance->initializationData().logger);
1080
- out << "exception in selector while calling closeSocket():\n" << ex;
1081
- }
1082
- }
1083
-
1084
- void
1085
- Selector::destroy()
1086
- {
1087
- #if !defined(ICE_USE_SELECT) && !defined(ICE_USE_POLL)
1088
- assert(_events.empty());
1089
- #endif
1090
- }
1091
-
1092
- void
1093
- Selector::update(EventHandler* handler, SocketOperation remove, SocketOperation add)
1094
- {
1095
- SocketOperation previous = handler->_registered;
1096
- handler->_registered = static_cast<SocketOperation>(handler->_registered & ~remove);
1097
- handler->_registered = static_cast<SocketOperation>(handler->_registered | add);
1098
- if(previous == handler->_registered)
1099
- {
1100
- return;
1101
- }
1102
-
1103
- updateImpl(handler);
1384
+ _wrappers.erase(p);
1385
+ return closeNow;
1104
1386
  }
1105
1387
 
1106
1388
  void
1107
- Selector::enable(EventHandler* handler, SocketOperation status)
1389
+ Selector::ready(EventHandler* handler, SocketOperation status, bool value)
1108
1390
  {
1109
- if(!(handler->_disabled & status))
1110
- {
1111
- return;
1112
- }
1113
- handler->_disabled = static_cast<SocketOperation>(handler->_disabled & ~status);
1114
-
1115
- if(handler->_registered & status)
1391
+ if(((handler->_ready & status) != 0) == value)
1116
1392
  {
1117
- updateImpl(handler);
1393
+ return; // Nothing to do if ready state already correctly set.
1118
1394
  }
1119
- }
1120
1395
 
1121
- void
1122
- Selector::disable(EventHandler* handler, SocketOperation status)
1123
- {
1124
- if(handler->_disabled & status)
1396
+ if(value)
1125
1397
  {
1126
- return;
1398
+ handler->_ready = static_cast<SocketOperation>(handler->_ready | status);
1127
1399
  }
1128
- handler->_disabled = static_cast<SocketOperation>(handler->_disabled | status);
1129
-
1130
- if(handler->_registered & status)
1400
+ else
1131
1401
  {
1132
- updateImpl(handler);
1402
+ handler->_ready = static_cast<SocketOperation>(handler->_ready & ~status);
1133
1403
  }
1134
- }
1135
1404
 
1136
- bool
1137
- Selector::finish(EventHandler* handler, bool closeNow)
1138
- {
1139
- if(handler->_registered)
1140
- {
1141
- update(handler, handler->_registered, SocketOperationNone);
1142
- return false; // Don't close now if selecting.
1143
- }
1144
- return closeNow;
1405
+ Lock sync(*this);
1406
+ std::map<EventHandler*, EventHandlerWrapperPtr>::iterator p = _wrappers.find(handler);
1407
+ assert(p != _wrappers.end());
1408
+ p->second->checkReady();
1145
1409
  }
1146
1410
 
1147
1411
  void
1148
1412
  Selector::startSelect()
1149
1413
  {
1150
- if(_interrupted)
1151
- {
1152
- char c;
1153
- while(true)
1154
- {
1155
- ssize_t ret;
1156
- #ifdef _WIN32
1157
- ret = ::recv(_fdIntrRead, &c, 1, 0);
1158
- #else
1159
- ret = ::read(_fdIntrRead, &c, 1);
1160
- #endif
1161
- if(ret == SOCKET_ERROR)
1162
- {
1163
- if(interrupted())
1164
- {
1165
- continue;
1166
- }
1167
-
1168
- Ice::SocketException ex(__FILE__, __LINE__);
1169
- ex.error = IceInternal::getSocketErrno();
1170
- throw ex;
1171
- }
1172
- break;
1173
- }
1174
- _interrupted = false;
1414
+ Lock sync(*this);
1175
1415
 
1176
- if(!_changes.empty())
1416
+ //
1417
+ // Re-enable callbacks for previously selected handlers.
1418
+ //
1419
+ vector<pair<EventHandlerWrapperPtr, SocketOperation> >::const_iterator p;
1420
+ for(p = _selectedHandlers.begin(); p != _selectedHandlers.end(); ++p)
1421
+ {
1422
+ if(p->first->checkReady())
1177
1423
  {
1178
- updateSelector();
1424
+ _changes.insert(p->first);
1179
1425
  }
1180
1426
  }
1181
- _selecting = true;
1427
+ _selectedHandlers.clear();
1182
1428
  }
1183
1429
 
1184
1430
  void
1185
- Selector::finishSelect()
1431
+ Selector::finishSelect(std::vector<std::pair<EventHandler*, SocketOperation> >& handlers)
1186
1432
  {
1187
- _selecting = false;
1433
+ Lock sync(*this);
1434
+ handlers.clear();
1435
+ for(set<EventHandlerWrapperPtr>::const_iterator p = _readyHandlers.begin(); p != _readyHandlers.end(); ++p)
1436
+ {
1437
+ SocketOperation op = (*p)->readyOp();
1438
+ if(op)
1439
+ {
1440
+ _selectedHandlers.push_back(pair<EventHandlerWrapperPtr, SocketOperation>(*p, op));
1441
+ handlers.push_back(pair<EventHandler*, SocketOperation>((*p)->_handler.get(), op));
1442
+ }
1443
+ }
1444
+ _readyHandlers.clear();
1188
1445
  }
1189
1446
 
1190
1447
  void
1191
- Selector::select(vector<pair<EventHandler*, SocketOperation> >& handlers, int timeout)
1448
+ Selector::select(int timeout)
1192
1449
  {
1193
- int ret = 0;
1194
- while(true)
1450
+ //
1451
+ // Wait for handlers to be ready.
1452
+ //
1453
+ Lock sync(*this);
1454
+ while(!_destroyed)
1195
1455
  {
1196
- #if defined(ICE_USE_SELECT)
1197
- fd_set* rFdSet = fdSetCopy(_selectedReadFdSet, _readFdSet);
1198
- fd_set* wFdSet = fdSetCopy(_selectedWriteFdSet, _writeFdSet);
1199
- fd_set* eFdSet = fdSetCopy(_selectedErrorFdSet, _errorFdSet);
1200
- if(timeout > 0)
1201
- {
1202
- struct timeval tv;
1203
- tv.tv_sec = timeout;
1204
- tv.tv_usec = 0;
1205
- ret = ::select(0, rFdSet, wFdSet, eFdSet, &tv); // The first parameter is ignored on Windows
1206
- }
1207
- else
1456
+ while(!_changes.empty())
1208
1457
  {
1209
- ret = ::select(0, rFdSet, wFdSet, eFdSet, 0); // The first parameter is ignored on Windows
1458
+ CFRunLoopSourceSignal(_source.get());
1459
+ CFRunLoopWakeUp(_runLoop);
1460
+
1461
+ wait();
1210
1462
  }
1211
- #else
1212
- ret = poll(&_pollFdSet[0], _pollFdSet.size(), timeout > 0 ? timeout * 1000 : -1);
1213
- #endif
1214
- if(ret == SOCKET_ERROR)
1463
+
1464
+ if(_readyHandlers.empty())
1215
1465
  {
1216
- if(interrupted())
1466
+ if(timeout > 0)
1217
1467
  {
1218
- continue;
1468
+ if(!timedWait(IceUtil::Time::seconds(timeout)))
1469
+ {
1470
+ break;
1471
+ }
1219
1472
  }
1220
-
1473
+ else
1221
1474
  {
1222
- Ice::SocketException ex(__FILE__, __LINE__, IceInternal::getSocketErrno());
1223
- Ice::Error out(_instance->initializationData().logger);
1224
- out << "fatal error: selector failed:\n" << ex;
1475
+ wait();
1225
1476
  }
1226
- abort();
1227
1477
  }
1228
- break;
1229
- }
1230
-
1231
- if(ret == 0)
1232
- {
1233
- throw SelectorTimeoutException();
1234
- }
1235
-
1236
- assert(ret > 0);
1237
-
1238
- #if defined(ICE_USE_SELECT)
1239
- if(_selectedReadFdSet.fd_count == 0 && _selectedWriteFdSet.fd_count == 0 && _selectedErrorFdSet.fd_count == 0)
1240
- {
1241
- Ice::Error out(_instance->initializationData().logger);
1242
- out << "select() in selector returned " << ret << " but no filedescriptor is ready";
1243
- return;
1244
- }
1245
1478
 
1246
- for(unsigned int i = 0; i < static_cast<unsigned int>(ret); ++i)
1247
- {
1248
- pair<EventHandler*, SocketOperation> p;
1249
-
1250
- //
1251
- // Round robin for the filedescriptors.
1252
- //
1253
- SOCKET fd;
1254
- p.second = SocketOperationNone;
1255
- if(i < _selectedReadFdSet.fd_count)
1256
- {
1257
- fd = _selectedReadFdSet.fd_array[i];
1258
- p.second = static_cast<SocketOperation>(p.second | SocketOperationRead);
1259
- }
1260
- else if(i < _selectedWriteFdSet.fd_count + _selectedReadFdSet.fd_count)
1261
- {
1262
- fd = _selectedWriteFdSet.fd_array[i - _selectedReadFdSet.fd_count];
1263
- p.second = static_cast<SocketOperation>(p.second | SocketOperationWrite);
1264
- }
1265
- else
1479
+ if(_changes.empty())
1266
1480
  {
1267
- fd = _selectedErrorFdSet.fd_array[i - _selectedReadFdSet.fd_count - _selectedWriteFdSet.fd_count];
1268
- p.second = static_cast<SocketOperation>(p.second | SocketOperationConnect);
1481
+ break;
1269
1482
  }
1483
+ }
1484
+ }
1270
1485
 
1271
- if(fd == _fdIntrRead) // Interrupted, we have to process the interrupt before returning any handlers
1486
+ void
1487
+ Selector::processInterrupt()
1488
+ {
1489
+ Lock sync(*this);
1490
+ if(!_changes.empty())
1491
+ {
1492
+ for(set<EventHandlerWrapperPtr>::const_iterator p = _changes.begin(); p != _changes.end(); ++p)
1272
1493
  {
1273
- handlers.clear();
1274
- return;
1494
+ (*p)->updateRunLoop();
1275
1495
  }
1276
-
1277
- assert(_handlers.find(fd) != _handlers.end());
1278
- p.first = _handlers[fd];
1279
- handlers.push_back(p);
1496
+ _changes.clear();
1497
+ notify();
1280
1498
  }
1281
- #else
1282
- if(_pollFdSet[0].revents == POLLIN) // Interrupted, we have to process the interrupt before returning any handlers
1499
+ if(_destroyed)
1283
1500
  {
1284
- return;
1501
+ CFRunLoopStop(_runLoop);
1285
1502
  }
1503
+ }
1286
1504
 
1287
- for(vector<struct pollfd>::const_iterator q = _pollFdSet.begin(); q != _pollFdSet.end(); ++q)
1505
+ void
1506
+ Selector::run()
1507
+ {
1288
1508
  {
1289
- pair<EventHandler*, SocketOperation> p;
1290
- if(q->revents != 0)
1291
- {
1292
- SOCKET fd = q->fd;
1293
- assert(fd != _fdIntrRead);
1294
- assert(_handlers.find(fd) != _handlers.end());
1295
- p.first = _handlers[fd];
1296
- p.second = SocketOperationNone;
1297
- if(q->revents & (POLLIN | POLLERR | POLLHUP))
1298
- {
1299
- p.second = static_cast<SocketOperation>(p.second | SocketOperationRead);
1300
- }
1301
- if(q->revents & POLLOUT)
1302
- {
1303
- p.second = static_cast<SocketOperation>(p.second | SocketOperationWrite);
1304
- }
1305
- assert(p.second);
1306
- handlers.push_back(p);
1307
- }
1509
+ Lock sync(*this);
1510
+ _runLoop = CFRunLoopGetCurrent();
1511
+ notify();
1308
1512
  }
1309
- #endif
1513
+
1514
+ CFRunLoopAddSource(CFRunLoopGetCurrent(), _source.get(), kCFRunLoopDefaultMode);
1515
+ CFRunLoopRun();
1516
+ CFRunLoopRemoveSource(CFRunLoopGetCurrent(), _source.get(), kCFRunLoopDefaultMode);
1310
1517
  }
1311
1518
 
1312
1519
  void
1313
- Selector::updateImpl(EventHandler* handler)
1520
+ Selector::ready(EventHandlerWrapper* wrapper, SocketOperation op, int error)
1314
1521
  {
1315
- SocketOperation status = static_cast<SocketOperation>(handler->_registered & ~handler->_disabled);
1316
- _changes.push_back(make_pair(handler, status));
1317
- if(_selecting)
1318
- {
1319
- if(!_interrupted)
1320
- {
1321
- char c = 0;
1322
- while(true)
1323
- {
1324
- #ifdef _WIN32
1325
- if(::send(_fdIntrWrite, &c, 1, 0) == SOCKET_ERROR)
1326
- #else
1327
- if(::write(_fdIntrWrite, &c, 1) == SOCKET_ERROR)
1328
- #endif
1329
- {
1330
- if(interrupted())
1331
- {
1332
- continue;
1333
- }
1334
-
1335
- Ice::SocketException ex(__FILE__, __LINE__);
1336
- ex.error = IceInternal::getSocketErrno();
1337
- throw ex;
1338
- }
1339
- break;
1340
- }
1341
- _interrupted = true;
1342
- }
1343
- }
1344
- else
1345
- {
1346
- updateSelector();
1347
- }
1522
+ Lock sync(*this);
1523
+ wrapper->ready(op, error);
1348
1524
  }
1349
1525
 
1350
1526
  void
1351
- Selector::updateSelector()
1527
+ Selector::addReadyHandler(EventHandlerWrapper* wrapper)
1352
1528
  {
1353
- for(vector<pair<EventHandler*, SocketOperation> >::const_iterator p = _changes.begin(); p != _changes.end(); ++p)
1529
+ // Called from ready()
1530
+ _readyHandlers.insert(wrapper);
1531
+ if(_readyHandlers.size() == 1)
1354
1532
  {
1355
- EventHandler* handler = p->first;
1356
- SocketOperation status = p->second;
1357
-
1358
- SOCKET fd = handler->getNativeInfo()->fd();
1359
- if(status)
1360
- {
1361
- #if defined(ICE_USE_SELECT)
1362
- if(status & SocketOperationRead)
1363
- {
1364
- FD_SET(fd, &_readFdSet);
1365
- }
1366
- else
1367
- {
1368
- FD_CLR(fd, &_readFdSet);
1369
- }
1370
- if(status & SocketOperationWrite)
1371
- {
1372
- FD_SET(fd, &_writeFdSet);
1373
- }
1374
- else
1375
- {
1376
- FD_CLR(fd, &_writeFdSet);
1377
- }
1378
- if(status & SocketOperationConnect)
1379
- {
1380
- FD_SET(fd, &_writeFdSet);
1381
- FD_SET(fd, &_errorFdSet);
1382
- }
1383
- else
1384
- {
1385
- FD_CLR(fd, &_writeFdSet);
1386
- FD_CLR(fd, &_errorFdSet);
1387
- }
1388
- _handlers[fd] = handler;
1389
- #else
1390
- short events = 0;
1391
- if(status & SocketOperationRead)
1392
- {
1393
- events |= POLLIN;
1394
- }
1395
- if(status & SocketOperationWrite)
1396
- {
1397
- events |= POLLOUT;
1398
- }
1399
- map<SOCKET, EventHandler*>::const_iterator q = _handlers.find(fd);
1400
- if(q == _handlers.end())
1401
- {
1402
- struct pollfd pollFd;
1403
- pollFd.fd = fd;
1404
- pollFd.events = events;
1405
- pollFd.revents = 0;
1406
- _pollFdSet.push_back(pollFd);
1407
- _handlers.insert(make_pair(fd, handler));
1408
- }
1409
- else
1410
- {
1411
- for(vector<struct pollfd>::iterator r = _pollFdSet.begin(); r != _pollFdSet.end(); ++r)
1412
- {
1413
- if(r->fd == fd)
1414
- {
1415
- r->events = events;
1416
- break;
1417
- }
1418
- }
1419
- }
1420
- #endif
1421
- }
1422
- else
1423
- {
1424
- #if defined(ICE_USE_SELECT)
1425
- FD_CLR(fd, &_readFdSet);
1426
- FD_CLR(fd, &_writeFdSet);
1427
- FD_CLR(fd, &_errorFdSet);
1428
- #else
1429
- for(vector<struct pollfd>::iterator r = _pollFdSet.begin(); r != _pollFdSet.end(); ++r)
1430
- {
1431
- if(r->fd == fd)
1432
- {
1433
- _pollFdSet.erase(r);
1434
- break;
1435
- }
1436
- }
1437
- #endif
1438
- _handlers.erase(fd);
1439
- }
1533
+ notify();
1440
1534
  }
1441
- _changes.clear();
1442
1535
  }
1443
1536
 
1444
1537
  #endif