zeroc-ice 3.6b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (675) hide show
  1. checksums.yaml +7 -0
  2. data/ICE_LICENSE +54 -0
  3. data/LICENSE +339 -0
  4. data/bin/slice2rb +17 -0
  5. data/ext/Communicator.cpp +596 -0
  6. data/ext/Communicator.h +25 -0
  7. data/ext/Config.h +111 -0
  8. data/ext/Connection.cpp +381 -0
  9. data/ext/Connection.h +26 -0
  10. data/ext/Endpoint.cpp +311 -0
  11. data/ext/Endpoint.h +27 -0
  12. data/ext/ImplicitContext.cpp +152 -0
  13. data/ext/ImplicitContext.h +25 -0
  14. data/ext/Init.cpp +52 -0
  15. data/ext/Logger.cpp +151 -0
  16. data/ext/Logger.h +28 -0
  17. data/ext/ObjectFactory.cpp +140 -0
  18. data/ext/ObjectFactory.h +50 -0
  19. data/ext/Operation.cpp +676 -0
  20. data/ext/Operation.h +36 -0
  21. data/ext/Properties.cpp +369 -0
  22. data/ext/Properties.h +25 -0
  23. data/ext/Proxy.cpp +1354 -0
  24. data/ext/Proxy.h +27 -0
  25. data/ext/Slice.cpp +223 -0
  26. data/ext/Slice.h +22 -0
  27. data/ext/Types.cpp +3160 -0
  28. data/ext/Types.h +545 -0
  29. data/ext/Util.cpp +792 -0
  30. data/ext/Util.h +511 -0
  31. data/ext/extconf.rb +118 -0
  32. data/ext/ice/BZIP_LICENSE +42 -0
  33. data/ext/ice/MCPP_LICENSE +36 -0
  34. data/ext/ice/bzip2/blocksort.c +1094 -0
  35. data/ext/ice/bzip2/bzlib.c +1572 -0
  36. data/ext/ice/bzip2/bzlib.h +282 -0
  37. data/ext/ice/bzip2/bzlib_private.h +509 -0
  38. data/ext/ice/bzip2/compress.c +672 -0
  39. data/ext/ice/bzip2/crctable.c +104 -0
  40. data/ext/ice/bzip2/decompress.c +646 -0
  41. data/ext/ice/bzip2/huffman.c +205 -0
  42. data/ext/ice/bzip2/randtable.c +84 -0
  43. data/ext/ice/cpp/include/Ice/ACMF.h +30 -0
  44. data/ext/ice/cpp/include/Ice/Application.h +156 -0
  45. data/ext/ice/cpp/include/Ice/AsyncResult.h +363 -0
  46. data/ext/ice/cpp/include/Ice/AsyncResultF.h +26 -0
  47. data/ext/ice/cpp/include/Ice/BasicStream.h +1315 -0
  48. data/ext/ice/cpp/include/Ice/Buffer.h +159 -0
  49. data/ext/ice/cpp/include/Ice/BuiltinSequences.h +74 -0
  50. data/ext/ice/cpp/include/Ice/Communicator.h +194 -0
  51. data/ext/ice/cpp/include/Ice/CommunicatorAsync.h +115 -0
  52. data/ext/ice/cpp/include/Ice/CommunicatorF.h +60 -0
  53. data/ext/ice/cpp/include/Ice/Config.h +97 -0
  54. data/ext/ice/cpp/include/Ice/Connection.h +495 -0
  55. data/ext/ice/cpp/include/Ice/ConnectionAsync.h +115 -0
  56. data/ext/ice/cpp/include/Ice/ConnectionF.h +72 -0
  57. data/ext/ice/cpp/include/Ice/ConnectionFactoryF.h +30 -0
  58. data/ext/ice/cpp/include/Ice/ConnectionIF.h +37 -0
  59. data/ext/ice/cpp/include/Ice/Current.h +94 -0
  60. data/ext/ice/cpp/include/Ice/DefaultObjectFactory.h +48 -0
  61. data/ext/ice/cpp/include/Ice/DeprecatedStringConverter.h +62 -0
  62. data/ext/ice/cpp/include/Ice/DispatchInterceptor.h +33 -0
  63. data/ext/ice/cpp/include/Ice/Dispatcher.h +51 -0
  64. data/ext/ice/cpp/include/Ice/DynamicLibrary.h +105 -0
  65. data/ext/ice/cpp/include/Ice/DynamicLibraryF.h +29 -0
  66. data/ext/ice/cpp/include/Ice/Endpoint.h +350 -0
  67. data/ext/ice/cpp/include/Ice/EndpointF.h +97 -0
  68. data/ext/ice/cpp/include/Ice/EndpointTypes.h +74 -0
  69. data/ext/ice/cpp/include/Ice/Exception.h +114 -0
  70. data/ext/ice/cpp/include/Ice/FacetMap.h +56 -0
  71. data/ext/ice/cpp/include/Ice/FactoryTable.h +69 -0
  72. data/ext/ice/cpp/include/Ice/FactoryTableInit.h +87 -0
  73. data/ext/ice/cpp/include/Ice/Format.h +39 -0
  74. data/ext/ice/cpp/include/Ice/Functional.h +138 -0
  75. data/ext/ice/cpp/include/Ice/GCObject.h +73 -0
  76. data/ext/ice/cpp/include/Ice/Handle.h +192 -0
  77. data/ext/ice/cpp/include/Ice/Ice.h +54 -0
  78. data/ext/ice/cpp/include/Ice/Identity.h +160 -0
  79. data/ext/ice/cpp/include/Ice/ImplicitContext.h +96 -0
  80. data/ext/ice/cpp/include/Ice/ImplicitContextF.h +60 -0
  81. data/ext/ice/cpp/include/Ice/Incoming.h +131 -0
  82. data/ext/ice/cpp/include/Ice/IncomingAsync.h +108 -0
  83. data/ext/ice/cpp/include/Ice/IncomingAsyncF.h +35 -0
  84. data/ext/ice/cpp/include/Ice/Initialize.h +141 -0
  85. data/ext/ice/cpp/include/Ice/InstanceF.h +26 -0
  86. data/ext/ice/cpp/include/Ice/Instrumentation.h +377 -0
  87. data/ext/ice/cpp/include/Ice/InstrumentationF.h +71 -0
  88. data/ext/ice/cpp/include/Ice/LocalException.h +1022 -0
  89. data/ext/ice/cpp/include/Ice/LocalObject.h +36 -0
  90. data/ext/ice/cpp/include/Ice/LocalObjectF.h +26 -0
  91. data/ext/ice/cpp/include/Ice/Locator.h +2191 -0
  92. data/ext/ice/cpp/include/Ice/LocatorF.h +89 -0
  93. data/ext/ice/cpp/include/Ice/Logger.h +94 -0
  94. data/ext/ice/cpp/include/Ice/LoggerF.h +60 -0
  95. data/ext/ice/cpp/include/Ice/LoggerUtil.h +153 -0
  96. data/ext/ice/cpp/include/Ice/Makefile +26 -0
  97. data/ext/ice/cpp/include/Ice/Metrics.h +2989 -0
  98. data/ext/ice/cpp/include/Ice/MetricsAdminI.h +662 -0
  99. data/ext/ice/cpp/include/Ice/MetricsFunctional.h +144 -0
  100. data/ext/ice/cpp/include/Ice/MetricsObserverI.h +576 -0
  101. data/ext/ice/cpp/include/Ice/NativePropertiesAdmin.h +55 -0
  102. data/ext/ice/cpp/include/Ice/Object.h +165 -0
  103. data/ext/ice/cpp/include/Ice/ObjectAdapter.h +162 -0
  104. data/ext/ice/cpp/include/Ice/ObjectAdapterF.h +60 -0
  105. data/ext/ice/cpp/include/Ice/ObjectAdapterFactoryF.h +26 -0
  106. data/ext/ice/cpp/include/Ice/ObjectF.h +26 -0
  107. data/ext/ice/cpp/include/Ice/ObjectFactory.h +86 -0
  108. data/ext/ice/cpp/include/Ice/ObjectFactoryF.h +60 -0
  109. data/ext/ice/cpp/include/Ice/ObjectFactoryManagerF.h +26 -0
  110. data/ext/ice/cpp/include/Ice/ObserverHelper.h +177 -0
  111. data/ext/ice/cpp/include/Ice/Outgoing.h +197 -0
  112. data/ext/ice/cpp/include/Ice/OutgoingAsync.h +264 -0
  113. data/ext/ice/cpp/include/Ice/OutgoingAsyncF.h +38 -0
  114. data/ext/ice/cpp/include/Ice/Plugin.h +121 -0
  115. data/ext/ice/cpp/include/Ice/PluginF.h +66 -0
  116. data/ext/ice/cpp/include/Ice/Process.h +568 -0
  117. data/ext/ice/cpp/include/Ice/ProcessF.h +77 -0
  118. data/ext/ice/cpp/include/Ice/Properties.h +130 -0
  119. data/ext/ice/cpp/include/Ice/PropertiesAdmin.h +824 -0
  120. data/ext/ice/cpp/include/Ice/PropertiesF.h +83 -0
  121. data/ext/ice/cpp/include/Ice/Protocol.h +242 -0
  122. data/ext/ice/cpp/include/Ice/Proxy.h +2448 -0
  123. data/ext/ice/cpp/include/Ice/ProxyF.h +78 -0
  124. data/ext/ice/cpp/include/Ice/ProxyFactoryF.h +26 -0
  125. data/ext/ice/cpp/include/Ice/ProxyHandle.h +330 -0
  126. data/ext/ice/cpp/include/Ice/ReferenceF.h +34 -0
  127. data/ext/ice/cpp/include/Ice/RemoteLogger.h +1496 -0
  128. data/ext/ice/cpp/include/Ice/RequestHandlerF.h +29 -0
  129. data/ext/ice/cpp/include/Ice/ResponseHandlerF.h +25 -0
  130. data/ext/ice/cpp/include/Ice/Router.h +1155 -0
  131. data/ext/ice/cpp/include/Ice/RouterF.h +77 -0
  132. data/ext/ice/cpp/include/Ice/ServantLocator.h +90 -0
  133. data/ext/ice/cpp/include/Ice/ServantLocatorF.h +60 -0
  134. data/ext/ice/cpp/include/Ice/ServantManagerF.h +26 -0
  135. data/ext/ice/cpp/include/Ice/Service.h +260 -0
  136. data/ext/ice/cpp/include/Ice/SliceChecksumDict.h +56 -0
  137. data/ext/ice/cpp/include/Ice/SliceChecksums.h +34 -0
  138. data/ext/ice/cpp/include/Ice/SlicedData.h +103 -0
  139. data/ext/ice/cpp/include/Ice/SlicedDataF.h +34 -0
  140. data/ext/ice/cpp/include/Ice/Stream.h +449 -0
  141. data/ext/ice/cpp/include/Ice/StreamF.h +30 -0
  142. data/ext/ice/cpp/include/Ice/StreamHelpers.h +877 -0
  143. data/ext/ice/cpp/include/Ice/ThreadPoolF.h +28 -0
  144. data/ext/ice/cpp/include/Ice/UserExceptionFactory.h +56 -0
  145. data/ext/ice/cpp/include/Ice/Version.h +254 -0
  146. data/ext/ice/cpp/include/IceSSL/Config.h +23 -0
  147. data/ext/ice/cpp/include/IceSSL/ConnectionInfo.h +119 -0
  148. data/ext/ice/cpp/include/IceSSL/EndpointInfo.h +101 -0
  149. data/ext/ice/cpp/include/IceSSL/IceSSL.h +22 -0
  150. data/ext/ice/cpp/include/IceSSL/Makefile +26 -0
  151. data/ext/ice/cpp/include/IceSSL/Plugin.h +558 -0
  152. data/ext/ice/cpp/include/IceUtil/AbstractMutex.h +119 -0
  153. data/ext/ice/cpp/include/IceUtil/Cache.h +362 -0
  154. data/ext/ice/cpp/include/IceUtil/Cond.h +323 -0
  155. data/ext/ice/cpp/include/IceUtil/Config.h +234 -0
  156. data/ext/ice/cpp/include/IceUtil/CountDownLatch.h +50 -0
  157. data/ext/ice/cpp/include/IceUtil/CtrlCHandler.h +70 -0
  158. data/ext/ice/cpp/include/IceUtil/DisableWarnings.h +45 -0
  159. data/ext/ice/cpp/include/IceUtil/Exception.h +184 -0
  160. data/ext/ice/cpp/include/IceUtil/Functional.h +389 -0
  161. data/ext/ice/cpp/include/IceUtil/Handle.h +266 -0
  162. data/ext/ice/cpp/include/IceUtil/IceUtil.h +51 -0
  163. data/ext/ice/cpp/include/IceUtil/IconvStringConverter.h +302 -0
  164. data/ext/ice/cpp/include/IceUtil/InputUtil.h +47 -0
  165. data/ext/ice/cpp/include/IceUtil/Iterator.h +36 -0
  166. data/ext/ice/cpp/include/IceUtil/Lock.h +135 -0
  167. data/ext/ice/cpp/include/IceUtil/Makefile +26 -0
  168. data/ext/ice/cpp/include/IceUtil/Monitor.h +249 -0
  169. data/ext/ice/cpp/include/IceUtil/Mutex.h +357 -0
  170. data/ext/ice/cpp/include/IceUtil/MutexProtocol.h +28 -0
  171. data/ext/ice/cpp/include/IceUtil/MutexPtrLock.h +83 -0
  172. data/ext/ice/cpp/include/IceUtil/MutexPtrTryLock.h +82 -0
  173. data/ext/ice/cpp/include/IceUtil/Optional.h +322 -0
  174. data/ext/ice/cpp/include/IceUtil/Options.h +141 -0
  175. data/ext/ice/cpp/include/IceUtil/OutputUtil.h +362 -0
  176. data/ext/ice/cpp/include/IceUtil/PopDisableWarnings.h +19 -0
  177. data/ext/ice/cpp/include/IceUtil/PushDisableWarnings.h +26 -0
  178. data/ext/ice/cpp/include/IceUtil/Random.h +24 -0
  179. data/ext/ice/cpp/include/IceUtil/RecMutex.h +113 -0
  180. data/ext/ice/cpp/include/IceUtil/SHA1.h +65 -0
  181. data/ext/ice/cpp/include/IceUtil/ScannerConfig.h +44 -0
  182. data/ext/ice/cpp/include/IceUtil/ScopedArray.h +97 -0
  183. data/ext/ice/cpp/include/IceUtil/Shared.h +168 -0
  184. data/ext/ice/cpp/include/IceUtil/StringConverter.h +175 -0
  185. data/ext/ice/cpp/include/IceUtil/StringUtil.h +91 -0
  186. data/ext/ice/cpp/include/IceUtil/Thread.h +181 -0
  187. data/ext/ice/cpp/include/IceUtil/ThreadException.h +108 -0
  188. data/ext/ice/cpp/include/IceUtil/Time.h +209 -0
  189. data/ext/ice/cpp/include/IceUtil/Timer.h +143 -0
  190. data/ext/ice/cpp/include/IceUtil/UUID.h +22 -0
  191. data/ext/ice/cpp/include/IceUtil/UndefSysMacros.h +42 -0
  192. data/ext/ice/cpp/include/IceUtil/UniquePtr.h +101 -0
  193. data/ext/ice/cpp/include/Slice/CPlusPlusUtil.h +64 -0
  194. data/ext/ice/cpp/include/Slice/Checksum.h +26 -0
  195. data/ext/ice/cpp/include/Slice/CsUtil.h +92 -0
  196. data/ext/ice/cpp/include/Slice/DotNetNames.h +34 -0
  197. data/ext/ice/cpp/include/Slice/FileTracker.h +71 -0
  198. data/ext/ice/cpp/include/Slice/JavaUtil.h +277 -0
  199. data/ext/ice/cpp/include/Slice/Makefile +26 -0
  200. data/ext/ice/cpp/include/Slice/PHPUtil.h +50 -0
  201. data/ext/ice/cpp/include/Slice/Parser.h +1116 -0
  202. data/ext/ice/cpp/include/Slice/Preprocessor.h +68 -0
  203. data/ext/ice/cpp/include/Slice/PythonUtil.h +64 -0
  204. data/ext/ice/cpp/include/Slice/RubyUtil.h +54 -0
  205. data/ext/ice/cpp/include/Slice/Util.h +33 -0
  206. data/ext/ice/cpp/src/Ice/ACM.cpp +343 -0
  207. data/ext/ice/cpp/src/Ice/ACM.h +117 -0
  208. data/ext/ice/cpp/src/Ice/Acceptor.cpp +16 -0
  209. data/ext/ice/cpp/src/Ice/Acceptor.h +41 -0
  210. data/ext/ice/cpp/src/Ice/AcceptorF.h +30 -0
  211. data/ext/ice/cpp/src/Ice/Application.cpp +760 -0
  212. data/ext/ice/cpp/src/Ice/AsyncResult.cpp +599 -0
  213. data/ext/ice/cpp/src/Ice/Base64.cpp +269 -0
  214. data/ext/ice/cpp/src/Ice/Base64.h +36 -0
  215. data/ext/ice/cpp/src/Ice/BasicStream.cpp +3393 -0
  216. data/ext/ice/cpp/src/Ice/Buffer.cpp +98 -0
  217. data/ext/ice/cpp/src/Ice/BuiltinSequences.cpp +34 -0
  218. data/ext/ice/cpp/src/Ice/CollocatedRequestHandler.cpp +718 -0
  219. data/ext/ice/cpp/src/Ice/CollocatedRequestHandler.h +106 -0
  220. data/ext/ice/cpp/src/Ice/Communicator.cpp +45 -0
  221. data/ext/ice/cpp/src/Ice/CommunicatorF.cpp +38 -0
  222. data/ext/ice/cpp/src/Ice/CommunicatorI.cpp +386 -0
  223. data/ext/ice/cpp/src/Ice/CommunicatorI.h +112 -0
  224. data/ext/ice/cpp/src/Ice/ConnectRequestHandler.cpp +546 -0
  225. data/ext/ice/cpp/src/Ice/ConnectRequestHandler.h +97 -0
  226. data/ext/ice/cpp/src/Ice/Connection.cpp +58 -0
  227. data/ext/ice/cpp/src/Ice/ConnectionF.cpp +38 -0
  228. data/ext/ice/cpp/src/Ice/ConnectionFactory.cpp +1639 -0
  229. data/ext/ice/cpp/src/Ice/ConnectionFactory.h +236 -0
  230. data/ext/ice/cpp/src/Ice/ConnectionI.cpp +3876 -0
  231. data/ext/ice/cpp/src/Ice/ConnectionI.h +364 -0
  232. data/ext/ice/cpp/src/Ice/ConnectionRequestHandler.cpp +115 -0
  233. data/ext/ice/cpp/src/Ice/ConnectionRequestHandler.h +50 -0
  234. data/ext/ice/cpp/src/Ice/Connector.cpp +16 -0
  235. data/ext/ice/cpp/src/Ice/Connector.h +36 -0
  236. data/ext/ice/cpp/src/Ice/ConnectorF.h +26 -0
  237. data/ext/ice/cpp/src/Ice/Current.cpp +38 -0
  238. data/ext/ice/cpp/src/Ice/DefaultsAndOverrides.cpp +168 -0
  239. data/ext/ice/cpp/src/Ice/DefaultsAndOverrides.h +57 -0
  240. data/ext/ice/cpp/src/Ice/DefaultsAndOverridesF.h +26 -0
  241. data/ext/ice/cpp/src/Ice/DeprecatedStringConverter.cpp +60 -0
  242. data/ext/ice/cpp/src/Ice/DispatchInterceptor.cpp +49 -0
  243. data/ext/ice/cpp/src/Ice/DynamicLibrary.cpp +281 -0
  244. data/ext/ice/cpp/src/Ice/Endpoint.cpp +53 -0
  245. data/ext/ice/cpp/src/Ice/EndpointF.cpp +38 -0
  246. data/ext/ice/cpp/src/Ice/EndpointFactory.cpp +25 -0
  247. data/ext/ice/cpp/src/Ice/EndpointFactory.h +44 -0
  248. data/ext/ice/cpp/src/Ice/EndpointFactoryF.h +26 -0
  249. data/ext/ice/cpp/src/Ice/EndpointFactoryManager.cpp +208 -0
  250. data/ext/ice/cpp/src/Ice/EndpointFactoryManager.h +46 -0
  251. data/ext/ice/cpp/src/Ice/EndpointFactoryManagerF.h +26 -0
  252. data/ext/ice/cpp/src/Ice/EndpointI.cpp +87 -0
  253. data/ext/ice/cpp/src/Ice/EndpointI.h +165 -0
  254. data/ext/ice/cpp/src/Ice/EndpointIF.h +41 -0
  255. data/ext/ice/cpp/src/Ice/EndpointTypes.cpp +38 -0
  256. data/ext/ice/cpp/src/Ice/EventHandler.cpp +35 -0
  257. data/ext/ice/cpp/src/Ice/EventHandler.h +78 -0
  258. data/ext/ice/cpp/src/Ice/EventHandlerF.h +26 -0
  259. data/ext/ice/cpp/src/Ice/EventLoggerMsg.h +53 -0
  260. data/ext/ice/cpp/src/Ice/Exception.cpp +832 -0
  261. data/ext/ice/cpp/src/Ice/FacetMap.cpp +34 -0
  262. data/ext/ice/cpp/src/Ice/FactoryTable.cpp +158 -0
  263. data/ext/ice/cpp/src/Ice/FactoryTableInit.cpp +95 -0
  264. data/ext/ice/cpp/src/Ice/GCObject.cpp +444 -0
  265. data/ext/ice/cpp/src/Ice/HashUtil.h +59 -0
  266. data/ext/ice/cpp/src/Ice/HttpParser.cpp +680 -0
  267. data/ext/ice/cpp/src/Ice/HttpParser.h +124 -0
  268. data/ext/ice/cpp/src/Ice/IPEndpointI.cpp +733 -0
  269. data/ext/ice/cpp/src/Ice/IPEndpointI.h +157 -0
  270. data/ext/ice/cpp/src/Ice/IPEndpointIF.h +29 -0
  271. data/ext/ice/cpp/src/Ice/Identity.cpp +42 -0
  272. data/ext/ice/cpp/src/Ice/ImplicitContext.cpp +41 -0
  273. data/ext/ice/cpp/src/Ice/ImplicitContextF.cpp +38 -0
  274. data/ext/ice/cpp/src/Ice/ImplicitContextI.cpp +639 -0
  275. data/ext/ice/cpp/src/Ice/ImplicitContextI.h +51 -0
  276. data/ext/ice/cpp/src/Ice/Incoming.cpp +757 -0
  277. data/ext/ice/cpp/src/Ice/IncomingAsync.cpp +340 -0
  278. data/ext/ice/cpp/src/Ice/IncomingRequest.h +37 -0
  279. data/ext/ice/cpp/src/Ice/Initialize.cpp +401 -0
  280. data/ext/ice/cpp/src/Ice/Instance.cpp +1928 -0
  281. data/ext/ice/cpp/src/Ice/Instance.h +198 -0
  282. data/ext/ice/cpp/src/Ice/Instrumentation.cpp +68 -0
  283. data/ext/ice/cpp/src/Ice/InstrumentationF.cpp +43 -0
  284. data/ext/ice/cpp/src/Ice/InstrumentationI.cpp +1083 -0
  285. data/ext/ice/cpp/src/Ice/InstrumentationI.h +262 -0
  286. data/ext/ice/cpp/src/Ice/LocalException.cpp +2091 -0
  287. data/ext/ice/cpp/src/Ice/LocalObject.cpp +29 -0
  288. data/ext/ice/cpp/src/Ice/Locator.cpp +1946 -0
  289. data/ext/ice/cpp/src/Ice/LocatorF.cpp +39 -0
  290. data/ext/ice/cpp/src/Ice/LocatorInfo.cpp +917 -0
  291. data/ext/ice/cpp/src/Ice/LocatorInfo.h +193 -0
  292. data/ext/ice/cpp/src/Ice/LocatorInfoF.h +34 -0
  293. data/ext/ice/cpp/src/Ice/Logger.cpp +40 -0
  294. data/ext/ice/cpp/src/Ice/LoggerAdminI.cpp +862 -0
  295. data/ext/ice/cpp/src/Ice/LoggerAdminI.h +46 -0
  296. data/ext/ice/cpp/src/Ice/LoggerF.cpp +38 -0
  297. data/ext/ice/cpp/src/Ice/LoggerI.cpp +199 -0
  298. data/ext/ice/cpp/src/Ice/LoggerI.h +57 -0
  299. data/ext/ice/cpp/src/Ice/LoggerUtil.cpp +107 -0
  300. data/ext/ice/cpp/src/Ice/Makefile +190 -0
  301. data/ext/ice/cpp/src/Ice/Metrics.cpp +2159 -0
  302. data/ext/ice/cpp/src/Ice/MetricsAdminI.cpp +669 -0
  303. data/ext/ice/cpp/src/Ice/MetricsObserverI.cpp +14 -0
  304. data/ext/ice/cpp/src/Ice/Network.cpp +2694 -0
  305. data/ext/ice/cpp/src/Ice/Network.h +291 -0
  306. data/ext/ice/cpp/src/Ice/NetworkF.h +28 -0
  307. data/ext/ice/cpp/src/Ice/NetworkProxy.cpp +325 -0
  308. data/ext/ice/cpp/src/Ice/NetworkProxy.h +74 -0
  309. data/ext/ice/cpp/src/Ice/NetworkProxyF.h +26 -0
  310. data/ext/ice/cpp/src/Ice/Object.cpp +440 -0
  311. data/ext/ice/cpp/src/Ice/ObjectAdapter.cpp +41 -0
  312. data/ext/ice/cpp/src/Ice/ObjectAdapterF.cpp +38 -0
  313. data/ext/ice/cpp/src/Ice/ObjectAdapterFactory.cpp +241 -0
  314. data/ext/ice/cpp/src/Ice/ObjectAdapterFactory.h +52 -0
  315. data/ext/ice/cpp/src/Ice/ObjectAdapterI.cpp +1498 -0
  316. data/ext/ice/cpp/src/Ice/ObjectAdapterI.h +155 -0
  317. data/ext/ice/cpp/src/Ice/ObjectFactory.cpp +41 -0
  318. data/ext/ice/cpp/src/Ice/ObjectFactoryF.cpp +38 -0
  319. data/ext/ice/cpp/src/Ice/ObjectFactoryManager.cpp +140 -0
  320. data/ext/ice/cpp/src/Ice/ObjectFactoryManager.h +43 -0
  321. data/ext/ice/cpp/src/Ice/ObserverHelper.cpp +84 -0
  322. data/ext/ice/cpp/src/Ice/OpaqueEndpointI.cpp +407 -0
  323. data/ext/ice/cpp/src/Ice/OpaqueEndpointI.h +70 -0
  324. data/ext/ice/cpp/src/Ice/Outgoing.cpp +737 -0
  325. data/ext/ice/cpp/src/Ice/OutgoingAsync.cpp +874 -0
  326. data/ext/ice/cpp/src/Ice/Plugin.cpp +43 -0
  327. data/ext/ice/cpp/src/Ice/PluginF.cpp +38 -0
  328. data/ext/ice/cpp/src/Ice/PluginManagerI.cpp +503 -0
  329. data/ext/ice/cpp/src/Ice/PluginManagerI.h +67 -0
  330. data/ext/ice/cpp/src/Ice/Process.cpp +299 -0
  331. data/ext/ice/cpp/src/Ice/ProcessF.cpp +39 -0
  332. data/ext/ice/cpp/src/Ice/Properties.cpp +45 -0
  333. data/ext/ice/cpp/src/Ice/PropertiesAdmin.cpp +555 -0
  334. data/ext/ice/cpp/src/Ice/PropertiesAdminI.cpp +207 -0
  335. data/ext/ice/cpp/src/Ice/PropertiesAdminI.h +45 -0
  336. data/ext/ice/cpp/src/Ice/PropertiesF.cpp +39 -0
  337. data/ext/ice/cpp/src/Ice/PropertiesI.cpp +759 -0
  338. data/ext/ice/cpp/src/Ice/PropertiesI.h +78 -0
  339. data/ext/ice/cpp/src/Ice/PropertyNames.cpp +1293 -0
  340. data/ext/ice/cpp/src/Ice/PropertyNames.h +81 -0
  341. data/ext/ice/cpp/src/Ice/Protocol.cpp +137 -0
  342. data/ext/ice/cpp/src/Ice/ProtocolInstance.cpp +98 -0
  343. data/ext/ice/cpp/src/Ice/ProtocolInstance.h +91 -0
  344. data/ext/ice/cpp/src/Ice/ProtocolInstanceF.h +26 -0
  345. data/ext/ice/cpp/src/Ice/ProtocolPluginFacade.cpp +51 -0
  346. data/ext/ice/cpp/src/Ice/ProtocolPluginFacade.h +67 -0
  347. data/ext/ice/cpp/src/Ice/ProtocolPluginFacadeF.h +26 -0
  348. data/ext/ice/cpp/src/Ice/Proxy.cpp +1810 -0
  349. data/ext/ice/cpp/src/Ice/ProxyFactory.cpp +305 -0
  350. data/ext/ice/cpp/src/Ice/ProxyFactory.h +57 -0
  351. data/ext/ice/cpp/src/Ice/Reference.cpp +1947 -0
  352. data/ext/ice/cpp/src/Ice/Reference.h +305 -0
  353. data/ext/ice/cpp/src/Ice/ReferenceFactory.cpp +937 -0
  354. data/ext/ice/cpp/src/Ice/ReferenceFactory.h +81 -0
  355. data/ext/ice/cpp/src/Ice/ReferenceFactoryF.h +24 -0
  356. data/ext/ice/cpp/src/Ice/RemoteLogger.cpp +958 -0
  357. data/ext/ice/cpp/src/Ice/ReplyStatus.h +29 -0
  358. data/ext/ice/cpp/src/Ice/RequestHandler.cpp +40 -0
  359. data/ext/ice/cpp/src/Ice/RequestHandler.h +90 -0
  360. data/ext/ice/cpp/src/Ice/RequestHandlerFactory.cpp +70 -0
  361. data/ext/ice/cpp/src/Ice/RequestHandlerFactory.h +41 -0
  362. data/ext/ice/cpp/src/Ice/ResponseHandler.cpp +20 -0
  363. data/ext/ice/cpp/src/Ice/ResponseHandler.h +39 -0
  364. data/ext/ice/cpp/src/Ice/RetryQueue.cpp +154 -0
  365. data/ext/ice/cpp/src/Ice/RetryQueue.h +69 -0
  366. data/ext/ice/cpp/src/Ice/RetryQueueF.h +24 -0
  367. data/ext/ice/cpp/src/Ice/Router.cpp +849 -0
  368. data/ext/ice/cpp/src/Ice/RouterF.cpp +39 -0
  369. data/ext/ice/cpp/src/Ice/RouterInfo.cpp +381 -0
  370. data/ext/ice/cpp/src/Ice/RouterInfo.h +148 -0
  371. data/ext/ice/cpp/src/Ice/RouterInfoF.h +30 -0
  372. data/ext/ice/cpp/src/Ice/Selector.cpp +926 -0
  373. data/ext/ice/cpp/src/Ice/Selector.h +231 -0
  374. data/ext/ice/cpp/src/Ice/ServantLocator.cpp +41 -0
  375. data/ext/ice/cpp/src/Ice/ServantLocatorF.cpp +38 -0
  376. data/ext/ice/cpp/src/Ice/ServantManager.cpp +495 -0
  377. data/ext/ice/cpp/src/Ice/ServantManager.h +74 -0
  378. data/ext/ice/cpp/src/Ice/Service.cpp +1897 -0
  379. data/ext/ice/cpp/src/Ice/SharedContext.h +51 -0
  380. data/ext/ice/cpp/src/Ice/SliceChecksumDict.cpp +34 -0
  381. data/ext/ice/cpp/src/Ice/SliceChecksums.cpp +80 -0
  382. data/ext/ice/cpp/src/Ice/SlicedData.cpp +80 -0
  383. data/ext/ice/cpp/src/Ice/Stream.cpp +53 -0
  384. data/ext/ice/cpp/src/Ice/StreamI.cpp +832 -0
  385. data/ext/ice/cpp/src/Ice/StreamI.h +198 -0
  386. data/ext/ice/cpp/src/Ice/StreamSocket.cpp +521 -0
  387. data/ext/ice/cpp/src/Ice/StreamSocket.h +85 -0
  388. data/ext/ice/cpp/src/Ice/StringConverterPlugin.cpp +145 -0
  389. data/ext/ice/cpp/src/Ice/SysLoggerI.cpp +167 -0
  390. data/ext/ice/cpp/src/Ice/SysLoggerI.h +43 -0
  391. data/ext/ice/cpp/src/Ice/TcpAcceptor.cpp +235 -0
  392. data/ext/ice/cpp/src/Ice/TcpAcceptor.h +67 -0
  393. data/ext/ice/cpp/src/Ice/TcpConnector.cpp +133 -0
  394. data/ext/ice/cpp/src/Ice/TcpConnector.h +51 -0
  395. data/ext/ice/cpp/src/Ice/TcpEndpointI.cpp +397 -0
  396. data/ext/ice/cpp/src/Ice/TcpEndpointI.h +93 -0
  397. data/ext/ice/cpp/src/Ice/TcpTransceiver.cpp +127 -0
  398. data/ext/ice/cpp/src/Ice/TcpTransceiver.h +61 -0
  399. data/ext/ice/cpp/src/Ice/ThreadPool.cpp +1357 -0
  400. data/ext/ice/cpp/src/Ice/ThreadPool.h +399 -0
  401. data/ext/ice/cpp/src/Ice/TraceLevels.cpp +43 -0
  402. data/ext/ice/cpp/src/Ice/TraceLevels.h +50 -0
  403. data/ext/ice/cpp/src/Ice/TraceLevelsF.h +26 -0
  404. data/ext/ice/cpp/src/Ice/TraceUtil.cpp +452 -0
  405. data/ext/ice/cpp/src/Ice/TraceUtil.h +28 -0
  406. data/ext/ice/cpp/src/Ice/Transceiver.cpp +24 -0
  407. data/ext/ice/cpp/src/Ice/Transceiver.h +52 -0
  408. data/ext/ice/cpp/src/Ice/TransceiverF.h +38 -0
  409. data/ext/ice/cpp/src/Ice/UdpConnector.cpp +144 -0
  410. data/ext/ice/cpp/src/Ice/UdpConnector.h +51 -0
  411. data/ext/ice/cpp/src/Ice/UdpEndpointI.cpp +483 -0
  412. data/ext/ice/cpp/src/Ice/UdpEndpointI.h +95 -0
  413. data/ext/ice/cpp/src/Ice/UdpTransceiver.cpp +1156 -0
  414. data/ext/ice/cpp/src/Ice/UdpTransceiver.h +123 -0
  415. data/ext/ice/cpp/src/Ice/Version.cpp +46 -0
  416. data/ext/ice/cpp/src/Ice/WSAcceptor.cpp +103 -0
  417. data/ext/ice/cpp/src/Ice/WSAcceptor.h +61 -0
  418. data/ext/ice/cpp/src/Ice/WSConnector.cpp +113 -0
  419. data/ext/ice/cpp/src/Ice/WSConnector.h +51 -0
  420. data/ext/ice/cpp/src/Ice/WSEndpoint.cpp +441 -0
  421. data/ext/ice/cpp/src/Ice/WSEndpoint.h +97 -0
  422. data/ext/ice/cpp/src/Ice/WSTransceiver.cpp +1728 -0
  423. data/ext/ice/cpp/src/Ice/WSTransceiver.h +149 -0
  424. data/ext/ice/cpp/src/IceDiscovery/IceDiscovery.cpp +594 -0
  425. data/ext/ice/cpp/src/IceDiscovery/IceDiscovery.h +1035 -0
  426. data/ext/ice/cpp/src/IceDiscovery/LocatorI.cpp +208 -0
  427. data/ext/ice/cpp/src/IceDiscovery/LocatorI.h +78 -0
  428. data/ext/ice/cpp/src/IceDiscovery/LookupI.cpp +308 -0
  429. data/ext/ice/cpp/src/IceDiscovery/LookupI.h +183 -0
  430. data/ext/ice/cpp/src/IceDiscovery/Makefile +61 -0
  431. data/ext/ice/cpp/src/IceDiscovery/PluginI.cpp +148 -0
  432. data/ext/ice/cpp/src/IceDiscovery/PluginI.h +39 -0
  433. data/ext/ice/cpp/src/IceSSL/AcceptorI.cpp +258 -0
  434. data/ext/ice/cpp/src/IceSSL/AcceptorI.h +66 -0
  435. data/ext/ice/cpp/src/IceSSL/Certificate.cpp +1334 -0
  436. data/ext/ice/cpp/src/IceSSL/ConnectionInfo.cpp +42 -0
  437. data/ext/ice/cpp/src/IceSSL/ConnectorI.cpp +151 -0
  438. data/ext/ice/cpp/src/IceSSL/ConnectorI.h +56 -0
  439. data/ext/ice/cpp/src/IceSSL/EndpointI.cpp +397 -0
  440. data/ext/ice/cpp/src/IceSSL/EndpointI.h +96 -0
  441. data/ext/ice/cpp/src/IceSSL/EndpointInfo.cpp +41 -0
  442. data/ext/ice/cpp/src/IceSSL/Instance.cpp +38 -0
  443. data/ext/ice/cpp/src/IceSSL/Instance.h +42 -0
  444. data/ext/ice/cpp/src/IceSSL/InstanceF.h +34 -0
  445. data/ext/ice/cpp/src/IceSSL/Makefile +82 -0
  446. data/ext/ice/cpp/src/IceSSL/OpenSSLEngine.cpp +1001 -0
  447. data/ext/ice/cpp/src/IceSSL/OpenSSLTransceiverI.cpp +607 -0
  448. data/ext/ice/cpp/src/IceSSL/OpenSSLTransceiverI.h +75 -0
  449. data/ext/ice/cpp/src/IceSSL/PluginI.cpp +102 -0
  450. data/ext/ice/cpp/src/IceSSL/PluginI.h +56 -0
  451. data/ext/ice/cpp/src/IceSSL/RFC2253.cpp +541 -0
  452. data/ext/ice/cpp/src/IceSSL/RFC2253.h +67 -0
  453. data/ext/ice/cpp/src/IceSSL/SChannelEngine.cpp +729 -0
  454. data/ext/ice/cpp/src/IceSSL/SChannelTransceiverI.cpp +1062 -0
  455. data/ext/ice/cpp/src/IceSSL/SChannelTransceiverI.h +130 -0
  456. data/ext/ice/cpp/src/IceSSL/SSLEngine.cpp +291 -0
  457. data/ext/ice/cpp/src/IceSSL/SSLEngine.h +264 -0
  458. data/ext/ice/cpp/src/IceSSL/SSLEngineF.h +41 -0
  459. data/ext/ice/cpp/src/IceSSL/SecureTransportEngine.cpp +1514 -0
  460. data/ext/ice/cpp/src/IceSSL/SecureTransportTransceiverI.cpp +609 -0
  461. data/ext/ice/cpp/src/IceSSL/SecureTransportTransceiverI.h +91 -0
  462. data/ext/ice/cpp/src/IceSSL/TrustManager.cpp +246 -0
  463. data/ext/ice/cpp/src/IceSSL/TrustManager.h +51 -0
  464. data/ext/ice/cpp/src/IceSSL/TrustManagerF.h +26 -0
  465. data/ext/ice/cpp/src/IceSSL/Util.cpp +1423 -0
  466. data/ext/ice/cpp/src/IceSSL/Util.h +136 -0
  467. data/ext/ice/cpp/src/IceUtil/ArgVector.cpp +65 -0
  468. data/ext/ice/cpp/src/IceUtil/ArgVector.h +41 -0
  469. data/ext/ice/cpp/src/IceUtil/Cond.cpp +386 -0
  470. data/ext/ice/cpp/src/IceUtil/ConvertUTF.cpp +477 -0
  471. data/ext/ice/cpp/src/IceUtil/ConvertUTF.h +144 -0
  472. data/ext/ice/cpp/src/IceUtil/CountDownLatch.cpp +184 -0
  473. data/ext/ice/cpp/src/IceUtil/CtrlCHandler.cpp +273 -0
  474. data/ext/ice/cpp/src/IceUtil/Exception.cpp +782 -0
  475. data/ext/ice/cpp/src/IceUtil/FileUtil.cpp +532 -0
  476. data/ext/ice/cpp/src/IceUtil/FileUtil.h +159 -0
  477. data/ext/ice/cpp/src/IceUtil/InputUtil.cpp +41 -0
  478. data/ext/ice/cpp/src/IceUtil/Makefile +68 -0
  479. data/ext/ice/cpp/src/IceUtil/MutexProtocol.cpp +24 -0
  480. data/ext/ice/cpp/src/IceUtil/Options.cpp +1049 -0
  481. data/ext/ice/cpp/src/IceUtil/OutputUtil.cpp +591 -0
  482. data/ext/ice/cpp/src/IceUtil/Random.cpp +185 -0
  483. data/ext/ice/cpp/src/IceUtil/RecMutex.cpp +257 -0
  484. data/ext/ice/cpp/src/IceUtil/SHA1.cpp +126 -0
  485. data/ext/ice/cpp/src/IceUtil/Shared.cpp +200 -0
  486. data/ext/ice/cpp/src/IceUtil/StopWatch.h +54 -0
  487. data/ext/ice/cpp/src/IceUtil/StringConverter.cpp +450 -0
  488. data/ext/ice/cpp/src/IceUtil/StringUtil.cpp +842 -0
  489. data/ext/ice/cpp/src/IceUtil/Thread.cpp +809 -0
  490. data/ext/ice/cpp/src/IceUtil/ThreadException.cpp +172 -0
  491. data/ext/ice/cpp/src/IceUtil/Time.cpp +306 -0
  492. data/ext/ice/cpp/src/IceUtil/Timer.cpp +251 -0
  493. data/ext/ice/cpp/src/IceUtil/UUID.cpp +174 -0
  494. data/ext/ice/cpp/src/IceUtil/Unicode.cpp +131 -0
  495. data/ext/ice/cpp/src/IceUtil/Unicode.h +49 -0
  496. data/ext/ice/cpp/src/Slice/CPlusPlusUtil.cpp +1139 -0
  497. data/ext/ice/cpp/src/Slice/Checksum.cpp +452 -0
  498. data/ext/ice/cpp/src/Slice/CsUtil.cpp +2650 -0
  499. data/ext/ice/cpp/src/Slice/DotNetNames.cpp +146 -0
  500. data/ext/ice/cpp/src/Slice/FileTracker.cpp +203 -0
  501. data/ext/ice/cpp/src/Slice/Grammar.cpp +4755 -0
  502. data/ext/ice/cpp/src/Slice/Grammar.h +98 -0
  503. data/ext/ice/cpp/src/Slice/GrammarUtil.h +234 -0
  504. data/ext/ice/cpp/src/Slice/JavaUtil.cpp +4376 -0
  505. data/ext/ice/cpp/src/Slice/MD5.cpp +57 -0
  506. data/ext/ice/cpp/src/Slice/MD5.h +44 -0
  507. data/ext/ice/cpp/src/Slice/MD5I.cpp +385 -0
  508. data/ext/ice/cpp/src/Slice/MD5I.h +91 -0
  509. data/ext/ice/cpp/src/Slice/Makefile +65 -0
  510. data/ext/ice/cpp/src/Slice/PHPUtil.cpp +156 -0
  511. data/ext/ice/cpp/src/Slice/Parser.cpp +6386 -0
  512. data/ext/ice/cpp/src/Slice/Preprocessor.cpp +686 -0
  513. data/ext/ice/cpp/src/Slice/Python.cpp +675 -0
  514. data/ext/ice/cpp/src/Slice/PythonUtil.cpp +2614 -0
  515. data/ext/ice/cpp/src/Slice/Ruby.cpp +317 -0
  516. data/ext/ice/cpp/src/Slice/RubyUtil.cpp +1774 -0
  517. data/ext/ice/cpp/src/Slice/Scanner.cpp +2426 -0
  518. data/ext/ice/cpp/src/Slice/Util.cpp +325 -0
  519. data/ext/ice/mcpp/config.h.Darwin +227 -0
  520. data/ext/ice/mcpp/config.h.Linux +227 -0
  521. data/ext/ice/mcpp/config.h.MINGW +7 -0
  522. data/ext/ice/mcpp/configed.H +382 -0
  523. data/ext/ice/mcpp/directive.c +1699 -0
  524. data/ext/ice/mcpp/eval.c +1673 -0
  525. data/ext/ice/mcpp/expand.c +2980 -0
  526. data/ext/ice/mcpp/internal.H +564 -0
  527. data/ext/ice/mcpp/main.c +1131 -0
  528. data/ext/ice/mcpp/mbchar.c +869 -0
  529. data/ext/ice/mcpp/mcpp_lib.h +31 -0
  530. data/ext/ice/mcpp/mcpp_out.h +13 -0
  531. data/ext/ice/mcpp/support.c +2811 -0
  532. data/ext/ice/mcpp/system.H +396 -0
  533. data/ext/ice/mcpp/system.c +4940 -0
  534. data/ice.gemspec +41 -0
  535. data/lib/Glacier2.rb +12 -0
  536. data/lib/Glacier2/Metrics.rb +99 -0
  537. data/lib/Glacier2/PermissionsVerifier.rb +168 -0
  538. data/lib/Glacier2/PermissionsVerifierF.rb +34 -0
  539. data/lib/Glacier2/Router.rb +141 -0
  540. data/lib/Glacier2/RouterF.rb +29 -0
  541. data/lib/Glacier2/SSLInfo.rb +79 -0
  542. data/lib/Glacier2/Session.rb +470 -0
  543. data/lib/Ice.rb +659 -0
  544. data/lib/Ice/BuiltinSequences.rb +64 -0
  545. data/lib/Ice/Communicator.rb +93 -0
  546. data/lib/Ice/CommunicatorF.rb +28 -0
  547. data/lib/Ice/Connection.rb +414 -0
  548. data/lib/Ice/ConnectionF.rb +36 -0
  549. data/lib/Ice/Current.rb +152 -0
  550. data/lib/Ice/Endpoint.rb +265 -0
  551. data/lib/Ice/EndpointF.rb +52 -0
  552. data/lib/Ice/EndpointTypes.rb +77 -0
  553. data/lib/Ice/FacetMap.rb +28 -0
  554. data/lib/Ice/Identity.rb +70 -0
  555. data/lib/Ice/ImplicitContext.rb +59 -0
  556. data/lib/Ice/ImplicitContextF.rb +28 -0
  557. data/lib/Ice/Instrumentation.rb +425 -0
  558. data/lib/Ice/InstrumentationF.rb +35 -0
  559. data/lib/Ice/LocalException.rb +1081 -0
  560. data/lib/Ice/Locator.rb +314 -0
  561. data/lib/Ice/LocatorF.rb +34 -0
  562. data/lib/Ice/Logger.rb +57 -0
  563. data/lib/Ice/LoggerF.rb +28 -0
  564. data/lib/Ice/Metrics.rb +696 -0
  565. data/lib/Ice/ObjectAdapterF.rb +28 -0
  566. data/lib/Ice/ObjectFactory.rb +53 -0
  567. data/lib/Ice/ObjectFactoryF.rb +28 -0
  568. data/lib/Ice/Plugin.rb +87 -0
  569. data/lib/Ice/PluginF.rb +32 -0
  570. data/lib/Ice/Process.rb +93 -0
  571. data/lib/Ice/ProcessF.rb +29 -0
  572. data/lib/Ice/Properties.rb +65 -0
  573. data/lib/Ice/PropertiesAdmin.rb +104 -0
  574. data/lib/Ice/PropertiesF.rb +33 -0
  575. data/lib/Ice/Router.rb +163 -0
  576. data/lib/Ice/RouterF.rb +29 -0
  577. data/lib/Ice/SliceChecksumDict.rb +28 -0
  578. data/lib/Ice/Version.rb +100 -0
  579. data/lib/IceBox.rb +10 -0
  580. data/lib/IceBox/IceBox.rb +272 -0
  581. data/lib/IceGrid.rb +17 -0
  582. data/lib/IceGrid/Admin.rb +1076 -0
  583. data/lib/IceGrid/Descriptor.rb +1505 -0
  584. data/lib/IceGrid/Exception.rb +401 -0
  585. data/lib/IceGrid/FileParser.rb +105 -0
  586. data/lib/IceGrid/Locator.rb +105 -0
  587. data/lib/IceGrid/Observer.rb +571 -0
  588. data/lib/IceGrid/Query.rb +168 -0
  589. data/lib/IceGrid/Registry.rb +120 -0
  590. data/lib/IceGrid/Session.rb +114 -0
  591. data/lib/IceGrid/UserAccountMapper.rb +101 -0
  592. data/lib/IcePatch2.rb +10 -0
  593. data/lib/IcePatch2/FileInfo.rb +75 -0
  594. data/lib/IcePatch2/FileServer.rb +141 -0
  595. data/lib/IceStorm.rb +11 -0
  596. data/lib/IceStorm/IceStorm.rb +463 -0
  597. data/lib/IceStorm/Metrics.rb +155 -0
  598. data/slice/Freeze/BackgroundSaveEvictor.ice +111 -0
  599. data/slice/Freeze/CatalogData.ice +49 -0
  600. data/slice/Freeze/Connection.ice +111 -0
  601. data/slice/Freeze/ConnectionF.ice +20 -0
  602. data/slice/Freeze/DB.ice +37 -0
  603. data/slice/Freeze/Evictor.ice +339 -0
  604. data/slice/Freeze/EvictorF.ice +22 -0
  605. data/slice/Freeze/EvictorStorage.ice +72 -0
  606. data/slice/Freeze/Exception.ice +100 -0
  607. data/slice/Freeze/Transaction.ice +57 -0
  608. data/slice/Freeze/TransactionalEvictor.ice +50 -0
  609. data/slice/Glacier2/Metrics.ice +77 -0
  610. data/slice/Glacier2/PermissionsVerifier.ice +105 -0
  611. data/slice/Glacier2/PermissionsVerifierF.ice +21 -0
  612. data/slice/Glacier2/Router.ice +178 -0
  613. data/slice/Glacier2/RouterF.ice +20 -0
  614. data/slice/Glacier2/SSLInfo.ice +50 -0
  615. data/slice/Glacier2/Session.ice +273 -0
  616. data/slice/Ice/BuiltinSequences.ice +48 -0
  617. data/slice/Ice/Communicator.ice +567 -0
  618. data/slice/Ice/CommunicatorF.ice +20 -0
  619. data/slice/Ice/Connection.ice +323 -0
  620. data/slice/Ice/ConnectionF.ice +22 -0
  621. data/slice/Ice/Current.ice +160 -0
  622. data/slice/Ice/Endpoint.ice +227 -0
  623. data/slice/Ice/EndpointF.ice +32 -0
  624. data/slice/Ice/EndpointTypes.ice +38 -0
  625. data/slice/Ice/FacetMap.ice +25 -0
  626. data/slice/Ice/Identity.ice +59 -0
  627. data/slice/Ice/ImplicitContext.ice +109 -0
  628. data/slice/Ice/ImplicitContextF.ice +20 -0
  629. data/slice/Ice/Instrumentation.ice +499 -0
  630. data/slice/Ice/InstrumentationF.ice +26 -0
  631. data/slice/Ice/LocalException.ice +1015 -0
  632. data/slice/Ice/Locator.ice +227 -0
  633. data/slice/Ice/LocatorF.ice +21 -0
  634. data/slice/Ice/Logger.ice +86 -0
  635. data/slice/Ice/LoggerF.ice +20 -0
  636. data/slice/Ice/Metrics.ice +422 -0
  637. data/slice/Ice/ObjectAdapter.ice +673 -0
  638. data/slice/Ice/ObjectAdapterF.ice +20 -0
  639. data/slice/Ice/ObjectFactory.ice +60 -0
  640. data/slice/Ice/ObjectFactoryF.ice +20 -0
  641. data/slice/Ice/Plugin.ice +117 -0
  642. data/slice/Ice/PluginF.ice +21 -0
  643. data/slice/Ice/Process.ice +54 -0
  644. data/slice/Ice/ProcessF.ice +20 -0
  645. data/slice/Ice/Properties.ice +228 -0
  646. data/slice/Ice/PropertiesAdmin.ice +75 -0
  647. data/slice/Ice/PropertiesF.ice +21 -0
  648. data/slice/Ice/RemoteLogger.ice +232 -0
  649. data/slice/Ice/Router.ice +83 -0
  650. data/slice/Ice/RouterF.ice +20 -0
  651. data/slice/Ice/ServantLocator.ice +117 -0
  652. data/slice/Ice/ServantLocatorF.ice +20 -0
  653. data/slice/Ice/SliceChecksumDict.ice +25 -0
  654. data/slice/Ice/Version.ice +39 -0
  655. data/slice/IceBox/IceBox.ice +194 -0
  656. data/slice/IceDiscovery/IceDiscovery.ice +32 -0
  657. data/slice/IceGrid/Admin.ice +1578 -0
  658. data/slice/IceGrid/Descriptor.ice +1079 -0
  659. data/slice/IceGrid/Discovery.ice +73 -0
  660. data/slice/IceGrid/Exception.ice +383 -0
  661. data/slice/IceGrid/FileParser.ice +61 -0
  662. data/slice/IceGrid/Locator.ice +56 -0
  663. data/slice/IceGrid/Observer.ice +394 -0
  664. data/slice/IceGrid/PluginFacade.ice +316 -0
  665. data/slice/IceGrid/Query.ice +130 -0
  666. data/slice/IceGrid/Registry.ice +138 -0
  667. data/slice/IceGrid/Session.ice +124 -0
  668. data/slice/IceGrid/UserAccountMapper.ice +58 -0
  669. data/slice/IcePatch2/FileInfo.ice +49 -0
  670. data/slice/IcePatch2/FileServer.ice +129 -0
  671. data/slice/IceSSL/ConnectionInfo.ice +34 -0
  672. data/slice/IceSSL/EndpointInfo.ice +41 -0
  673. data/slice/IceStorm/IceStorm.ice +405 -0
  674. data/slice/IceStorm/Metrics.ice +71 -0
  675. metadata +737 -0
@@ -0,0 +1,14 @@
1
+ // **********************************************************************
2
+ //
3
+ // Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
4
+ //
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
+
10
+ #include <Ice/MetricsObserverI.h>
11
+
12
+ #include <Ice/Connection.h>
13
+ #include <Ice/Endpoint.h>
14
+
@@ -0,0 +1,2694 @@
1
+ // **********************************************************************
2
+ //
3
+ // Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
4
+ //
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
+
10
+ //
11
+ // The following is required on HP-UX in order to bring in
12
+ // the definition for the ip_mreq structure.
13
+ //
14
+ #if defined(__hpux)
15
+ # undef _XOPEN_SOURCE_EXTENDED
16
+ # define _XOPEN_SOURCE
17
+ # include <netinet/in.h>
18
+ #endif
19
+
20
+ #include <IceUtil/DisableWarnings.h>
21
+ #include <Ice/Network.h>
22
+ #include <Ice/NetworkProxy.h>
23
+ #include <IceUtil/StringUtil.h>
24
+ #include <IceUtil/StringConverter.h>
25
+ #include <Ice/LocalException.h>
26
+ #include <Ice/Properties.h> // For setTcpBufSize
27
+ #include <Ice/LoggerUtil.h> // For setTcpBufSize
28
+ #include <Ice/Buffer.h>
29
+ #include <IceUtil/Random.h>
30
+
31
+ #if defined(ICE_OS_WINRT)
32
+ # include <IceUtil/InputUtil.h>
33
+ # include <IceUtil/CountDownLatch.h>
34
+ #elif defined(_WIN32)
35
+ # include <winsock2.h>
36
+ # include <ws2tcpip.h>
37
+ # ifdef __MINGW32__
38
+ # include <wincrypt.h>
39
+ # endif
40
+ # include <iphlpapi.h>
41
+ # include <Mswsock.h>
42
+ # include <mstcpip.h>
43
+ #else
44
+ # include <net/if.h>
45
+ # include <sys/ioctl.h>
46
+ #endif
47
+
48
+ #if defined(__linux) || defined(__APPLE__) || defined(__FreeBSD__)
49
+ # include <ifaddrs.h>
50
+ #elif defined(__sun)
51
+ # include <sys/sockio.h>
52
+ #endif
53
+
54
+ #if defined(_WIN32)
55
+ # ifndef SIO_LOOPBACK_FAST_PATH
56
+ # define SIO_LOOPBACK_FAST_PATH _WSAIOW(IOC_VENDOR,16)
57
+ # endif
58
+ #endif
59
+
60
+ #if defined(__MINGW32__)
61
+ //
62
+ // Work-around for missing definitions in MinGW Windows headers
63
+ //
64
+ # ifndef IPV6_V6ONLY
65
+ # define IPV6_V6ONLY 27
66
+ # endif
67
+
68
+ extern "C"
69
+ {
70
+ WINSOCK_API_LINKAGE int WSAAPI inet_pton(INT, PCTSTR, PVOID);
71
+ }
72
+ #endif
73
+
74
+
75
+ using namespace std;
76
+ using namespace Ice;
77
+ using namespace IceInternal;
78
+
79
+ #ifdef ICE_OS_WINRT
80
+ using namespace Platform;
81
+ using namespace Windows::Foundation;
82
+ using namespace Windows::Storage::Streams;
83
+ using namespace Windows::Networking;
84
+ using namespace Windows::Networking::Sockets;
85
+ #endif
86
+
87
+ namespace
88
+ {
89
+
90
+ #ifndef ICE_OS_WINRT
91
+ struct AddressIsIPv6 : public unary_function<Address, bool>
92
+ {
93
+ public:
94
+
95
+ bool
96
+ operator()(const Address& ss) const
97
+ {
98
+ return ss.saStorage.ss_family == AF_INET6;
99
+ }
100
+ };
101
+
102
+ struct RandomNumberGenerator : public std::unary_function<ptrdiff_t, ptrdiff_t>
103
+ {
104
+ ptrdiff_t operator()(ptrdiff_t d)
105
+ {
106
+ return IceUtilInternal::random(static_cast<int>(d));
107
+ }
108
+ };
109
+
110
+ void
111
+ sortAddresses(vector<Address>& addrs, ProtocolSupport protocol, Ice::EndpointSelectionType selType, bool preferIPv6)
112
+ {
113
+ if(selType == Ice::Random)
114
+ {
115
+ RandomNumberGenerator rng;
116
+ random_shuffle(addrs.begin(), addrs.end(), rng);
117
+ }
118
+
119
+ if(protocol == EnableBoth)
120
+ {
121
+ if(preferIPv6)
122
+ {
123
+ stable_partition(addrs.begin(), addrs.end(), AddressIsIPv6());
124
+ }
125
+ else
126
+ {
127
+ stable_partition(addrs.begin(), addrs.end(), not1(AddressIsIPv6()));
128
+ }
129
+ }
130
+ }
131
+
132
+ void
133
+ setTcpNoDelay(SOCKET fd)
134
+ {
135
+ int flag = 1;
136
+ if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
137
+ {
138
+ closeSocketNoThrow(fd);
139
+ SocketException ex(__FILE__, __LINE__);
140
+ ex.error = getSocketErrno();
141
+ throw ex;
142
+ }
143
+ }
144
+
145
+ void
146
+ setKeepAlive(SOCKET fd)
147
+ {
148
+ int flag = 1;
149
+ if(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
150
+ {
151
+ closeSocketNoThrow(fd);
152
+ SocketException ex(__FILE__, __LINE__);
153
+ ex.error = getSocketErrno();
154
+ throw ex;
155
+ }
156
+ }
157
+ #endif
158
+
159
+ #if defined(_WIN32) && !defined(ICE_OS_WINRT)
160
+ void
161
+ setTcpLoopbackFastPath(SOCKET fd)
162
+ {
163
+ int OptionValue = 1;
164
+ DWORD NumberOfBytesReturned = 0;
165
+
166
+ int status =
167
+ WSAIoctl(fd, SIO_LOOPBACK_FAST_PATH, &OptionValue, sizeof(OptionValue), NULL, 0, &NumberOfBytesReturned, 0, 0);
168
+ if(status == SOCKET_ERROR)
169
+ {
170
+ // On platforms that do not support fast path (< Windows 8), WSAEONOTSUPP is expected.
171
+ DWORD LastError = ::GetLastError();
172
+ if(LastError != WSAEOPNOTSUPP)
173
+ {
174
+ closeSocketNoThrow(fd);
175
+ SocketException ex(__FILE__, __LINE__);
176
+ ex.error = getSocketErrno();
177
+ throw ex;
178
+ }
179
+ }
180
+ }
181
+ #endif
182
+
183
+ #ifdef ICE_OS_WINRT
184
+ SOCKET
185
+ createSocketImpl(bool udp, int)
186
+ {
187
+ SOCKET fd;
188
+
189
+ if(udp)
190
+ {
191
+ return ref new DatagramSocket();
192
+ }
193
+ else
194
+ {
195
+ StreamSocket^ socket = ref new StreamSocket();
196
+ socket->Control->KeepAlive = true;
197
+ socket->Control->NoDelay = true;
198
+ return socket;
199
+ }
200
+
201
+ return fd;
202
+ }
203
+ #else
204
+ SOCKET
205
+ createSocketImpl(bool udp, int family)
206
+ {
207
+ SOCKET fd;
208
+ if(udp)
209
+ {
210
+ fd = socket(family, SOCK_DGRAM, IPPROTO_UDP);
211
+ }
212
+ else
213
+ {
214
+ fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
215
+ }
216
+
217
+ if(fd == INVALID_SOCKET)
218
+ {
219
+ SocketException ex(__FILE__, __LINE__);
220
+ ex.error = getSocketErrno();
221
+ throw ex;
222
+ }
223
+
224
+ if(!udp)
225
+ {
226
+ setTcpNoDelay(fd);
227
+ setKeepAlive(fd);
228
+
229
+ #if defined(_WIN32) && !defined(ICE_OS_WINRT)
230
+ //
231
+ // FIX: the fast path loopback appears to cause issues with
232
+ // connection closure when it's enabled. Sometime, a peer
233
+ // doesn't receive the TCP/IP connection closure (RST) from
234
+ // the other peer and it ends up hanging. This is showing up
235
+ // with the background test when ran with WS. The test
236
+ // sporadically hangs on exit. See bug #6093.
237
+ //
238
+ //setTcpLoopbackFastPath(fd);
239
+ #endif
240
+ }
241
+
242
+ return fd;
243
+ }
244
+ #endif
245
+
246
+ #ifndef ICE_OS_WINRT
247
+ vector<Address>
248
+ getLocalAddresses(ProtocolSupport protocol, bool includeLoopback)
249
+ {
250
+ vector<Address> result;
251
+
252
+ #if defined(_WIN32)
253
+ DWORD family;
254
+ switch(protocol)
255
+ {
256
+ case EnableIPv4:
257
+ family = AF_INET;
258
+ break;
259
+ case EnableIPv6:
260
+ family = AF_INET6;
261
+ break;
262
+ default:
263
+ family = AF_UNSPEC;
264
+ break;
265
+ }
266
+
267
+ DWORD size;
268
+ DWORD rv = GetAdaptersAddresses(family, 0, NULL, NULL, &size);
269
+ if (rv == ERROR_BUFFER_OVERFLOW)
270
+ {
271
+ PIP_ADAPTER_ADDRESSES adapter_addresses = (PIP_ADAPTER_ADDRESSES) malloc(size);
272
+ rv = GetAdaptersAddresses(family, 0, NULL, adapter_addresses, &size);
273
+ if (rv == ERROR_SUCCESS)
274
+ {
275
+ for (PIP_ADAPTER_ADDRESSES aa = adapter_addresses; aa != NULL; aa = aa->Next)
276
+ {
277
+ for (PIP_ADAPTER_UNICAST_ADDRESS ua = aa->FirstUnicastAddress; ua != NULL; ua = ua->Next)
278
+ {
279
+ Address addr;
280
+ memcpy(&addr.saStorage, ua->Address.lpSockaddr, ua->Address.iSockaddrLength);
281
+ if(addr.saStorage.ss_family == AF_INET && protocol != EnableIPv6)
282
+ {
283
+ if(addr.saIn.sin_addr.s_addr != 0 &&
284
+ (includeLoopback || addr.saIn.sin_addr.s_addr != htonl(INADDR_LOOPBACK)))
285
+ {
286
+ result.push_back(addr);
287
+ }
288
+ }
289
+ else if(addr.saStorage.ss_family == AF_INET6 && protocol != EnableIPv4)
290
+ {
291
+ if(!IN6_IS_ADDR_UNSPECIFIED(&addr.saIn6.sin6_addr) &&
292
+ (includeLoopback || !IN6_IS_ADDR_LOOPBACK(&addr.saIn6.sin6_addr)))
293
+ {
294
+ result.push_back(addr);
295
+ }
296
+ }
297
+ }
298
+ }
299
+ }
300
+
301
+ free(adapter_addresses);
302
+ }
303
+ #elif defined(__linux) || defined(__APPLE__) || defined(__FreeBSD__)
304
+ struct ifaddrs* ifap;
305
+ if(::getifaddrs(&ifap) == SOCKET_ERROR)
306
+ {
307
+ SocketException ex(__FILE__, __LINE__);
308
+ ex.error = getSocketErrno();
309
+ throw ex;
310
+ }
311
+
312
+ struct ifaddrs* curr = ifap;
313
+ while(curr != 0)
314
+ {
315
+ if(curr->ifa_addr && (includeLoopback || !(curr->ifa_flags & IFF_LOOPBACK)))
316
+ {
317
+ if(curr->ifa_addr->sa_family == AF_INET && protocol != EnableIPv6)
318
+ {
319
+ Address addr;
320
+ memcpy(&addr.saStorage, curr->ifa_addr, sizeof(sockaddr_in));
321
+ if(addr.saIn.sin_addr.s_addr != 0)
322
+ {
323
+ result.push_back(addr);
324
+ }
325
+ }
326
+ else if(curr->ifa_addr->sa_family == AF_INET6 && protocol != EnableIPv4)
327
+ {
328
+ Address addr;
329
+ memcpy(&addr.saStorage, curr->ifa_addr, sizeof(sockaddr_in6));
330
+ if(!IN6_IS_ADDR_UNSPECIFIED(&addr.saIn6.sin6_addr))
331
+ {
332
+ result.push_back(addr);
333
+ }
334
+ }
335
+ }
336
+
337
+ curr = curr->ifa_next;
338
+ }
339
+
340
+ ::freeifaddrs(ifap);
341
+ #else
342
+ for(int i = 0; i < 2; i++)
343
+ {
344
+ if((i == 0 && protocol == EnableIPv6) || (i == 1 && protocol == EnableIPv4))
345
+ {
346
+ continue;
347
+ }
348
+ SOCKET fd = createSocketImpl(false, i == 0 ? AF_INET : AF_INET6);
349
+
350
+ #ifdef _AIX
351
+ int cmd = CSIOCGIFCONF;
352
+ #else
353
+ int cmd = SIOCGIFCONF;
354
+ #endif
355
+ struct ifconf ifc;
356
+ int numaddrs = 10;
357
+ int old_ifc_len = 0;
358
+
359
+ //
360
+ // Need to call ioctl multiple times since we do not know up front
361
+ // how many addresses there will be, and thus how large a buffer we need.
362
+ // We keep increasing the buffer size until subsequent calls return
363
+ // the same length, meaning we have all the addresses.
364
+ //
365
+ while(true)
366
+ {
367
+ int bufsize = numaddrs * static_cast<int>(sizeof(struct ifreq));
368
+ ifc.ifc_len = bufsize;
369
+ ifc.ifc_buf = (char*)malloc(bufsize);
370
+
371
+ int rs = ioctl(fd, cmd, &ifc);
372
+ if(rs == SOCKET_ERROR)
373
+ {
374
+ free(ifc.ifc_buf);
375
+ closeSocketNoThrow(fd);
376
+ SocketException ex(__FILE__, __LINE__);
377
+ ex.error = getSocketErrno();
378
+ throw ex;
379
+ }
380
+ else if(ifc.ifc_len == old_ifc_len)
381
+ {
382
+ //
383
+ // Returned same length twice in a row, finished.
384
+ //
385
+ break;
386
+ }
387
+ else
388
+ {
389
+ old_ifc_len = ifc.ifc_len;
390
+ }
391
+
392
+ numaddrs += 10;
393
+ free(ifc.ifc_buf);
394
+ }
395
+ closeSocket(fd);
396
+
397
+ numaddrs = ifc.ifc_len / static_cast<int>(sizeof(struct ifreq));
398
+ struct ifreq* ifr = ifc.ifc_req;
399
+ for(int i = 0; i < numaddrs; ++i)
400
+ {
401
+ if(!(ifr[i].ifr_flags & IFF_LOOPBACK)) // Don't include loopback interface addresses
402
+ {
403
+ //
404
+ // On Solaris the above Loopback check does not always work so we double
405
+ // check the address below. Solaris also returns duplicate entries that need
406
+ // to be filtered out.
407
+ //
408
+ if(ifr[i].ifr_addr.sa_family == AF_INET && protocol != EnableIPv6)
409
+ {
410
+ Address addr;
411
+ memcpy(&addr.saStorage, &ifr[i].ifr_addr, sizeof(sockaddr_in));
412
+ if(addr.saIn.sin_addr.s_addr != 0 &&
413
+ (includeLoopback || addr.saIn.sin_addr.s_addr != htonl(INADDR_LOOPBACK)))
414
+ {
415
+ unsigned int j;
416
+ for(j = 0; j < result.size(); ++j)
417
+ {
418
+ if(compareAddress(addr, result[j]) == 0)
419
+ {
420
+ break;
421
+ }
422
+ }
423
+ if(j == result.size())
424
+ {
425
+ result.push_back(addr);
426
+ }
427
+ }
428
+ }
429
+ else if(ifr[i].ifr_addr.sa_family == AF_INET6 && protocol != EnableIPv4)
430
+ {
431
+ Address addr;
432
+ memcpy(&addr.saStorage, &ifr[i].ifr_addr, sizeof(sockaddr_in6));
433
+ if(!IN6_IS_ADDR_UNSPECIFIED(&addr.saIn6.sin6_addr) &&
434
+ (includeLoopback || !IN6_IS_ADDR_LOOPBACK(&addr.saIn6.sin6_addr)))
435
+ {
436
+ unsigned int j;
437
+ for(j = 0; j < result.size(); ++j)
438
+ {
439
+ if(compareAddress(addr, result[j]) == 0)
440
+ {
441
+ break;
442
+ }
443
+ }
444
+ if(j == result.size())
445
+ {
446
+ result.push_back(addr);
447
+ }
448
+ }
449
+ }
450
+ }
451
+ }
452
+ free(ifc.ifc_buf);
453
+ }
454
+ #endif
455
+
456
+ return result;
457
+ }
458
+
459
+ bool
460
+ isLinklocal(const Address& addr)
461
+ {
462
+ if (addr.saStorage.ss_family == AF_INET6)
463
+ {
464
+ return IN6_IS_ADDR_LINKLOCAL(&addr.saIn6.sin6_addr);
465
+ }
466
+ else if (addr.saStorage.ss_family == AF_INET)
467
+ {
468
+ // Check for 169.254.X.X in network order
469
+ return (addr.saIn.sin_addr.s_addr & 0xFF) == 169 && ((addr.saIn.sin_addr.s_addr & 0xFF00)>>8) == 254;
470
+ }
471
+ return false;
472
+ }
473
+
474
+ bool
475
+ isWildcard(const string& host, ProtocolSupport protocol, bool& ipv4)
476
+ {
477
+ try
478
+ {
479
+ Address addr = getAddressForServer(host, 0, protocol, true);
480
+ if(addr.saStorage.ss_family == AF_INET)
481
+ {
482
+ if(addr.saIn.sin_addr.s_addr == INADDR_ANY)
483
+ {
484
+ ipv4 = true;
485
+ return true;
486
+ }
487
+ }
488
+ else if(addr.saStorage.ss_family)
489
+ {
490
+ if(IN6_IS_ADDR_UNSPECIFIED(&addr.saIn6.sin6_addr))
491
+ {
492
+ ipv4 = false;
493
+ return true;
494
+ }
495
+ }
496
+ }
497
+ catch(const DNSException&)
498
+ {
499
+ }
500
+ return false;
501
+ }
502
+
503
+ int
504
+ getInterfaceIndex(const string& name)
505
+ {
506
+ if(name.empty())
507
+ {
508
+ return 0;
509
+ }
510
+
511
+ int index = 0;
512
+
513
+ //
514
+ // First check if index
515
+ //
516
+ istringstream p(name);
517
+ if((p >> index) && p.eof())
518
+ {
519
+ return index;
520
+ }
521
+
522
+ //
523
+ // Then check if it's an IPv6 address. If it's an address we'll
524
+ // look for the interface index by address.
525
+ //
526
+ in6_addr addr;
527
+ bool isAddr = inet_pton(AF_INET6, name.c_str(), &addr) > 0;
528
+
529
+ #ifdef _WIN32
530
+ IP_ADAPTER_ADDRESSES addrs;
531
+ ULONG buflen = 0;
532
+ if(::GetAdaptersAddresses(AF_INET6, 0, 0, &addrs, &buflen) == ERROR_BUFFER_OVERFLOW)
533
+ {
534
+ PIP_ADAPTER_ADDRESSES paddrs;
535
+ char* buf = new char[buflen];
536
+ paddrs = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buf);
537
+ if(::GetAdaptersAddresses(AF_INET6, 0, 0, paddrs, &buflen) == NO_ERROR)
538
+ {
539
+ while(paddrs)
540
+ {
541
+ if(isAddr)
542
+ {
543
+ PIP_ADAPTER_UNICAST_ADDRESS ipAddr = paddrs->FirstUnicastAddress;
544
+ while(ipAddr)
545
+ {
546
+ if(ipAddr->Address.lpSockaddr->sa_family == AF_INET6)
547
+ {
548
+ struct sockaddr_in6* ipv6Addr =
549
+ reinterpret_cast<struct sockaddr_in6*>(ipAddr->Address.lpSockaddr);
550
+ if(memcmp(&addr, &ipv6Addr->sin6_addr, sizeof(in6_addr)) == 0)
551
+ {
552
+ break;
553
+ }
554
+ }
555
+ ipAddr = ipAddr->Next;
556
+ }
557
+ if(ipAddr)
558
+ {
559
+ index = paddrs->Ipv6IfIndex;
560
+ break;
561
+ }
562
+ }
563
+ else
564
+ {
565
+ //
566
+ // Don't need to pass a wide string converter as the wide string
567
+ // come from Windows API.
568
+ //
569
+ if(IceUtil::wstringToString(paddrs->FriendlyName, IceUtil::getProcessStringConverter()) == name)
570
+ {
571
+ index = paddrs->Ipv6IfIndex;
572
+ break;
573
+ }
574
+ }
575
+ paddrs = paddrs->Next;
576
+ }
577
+ }
578
+ delete[] buf;
579
+ }
580
+ #elif !defined(__hpux)
581
+
582
+ //
583
+ // Look for an interface with a matching IP address
584
+ //
585
+ if(isAddr)
586
+ {
587
+ # if defined(__linux) || defined(__APPLE__) || defined(__FreeBSD__)
588
+ struct ifaddrs* ifap;
589
+ if(::getifaddrs(&ifap) != SOCKET_ERROR)
590
+ {
591
+ struct ifaddrs* curr = ifap;
592
+ while(curr != 0)
593
+ {
594
+ if(curr->ifa_addr && curr->ifa_addr->sa_family == AF_INET6)
595
+ {
596
+ struct sockaddr_in6* ipv6Addr = reinterpret_cast<struct sockaddr_in6*>(curr->ifa_addr);
597
+ if(memcmp(&addr, &ipv6Addr->sin6_addr, sizeof(in6_addr)) == 0)
598
+ {
599
+ index = if_nametoindex(curr->ifa_name);
600
+ break;
601
+ }
602
+ }
603
+ curr = curr->ifa_next;
604
+ }
605
+ ::freeifaddrs(ifap);
606
+ }
607
+ # else
608
+ SOCKET fd = createSocketImpl(false, AF_INET6);
609
+ # ifdef _AIX
610
+ int cmd = CSIOCGIFCONF;
611
+ # else
612
+ int cmd = SIOCGIFCONF;
613
+ # endif
614
+ struct ifconf ifc;
615
+ int numaddrs = 10;
616
+ int old_ifc_len = 0;
617
+
618
+ //
619
+ // Need to call ioctl multiple times since we do not know up front
620
+ // how many addresses there will be, and thus how large a buffer we need.
621
+ // We keep increasing the buffer size until subsequent calls return
622
+ // the same length, meaning we have all the addresses.
623
+ //
624
+ while(true)
625
+ {
626
+ int bufsize = numaddrs * static_cast<int>(sizeof(struct ifreq));
627
+ ifc.ifc_len = bufsize;
628
+ ifc.ifc_buf = (char*)malloc(bufsize);
629
+
630
+ int rs = ioctl(fd, cmd, &ifc);
631
+ if(rs == SOCKET_ERROR)
632
+ {
633
+ free(ifc.ifc_buf);
634
+ ifc.ifc_buf = 0;
635
+ break;
636
+ }
637
+ else if(ifc.ifc_len == old_ifc_len)
638
+ {
639
+ //
640
+ // Returned same length twice in a row, finished.
641
+ //
642
+ break;
643
+ }
644
+ else
645
+ {
646
+ old_ifc_len = ifc.ifc_len;
647
+ }
648
+ numaddrs += 10;
649
+ free(ifc.ifc_buf);
650
+ }
651
+ closeSocketNoThrow(fd);
652
+
653
+ if(ifc.ifc_buf)
654
+ {
655
+ numaddrs = ifc.ifc_len / static_cast<int>(sizeof(struct ifreq));
656
+ struct ifreq* ifr = ifc.ifc_req;
657
+ for(int i = 0; i < numaddrs; ++i)
658
+ {
659
+ if(ifr[i].ifr_addr.sa_family == AF_INET6)
660
+ {
661
+ struct sockaddr_in6* ipv6Addr = reinterpret_cast<struct sockaddr_in6*>(&ifr[i].ifr_addr);
662
+ if(memcmp(&addr, &ipv6Addr->sin6_addr, sizeof(in6_addr)) == 0)
663
+ {
664
+ index = if_nametoindex(ifr[i].ifr_name);
665
+ break;
666
+ }
667
+ }
668
+ }
669
+ free(ifc.ifc_buf);
670
+ }
671
+ # endif
672
+ }
673
+ else // Look for an interface with the given name.
674
+ {
675
+ index = if_nametoindex(name.c_str());
676
+ }
677
+ #endif
678
+
679
+ return index;
680
+ }
681
+
682
+ struct in_addr
683
+ getInterfaceAddress(const string& name)
684
+ {
685
+ struct in_addr addr;
686
+ addr.s_addr = INADDR_ANY;
687
+ if(name.empty())
688
+ {
689
+ return addr;
690
+ }
691
+
692
+ if(inet_pton(AF_INET, name.c_str(), &addr) > 0)
693
+ {
694
+ return addr;
695
+ }
696
+
697
+ #ifdef _WIN32
698
+ IP_ADAPTER_ADDRESSES addrs;
699
+ ULONG buflen = 0;
700
+ if(::GetAdaptersAddresses(AF_INET, 0, 0, &addrs, &buflen) == ERROR_BUFFER_OVERFLOW)
701
+ {
702
+ PIP_ADAPTER_ADDRESSES paddrs;
703
+ char* buf = new char[buflen];
704
+ paddrs = reinterpret_cast<PIP_ADAPTER_ADDRESSES>(buf);
705
+ if(::GetAdaptersAddresses(AF_INET, 0, 0, paddrs, &buflen) == NO_ERROR)
706
+ {
707
+ while(paddrs)
708
+ {
709
+ //
710
+ // Don't need to pass a wide string converter as the wide string come
711
+ // from Windows API.
712
+ //
713
+ if(IceUtil::wstringToString(paddrs->FriendlyName, IceUtil::getProcessStringConverter()) == name)
714
+ {
715
+ struct sockaddr_in addrin;
716
+ memcpy(&addrin, paddrs->FirstUnicastAddress->Address.lpSockaddr,
717
+ paddrs->FirstUnicastAddress->Address.iSockaddrLength);
718
+ addr = addrin.sin_addr;
719
+ break;
720
+ }
721
+ paddrs = paddrs->Next;
722
+ }
723
+ }
724
+ delete[] buf;
725
+ }
726
+ #else
727
+ ifreq if_address;
728
+ strcpy(if_address.ifr_name, name.c_str());
729
+
730
+ SOCKET fd = createSocketImpl(false, AF_INET);
731
+ int rc = ioctl(fd, SIOCGIFADDR, &if_address);
732
+ closeSocketNoThrow(fd);
733
+
734
+ if(rc != SOCKET_ERROR)
735
+ {
736
+ addr = reinterpret_cast<struct sockaddr_in*>(&if_address.ifr_addr)->sin_addr;
737
+ }
738
+ #endif
739
+
740
+ return addr;
741
+ }
742
+
743
+ int
744
+ getAddressStorageSize(const Address& addr)
745
+ {
746
+ int size = 0;
747
+ if(addr.saStorage.ss_family == AF_INET)
748
+ {
749
+ size = sizeof(sockaddr_in);
750
+ }
751
+ else if(addr.saStorage.ss_family == AF_INET6)
752
+ {
753
+ size = sizeof(sockaddr_in6);
754
+ }
755
+ return size;
756
+ }
757
+
758
+ #endif // #ifndef ICE_OS_WINRT
759
+
760
+ }
761
+
762
+ #ifdef ICE_USE_IOCP
763
+ IceInternal::AsyncInfo::AsyncInfo(SocketOperation s)
764
+ {
765
+ ZeroMemory(this, sizeof(AsyncInfo));
766
+ status = s;
767
+ }
768
+
769
+ void
770
+ IceInternal::NativeInfo::initialize(HANDLE handle, ULONG_PTR key)
771
+ {
772
+ _handle = handle;
773
+ _key = key;
774
+ }
775
+
776
+ void
777
+ IceInternal::NativeInfo::completed(SocketOperation operation)
778
+ {
779
+ if(!PostQueuedCompletionStatus(_handle, 0, _key, getAsyncInfo(operation)))
780
+ {
781
+ Ice::SocketException ex(__FILE__, __LINE__);
782
+ ex.error = GetLastError();
783
+ throw ex;
784
+ }
785
+ }
786
+ #elif defined(ICE_OS_WINRT)
787
+
788
+ void
789
+ IceInternal::NativeInfo::completed(SocketOperation operation)
790
+ {
791
+ assert(_completedHandler);
792
+ _completedHandler(operation);
793
+ }
794
+
795
+ #endif
796
+
797
+ bool
798
+ IceInternal::noMoreFds(int error)
799
+ {
800
+ #if defined(ICE_OS_WINRT)
801
+ return error == (int)SocketErrorStatus::TooManyOpenFiles;
802
+ #elif defined(_WIN32)
803
+ return error == WSAEMFILE;
804
+ #else
805
+ return error == EMFILE || error == ENFILE;
806
+ #endif
807
+ }
808
+
809
+ #if defined(ICE_OS_WINRT)
810
+ string
811
+ IceInternal::errorToStringDNS(int)
812
+ {
813
+ return "Host not found";
814
+ }
815
+ #else
816
+ string
817
+ IceInternal::errorToStringDNS(int error)
818
+ {
819
+ # if defined(_WIN32)
820
+ return IceUtilInternal::errorToString(error);
821
+ # else
822
+ return gai_strerror(error);
823
+ # endif
824
+ }
825
+ #endif
826
+
827
+ #ifdef ICE_OS_WINRT
828
+ vector<Address>
829
+ IceInternal::getAddresses(const string& host, int port, ProtocolSupport, Ice::EndpointSelectionType, bool, bool)
830
+ {
831
+ try
832
+ {
833
+ vector<Address> result;
834
+ Address addr;
835
+ if(host.empty())
836
+ {
837
+ addr.host = ref new HostName("localhost");
838
+ }
839
+ else
840
+ {
841
+ //
842
+ // Don't need to pass a wide string converter as the wide string is passed
843
+ // to Windows API.
844
+ //
845
+ addr.host = ref new HostName(ref new String(
846
+ IceUtil::stringToWstring(host,
847
+ IceUtil::getProcessStringConverter()).c_str()));
848
+ }
849
+ stringstream os;
850
+ os << port;
851
+ //
852
+ // Don't need to use any string converter here as the port number use just
853
+ // ACII characters.
854
+ //
855
+ addr.port = ref new String(IceUtil::stringToWstring(os.str()).c_str());
856
+ result.push_back(addr);
857
+ return result;
858
+ }
859
+ catch(Platform::Exception^ pex)
860
+ {
861
+ DNSException ex(__FILE__, __LINE__);
862
+ ex.error = (int)SocketError::GetStatus(pex->HResult);
863
+ ex.host = host;
864
+ throw ex;
865
+ }
866
+
867
+ }
868
+ #else
869
+ vector<Address>
870
+ IceInternal::getAddresses(const string& host, int port, ProtocolSupport protocol, Ice::EndpointSelectionType selType,
871
+ bool preferIPv6, bool blocking)
872
+ {
873
+ vector<Address> result;
874
+ Address addr;
875
+
876
+ memset(&addr.saStorage, 0, sizeof(sockaddr_storage));
877
+
878
+ //
879
+ // We don't use getaddrinfo when host is empty as it's not portable (some old Linux
880
+ // versions don't support it).
881
+ //
882
+ if(host.empty())
883
+ {
884
+ if(protocol != EnableIPv4)
885
+ {
886
+ addr.saIn6.sin6_family = AF_INET6;
887
+ addr.saIn6.sin6_port = htons(port);
888
+ addr.saIn6.sin6_addr = in6addr_loopback;
889
+ result.push_back(addr);
890
+ }
891
+ if(protocol != EnableIPv6)
892
+ {
893
+ addr.saIn.sin_family = AF_INET;
894
+ addr.saIn.sin_port = htons(port);
895
+ addr.saIn.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
896
+ result.push_back(addr);
897
+ }
898
+ sortAddresses(result, protocol, selType, preferIPv6);
899
+ return result;
900
+ }
901
+
902
+ struct addrinfo* info = 0;
903
+ int retry = 5;
904
+
905
+ struct addrinfo hints = { 0 };
906
+ if(protocol == EnableIPv4)
907
+ {
908
+ hints.ai_family = PF_INET;
909
+ }
910
+ else if(protocol == EnableIPv6)
911
+ {
912
+ hints.ai_family = PF_INET6;
913
+ }
914
+ else
915
+ {
916
+ hints.ai_family = PF_UNSPEC;
917
+ }
918
+
919
+ if(!blocking)
920
+ {
921
+ hints.ai_flags = AI_NUMERICHOST;
922
+ }
923
+
924
+ int rs = 0;
925
+ do
926
+ {
927
+ rs = getaddrinfo(host.c_str(), 0, &hints, &info);
928
+ }
929
+ while(info == 0 && rs == EAI_AGAIN && --retry >= 0);
930
+
931
+ // In theory, getaddrinfo should only return EAI_NONAME if
932
+ // AI_NUMERICHOST is specified and the host name is not a IP
933
+ // address. However on some platforms (e.g. OS X 10.4.x)
934
+ // EAI_NODATA is also returned so we also check for it.
935
+ # ifdef EAI_NODATA
936
+ if(!blocking && (rs == EAI_NONAME || rs == EAI_NODATA))
937
+ # else
938
+ if(!blocking && rs == EAI_NONAME)
939
+ # endif
940
+ {
941
+ return result; // Empty result indicates that a blocking lookup is necessary.
942
+ }
943
+ else if(rs != 0)
944
+ {
945
+ DNSException ex(__FILE__, __LINE__);
946
+ ex.error = rs;
947
+ ex.host = host;
948
+ throw ex;
949
+ }
950
+
951
+ for(struct addrinfo* p = info; p != NULL; p = p->ai_next)
952
+ {
953
+ memcpy(&addr.saStorage, p->ai_addr, p->ai_addrlen);
954
+ if(p->ai_family == PF_INET)
955
+ {
956
+ addr.saIn.sin_port = htons(port);
957
+ }
958
+ else if(p->ai_family == PF_INET6)
959
+ {
960
+ addr.saIn6.sin6_port = htons(port);
961
+ }
962
+
963
+ bool found = false;
964
+ for(unsigned int i = 0; i < result.size(); ++i)
965
+ {
966
+ if(compareAddress(result[i], addr) == 0)
967
+ {
968
+ found = true;
969
+ break;
970
+ }
971
+ }
972
+ if(!found)
973
+ {
974
+ result.push_back(addr);
975
+ }
976
+ }
977
+
978
+ freeaddrinfo(info);
979
+
980
+ if(result.empty())
981
+ {
982
+ DNSException ex(__FILE__, __LINE__);
983
+ ex.host = host;
984
+ throw ex;
985
+ }
986
+ sortAddresses(result, protocol, selType, preferIPv6);
987
+ return result;
988
+ }
989
+ #endif
990
+
991
+ #ifdef ICE_OS_WINRT
992
+ ProtocolSupport
993
+ IceInternal::getProtocolSupport(const Address&)
994
+ {
995
+ // For WinRT, there's no distinction between IPv4 and IPv6 adresses.
996
+ return EnableBoth;
997
+ }
998
+ #else
999
+ ProtocolSupport
1000
+ IceInternal::getProtocolSupport(const Address& addr)
1001
+ {
1002
+ return addr.saStorage.ss_family == AF_INET ? EnableIPv4 : EnableIPv6;
1003
+ }
1004
+ #endif
1005
+
1006
+ Address
1007
+ IceInternal::getAddressForServer(const string& host, int port, ProtocolSupport protocol, bool preferIPv6)
1008
+ {
1009
+ //
1010
+ // We don't use getaddrinfo when host is empty as it's not portable (some old Linux
1011
+ // versions don't support it).
1012
+ //
1013
+ if(host.empty())
1014
+ {
1015
+ Address addr;
1016
+ #ifdef ICE_OS_WINRT
1017
+ ostringstream os;
1018
+ os << port;
1019
+ //
1020
+ // Don't need to use any string converter here as the port number use just
1021
+ // ASCII characters.
1022
+ //
1023
+ addr.port = ref new String(IceUtil::stringToWstring(os.str()).c_str());
1024
+ addr.host = nullptr; // Equivalent of inaddr_any, see doBind implementation.
1025
+ #else
1026
+ memset(&addr.saStorage, 0, sizeof(sockaddr_storage));
1027
+ if(protocol != EnableIPv4)
1028
+ {
1029
+ addr.saIn6.sin6_family = AF_INET6;
1030
+ addr.saIn6.sin6_port = htons(port);
1031
+ addr.saIn6.sin6_addr = in6addr_any;
1032
+ }
1033
+ else
1034
+ {
1035
+ addr.saIn.sin_family = AF_INET;
1036
+ addr.saIn.sin_port = htons(port);
1037
+ addr.saIn.sin_addr.s_addr = htonl(INADDR_ANY);
1038
+ }
1039
+ #endif
1040
+ return addr;
1041
+ }
1042
+ return getAddresses(host, port, protocol, Ice::Ordered, preferIPv6, true)[0];
1043
+ }
1044
+
1045
+ int
1046
+ IceInternal::compareAddress(const Address& addr1, const Address& addr2)
1047
+ {
1048
+ #ifdef ICE_OS_WINRT
1049
+ int o = String::CompareOrdinal(addr1.port, addr2.port);
1050
+ if(o != 0)
1051
+ {
1052
+ return o;
1053
+ }
1054
+ if(addr1.host == addr2.host)
1055
+ {
1056
+ return 0;
1057
+ }
1058
+ if(addr1.host == nullptr)
1059
+ {
1060
+ return -1;
1061
+ }
1062
+ if(addr2.host == nullptr)
1063
+ {
1064
+ return 1;
1065
+ }
1066
+ return String::CompareOrdinal(addr1.host->RawName, addr2.host->RawName);
1067
+ #else
1068
+ if(addr1.saStorage.ss_family < addr2.saStorage.ss_family)
1069
+ {
1070
+ return -1;
1071
+ }
1072
+ else if(addr2.saStorage.ss_family < addr1.saStorage.ss_family)
1073
+ {
1074
+ return 1;
1075
+ }
1076
+
1077
+ if(addr1.saStorage.ss_family == AF_INET)
1078
+ {
1079
+ if(addr1.saIn.sin_port < addr2.saIn.sin_port)
1080
+ {
1081
+ return -1;
1082
+ }
1083
+ else if(addr2.saIn.sin_port < addr1.saIn.sin_port)
1084
+ {
1085
+ return 1;
1086
+ }
1087
+
1088
+ if(addr1.saIn.sin_addr.s_addr < addr2.saIn.sin_addr.s_addr)
1089
+ {
1090
+ return -1;
1091
+ }
1092
+ else if(addr2.saIn.sin_addr.s_addr < addr1.saIn.sin_addr.s_addr)
1093
+ {
1094
+ return 1;
1095
+ }
1096
+ }
1097
+ else
1098
+ {
1099
+ if(addr1.saIn6.sin6_port < addr2.saIn6.sin6_port)
1100
+ {
1101
+ return -1;
1102
+ }
1103
+ else if(addr2.saIn6.sin6_port < addr1.saIn6.sin6_port)
1104
+ {
1105
+ return 1;
1106
+ }
1107
+
1108
+ int res = memcmp(&addr1.saIn6.sin6_addr, &addr2.saIn6.sin6_addr, sizeof(in6_addr));
1109
+ if(res < 0)
1110
+ {
1111
+ return -1;
1112
+ }
1113
+ else if(res > 0)
1114
+ {
1115
+ return 1;
1116
+ }
1117
+ }
1118
+
1119
+ return 0;
1120
+ #endif
1121
+ }
1122
+
1123
+ #ifdef ICE_OS_WINRT
1124
+ bool
1125
+ IceInternal::isIPv6Supported()
1126
+ {
1127
+ return true;
1128
+ }
1129
+ #else
1130
+ bool
1131
+ IceInternal::isIPv6Supported()
1132
+ {
1133
+ SOCKET fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
1134
+ if(fd == INVALID_SOCKET)
1135
+ {
1136
+ return false;
1137
+ }
1138
+ else
1139
+ {
1140
+ closeSocketNoThrow(fd);
1141
+ return true;
1142
+ }
1143
+ }
1144
+ #endif
1145
+
1146
+ #ifdef ICE_OS_WINRT
1147
+ SOCKET
1148
+ IceInternal::createSocket(bool udp, const Address&)
1149
+ {
1150
+ return createSocketImpl(udp, 0);
1151
+ }
1152
+ #else
1153
+ SOCKET
1154
+ IceInternal::createSocket(bool udp, const Address& addr)
1155
+ {
1156
+ return createSocketImpl(udp, addr.saStorage.ss_family);
1157
+ }
1158
+ #endif
1159
+
1160
+ #ifndef ICE_OS_WINRT
1161
+ SOCKET
1162
+ IceInternal::createServerSocket(bool udp, const Address& addr, ProtocolSupport protocol)
1163
+ {
1164
+ SOCKET fd = createSocket(udp, addr);
1165
+ if(addr.saStorage.ss_family == AF_INET6 && protocol != EnableIPv4)
1166
+ {
1167
+ int flag = protocol == EnableIPv6 ? 1 : 0;
1168
+ if(setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
1169
+ {
1170
+ #ifdef _WIN32
1171
+ if(getSocketErrno() == WSAENOPROTOOPT)
1172
+ {
1173
+ return fd; // Windows XP doesn't support IPV6_V6ONLY
1174
+ }
1175
+ #endif
1176
+ closeSocketNoThrow(fd);
1177
+ SocketException ex(__FILE__, __LINE__);
1178
+ ex.error = getSocketErrno();
1179
+ throw ex;
1180
+ }
1181
+ }
1182
+ return fd;
1183
+ }
1184
+ #else
1185
+ SOCKET
1186
+ IceInternal::createServerSocket(bool udp, const Address& addr, ProtocolSupport)
1187
+ {
1188
+ return createSocket(udp, addr);
1189
+ }
1190
+ #endif
1191
+
1192
+ void
1193
+ IceInternal::closeSocketNoThrow(SOCKET fd)
1194
+ {
1195
+ #if defined(ICE_OS_WINRT)
1196
+ //
1197
+ // NOTE: StreamSocket::Close or DatagramSocket::Close aren't
1198
+ // exposed in C++, you have to delete the socket to close
1199
+ // it. According some Microsoft samples, this is safe even if
1200
+ // there are still references to the object...
1201
+ //
1202
+ //fd->Close();
1203
+ delete fd;
1204
+ #elif defined(_WIN32)
1205
+ int error = WSAGetLastError();
1206
+ closesocket(fd);
1207
+ WSASetLastError(error);
1208
+ #else
1209
+ int error = errno;
1210
+ close(fd);
1211
+ errno = error;
1212
+ #endif
1213
+ }
1214
+
1215
+ void
1216
+ IceInternal::closeSocket(SOCKET fd)
1217
+ {
1218
+ #if defined(ICE_OS_WINRT)
1219
+ //
1220
+ // NOTE: StreamSocket::Close or DatagramSocket::Close aren't
1221
+ // exposed in C++, you have to delete the socket to close
1222
+ // it. According some Microsoft samples, this is safe even if
1223
+ // there are still references to the object...
1224
+ //
1225
+ //fd->Close();
1226
+ delete fd;
1227
+ #elif defined(_WIN32)
1228
+ int error = WSAGetLastError();
1229
+ if(closesocket(fd) == SOCKET_ERROR)
1230
+ {
1231
+ SocketException ex(__FILE__, __LINE__);
1232
+ ex.error = getSocketErrno();
1233
+ throw ex;
1234
+ }
1235
+ WSASetLastError(error);
1236
+ #else
1237
+ int error = errno;
1238
+ if(close(fd) == SOCKET_ERROR)
1239
+ {
1240
+ SocketException ex(__FILE__, __LINE__);
1241
+ ex.error = getSocketErrno();
1242
+ throw ex;
1243
+ }
1244
+ errno = error;
1245
+ #endif
1246
+ }
1247
+
1248
+ string
1249
+ IceInternal::addrToString(const Address& addr)
1250
+ {
1251
+ ostringstream s;
1252
+ s << inetAddrToString(addr) << ':' << getPort(addr);
1253
+ return s.str();
1254
+ }
1255
+
1256
+ void
1257
+ IceInternal::fdToLocalAddress(SOCKET fd, Address& addr)
1258
+ {
1259
+ #ifndef ICE_OS_WINRT
1260
+ socklen_t len = static_cast<socklen_t>(sizeof(sockaddr_storage));
1261
+ if(getsockname(fd, &addr.sa, &len) == SOCKET_ERROR)
1262
+ {
1263
+ closeSocketNoThrow(fd);
1264
+ SocketException ex(__FILE__, __LINE__);
1265
+ ex.error = getSocketErrno();
1266
+ throw ex;
1267
+ }
1268
+ #else
1269
+ StreamSocket^ stream = dynamic_cast<StreamSocket^>(fd);
1270
+ if(stream)
1271
+ {
1272
+ addr.host = stream->Information->LocalAddress;
1273
+ addr.port = stream->Information->LocalPort;
1274
+ }
1275
+ DatagramSocket^ datagram = dynamic_cast<DatagramSocket^>(fd);
1276
+ if(datagram)
1277
+ {
1278
+ addr.host = datagram->Information->LocalAddress;
1279
+ addr.port = datagram->Information->LocalPort;
1280
+ }
1281
+ #endif
1282
+ }
1283
+
1284
+ bool
1285
+ IceInternal::fdToRemoteAddress(SOCKET fd, Address& addr)
1286
+ {
1287
+ #ifndef ICE_OS_WINRT
1288
+ socklen_t len = static_cast<socklen_t>(sizeof(sockaddr_storage));
1289
+ if(getpeername(fd, &addr.sa, &len) == SOCKET_ERROR)
1290
+ {
1291
+ if(notConnected())
1292
+ {
1293
+ return false;
1294
+ }
1295
+ else
1296
+ {
1297
+ closeSocketNoThrow(fd);
1298
+ SocketException ex(__FILE__, __LINE__);
1299
+ ex.error = getSocketErrno();
1300
+ throw ex;
1301
+ }
1302
+ }
1303
+
1304
+ return true;
1305
+ #else
1306
+ StreamSocket^ stream = dynamic_cast<StreamSocket^>(fd);
1307
+ if(stream != nullptr)
1308
+ {
1309
+ addr.host = stream->Information->RemoteAddress;
1310
+ addr.port = stream->Information->RemotePort;
1311
+ }
1312
+ DatagramSocket^ datagram = dynamic_cast<DatagramSocket^>(fd);
1313
+ if(datagram != nullptr)
1314
+ {
1315
+ addr.host = datagram->Information->RemoteAddress;
1316
+ addr.port = datagram->Information->RemotePort;
1317
+ }
1318
+ return addr.host != nullptr;
1319
+ #endif
1320
+ }
1321
+
1322
+ std::string
1323
+ IceInternal::fdToString(SOCKET fd, const NetworkProxyPtr& proxy, const Address& target)
1324
+ {
1325
+ if(fd == INVALID_SOCKET)
1326
+ {
1327
+ return "<closed>";
1328
+ }
1329
+
1330
+ ostringstream s;
1331
+
1332
+ Address remoteAddr;
1333
+ bool peerConnected = fdToRemoteAddress(fd, remoteAddr);
1334
+
1335
+ #ifdef _WIN32
1336
+ if(!peerConnected)
1337
+ {
1338
+ //
1339
+ // The local address is only accessible with connected sockets on Windows.
1340
+ //
1341
+ s << "local address = <not available>";
1342
+ }
1343
+ else
1344
+ #endif
1345
+ {
1346
+ Address localAddr;
1347
+ fdToLocalAddress(fd, localAddr);
1348
+ s << "local address = " << addrToString(localAddr);
1349
+ }
1350
+
1351
+ if(proxy)
1352
+ {
1353
+ if(!peerConnected)
1354
+ {
1355
+ remoteAddr = proxy->getAddress();
1356
+ }
1357
+ s << "\n" + proxy->getName() + " proxy address = " << addrToString(remoteAddr);
1358
+ s << "\nremote address = " << addrToString(target);
1359
+ }
1360
+ else
1361
+ {
1362
+ if(!peerConnected)
1363
+ {
1364
+ remoteAddr = target;
1365
+ }
1366
+ s << "\nremote address = " << addrToString(remoteAddr);
1367
+ }
1368
+
1369
+ return s.str();
1370
+ }
1371
+
1372
+ std::string
1373
+ IceInternal::fdToString(SOCKET fd)
1374
+ {
1375
+ if(fd == INVALID_SOCKET)
1376
+ {
1377
+ return "<closed>";
1378
+ }
1379
+
1380
+ Address localAddr;
1381
+ fdToLocalAddress(fd, localAddr);
1382
+
1383
+ Address remoteAddr;
1384
+ bool peerConnected = fdToRemoteAddress(fd, remoteAddr);
1385
+
1386
+ return addressesToString(localAddr, remoteAddr, peerConnected);
1387
+ }
1388
+
1389
+ void
1390
+ IceInternal::fdToAddressAndPort(SOCKET fd, string& localAddress, int& localPort, string& remoteAddress, int& remotePort)
1391
+ {
1392
+ if(fd == INVALID_SOCKET)
1393
+ {
1394
+ localAddress.clear();
1395
+ remoteAddress.clear();
1396
+ localPort = -1;
1397
+ remotePort = -1;
1398
+ return;
1399
+ }
1400
+
1401
+ Address localAddr;
1402
+ fdToLocalAddress(fd, localAddr);
1403
+ addrToAddressAndPort(localAddr, localAddress, localPort);
1404
+
1405
+ Address remoteAddr;
1406
+ if(fdToRemoteAddress(fd, remoteAddr))
1407
+ {
1408
+ addrToAddressAndPort(remoteAddr, remoteAddress, remotePort);
1409
+ }
1410
+ else
1411
+ {
1412
+ remoteAddress.clear();
1413
+ remotePort = -1;
1414
+ }
1415
+ }
1416
+
1417
+ void
1418
+ IceInternal::addrToAddressAndPort(const Address& addr, string& address, int& port)
1419
+ {
1420
+ address = inetAddrToString(addr);
1421
+ port = getPort(addr);
1422
+ }
1423
+
1424
+ std::string
1425
+ IceInternal::addressesToString(const Address& localAddr, const Address& remoteAddr, bool peerConnected)
1426
+ {
1427
+ ostringstream s;
1428
+ s << "local address = " << addrToString(localAddr);
1429
+ if(peerConnected)
1430
+ {
1431
+ s << "\nremote address = " << addrToString(remoteAddr);
1432
+ }
1433
+ else
1434
+ {
1435
+ s << "\nremote address = <not connected>";
1436
+ }
1437
+ return s.str();
1438
+ }
1439
+
1440
+ bool
1441
+ IceInternal::isAddressValid(const Address& addr)
1442
+ {
1443
+ #ifndef ICE_OS_WINRT
1444
+ return addr.saStorage.ss_family != AF_UNSPEC;
1445
+ #else
1446
+ return addr.host != nullptr || addr.port != nullptr;
1447
+ #endif
1448
+ }
1449
+
1450
+ #ifdef ICE_OS_WINRT
1451
+ vector<string>
1452
+ IceInternal::getHostsForEndpointExpand(const string&, ProtocolSupport, bool)
1453
+ {
1454
+ //
1455
+ // No support for expanding wildcard addresses on WinRT
1456
+ //
1457
+ vector<string> hosts;
1458
+ return hosts;
1459
+ }
1460
+ #else
1461
+ vector<string>
1462
+ IceInternal::getHostsForEndpointExpand(const string& host, ProtocolSupport protocolSupport, bool includeLoopback)
1463
+ {
1464
+ vector<string> hosts;
1465
+ bool ipv4Wildcard = false;
1466
+ if(isWildcard(host, protocolSupport, ipv4Wildcard))
1467
+ {
1468
+ vector<Address> addrs = getLocalAddresses(ipv4Wildcard ? EnableIPv4 : protocolSupport, includeLoopback);
1469
+ for(vector<Address>::const_iterator p = addrs.begin(); p != addrs.end(); ++p)
1470
+ {
1471
+ //
1472
+ // NOTE: We don't publish link-local addresses as in most cases
1473
+ // these are not desired to be published and in some cases
1474
+ // will not work without extra configuration.
1475
+ //
1476
+ if(!isLinklocal(*p))
1477
+ {
1478
+ hosts.push_back(inetAddrToString(*p));
1479
+ }
1480
+ }
1481
+ }
1482
+ return hosts; // An empty host list indicates to just use the given host.
1483
+ }
1484
+ #endif
1485
+
1486
+ string
1487
+ IceInternal::inetAddrToString(const Address& ss)
1488
+ {
1489
+ #ifndef ICE_OS_WINRT
1490
+ int size = getAddressStorageSize(ss);
1491
+ if(size == 0)
1492
+ {
1493
+ return "";
1494
+ }
1495
+
1496
+ char namebuf[1024];
1497
+ namebuf[0] = '\0';
1498
+ getnameinfo(&ss.sa, size, namebuf, static_cast<socklen_t>(sizeof(namebuf)), 0, 0, NI_NUMERICHOST);
1499
+ return string(namebuf);
1500
+ #else
1501
+ if(ss.host == nullptr)
1502
+ {
1503
+ return "";
1504
+ }
1505
+ else
1506
+ {
1507
+ //
1508
+ // Don't need to pass a wide string converter as the wide string come
1509
+ // from Windows API.
1510
+ //
1511
+ return IceUtil::wstringToString(ss.host->RawName->Data(), IceUtil::getProcessStringConverter());
1512
+ }
1513
+ #endif
1514
+ }
1515
+
1516
+ int
1517
+ IceInternal::getPort(const Address& addr)
1518
+ {
1519
+ #ifndef ICE_OS_WINRT
1520
+ if(addr.saStorage.ss_family == AF_INET)
1521
+ {
1522
+ return ntohs(addr.saIn.sin_port);
1523
+ }
1524
+ else if(addr.saStorage.ss_family == AF_INET6)
1525
+ {
1526
+ return ntohs(addr.saIn6.sin6_port);
1527
+ }
1528
+ else
1529
+ {
1530
+ return -1;
1531
+ }
1532
+ #else
1533
+ IceUtil::Int64 port;
1534
+ //
1535
+ // Don't need to use any string converter here as the port number use just ASCII characters.
1536
+ //
1537
+ if(addr.port == nullptr || !IceUtilInternal::stringToInt64(IceUtil::wstringToString(addr.port->Data()), port))
1538
+ {
1539
+ return -1;
1540
+ }
1541
+ return static_cast<int>(port);
1542
+ #endif
1543
+ }
1544
+
1545
+ void
1546
+ IceInternal::setPort(Address& addr, int port)
1547
+ {
1548
+ #ifndef ICE_OS_WINRT
1549
+ if(addr.saStorage.ss_family == AF_INET)
1550
+ {
1551
+ addr.saIn.sin_port = htons(port);
1552
+ }
1553
+ else
1554
+ {
1555
+ assert(addr.saStorage.ss_family == AF_INET6);
1556
+ addr.saIn6.sin6_port = htons(port);
1557
+ }
1558
+ #else
1559
+ ostringstream os;
1560
+ os << port;
1561
+ //
1562
+ // Don't need to use any string converter here as the port number use just
1563
+ // ACII characters.
1564
+ //
1565
+ addr.port = ref new String(IceUtil::stringToWstring(os.str()).c_str());
1566
+ #endif
1567
+ }
1568
+
1569
+ bool
1570
+ IceInternal::isMulticast(const Address& addr)
1571
+ {
1572
+ #ifndef ICE_OS_WINRT
1573
+ if(addr.saStorage.ss_family == AF_INET)
1574
+ {
1575
+ return IN_MULTICAST(ntohl(addr.saIn.sin_addr.s_addr));
1576
+ }
1577
+ else if(addr.saStorage.ss_family == AF_INET6)
1578
+ {
1579
+ return IN6_IS_ADDR_MULTICAST(&addr.saIn6.sin6_addr);
1580
+ }
1581
+ #else
1582
+ if(addr.host == nullptr)
1583
+ {
1584
+ return false;
1585
+ }
1586
+ //
1587
+ // Don't need to use string converters here, this is just to do a local
1588
+ // comparison to find if the address is multicast.
1589
+ //
1590
+ string host = IceUtil::wstringToString(addr.host->RawName->Data());
1591
+ string ip = IceUtilInternal::toUpper(host);
1592
+ vector<string> tokens;
1593
+ IceUtilInternal::splitString(ip, ".", tokens);
1594
+ if(tokens.size() == 4)
1595
+ {
1596
+ IceUtil::Int64 j;
1597
+ if(IceUtilInternal::stringToInt64(tokens[0], j))
1598
+ {
1599
+ if(j >= 233 && j <= 239)
1600
+ {
1601
+ return true;
1602
+ }
1603
+ }
1604
+ }
1605
+ if(ip.find("::") != string::npos)
1606
+ {
1607
+ return ip.compare(0, 2, "FF") == 0;
1608
+ }
1609
+ #endif
1610
+ return false;
1611
+ }
1612
+
1613
+ void
1614
+ IceInternal::setTcpBufSize(SOCKET fd, const Ice::PropertiesPtr& properties, const Ice::LoggerPtr& logger)
1615
+ {
1616
+ assert(fd != INVALID_SOCKET);
1617
+
1618
+ //
1619
+ // By default, on Windows we use a 128KB buffer size. On Unix
1620
+ // platforms, we use the system defaults.
1621
+ //
1622
+ #ifdef _WIN32
1623
+ const int dfltBufSize = 128 * 1024;
1624
+ #else
1625
+ const int dfltBufSize = 0;
1626
+ #endif
1627
+ Int sizeRequested;
1628
+
1629
+ sizeRequested = properties->getPropertyAsIntWithDefault("Ice.TCP.RcvSize", dfltBufSize);
1630
+ if(sizeRequested > 0)
1631
+ {
1632
+ //
1633
+ // Try to set the buffer size. The kernel will silently adjust
1634
+ // the size to an acceptable value. Then read the size back to
1635
+ // get the size that was actually set.
1636
+ //
1637
+ setRecvBufferSize(fd, sizeRequested);
1638
+ int size = getRecvBufferSize(fd);
1639
+ if(size > 0 && size < sizeRequested) // Warn if the size that was set is less than the requested size.
1640
+ {
1641
+ Ice::Warning out(logger);
1642
+ out << "TCP receive buffer size: requested size of " << sizeRequested << " adjusted to " << size;
1643
+ }
1644
+ }
1645
+
1646
+ sizeRequested = properties->getPropertyAsIntWithDefault("Ice.TCP.SndSize", dfltBufSize);
1647
+ if(sizeRequested > 0)
1648
+ {
1649
+ //
1650
+ // Try to set the buffer size. The kernel will silently adjust
1651
+ // the size to an acceptable value. Then read the size back to
1652
+ // get the size that was actually set.
1653
+ //
1654
+ setSendBufferSize(fd, sizeRequested);
1655
+ int size = getSendBufferSize(fd);
1656
+ if(size > 0 && size < sizeRequested) // Warn if the size that was set is less than the requested size.
1657
+ {
1658
+ Ice::Warning out(logger);
1659
+ out << "TCP send buffer size: requested size of " << sizeRequested << " adjusted to " << size;
1660
+ }
1661
+ }
1662
+ }
1663
+
1664
+ #ifdef ICE_OS_WINRT
1665
+ void
1666
+ IceInternal::setBlock(SOCKET fd, bool)
1667
+ {
1668
+ }
1669
+ #else
1670
+ void
1671
+ IceInternal::setBlock(SOCKET fd, bool block)
1672
+ {
1673
+ #ifdef _WIN32
1674
+ if(block)
1675
+ {
1676
+ unsigned long arg = 0;
1677
+ if(ioctlsocket(fd, FIONBIO, &arg) == SOCKET_ERROR)
1678
+ {
1679
+ closeSocketNoThrow(fd);
1680
+ SocketException ex(__FILE__, __LINE__);
1681
+ ex.error = WSAGetLastError();
1682
+ throw ex;
1683
+ }
1684
+ }
1685
+ else
1686
+ {
1687
+ unsigned long arg = 1;
1688
+ if(ioctlsocket(fd, FIONBIO, &arg) == SOCKET_ERROR)
1689
+ {
1690
+ closeSocketNoThrow(fd);
1691
+ SocketException ex(__FILE__, __LINE__);
1692
+ ex.error = WSAGetLastError();
1693
+ throw ex;
1694
+ }
1695
+ }
1696
+ #else
1697
+ if(block)
1698
+ {
1699
+ int flags = fcntl(fd, F_GETFL);
1700
+ flags &= ~O_NONBLOCK;
1701
+ if(fcntl(fd, F_SETFL, flags) == SOCKET_ERROR)
1702
+ {
1703
+ closeSocketNoThrow(fd);
1704
+ SocketException ex(__FILE__, __LINE__);
1705
+ ex.error = errno;
1706
+ throw ex;
1707
+ }
1708
+ }
1709
+ else
1710
+ {
1711
+ int flags = fcntl(fd, F_GETFL);
1712
+ flags |= O_NONBLOCK;
1713
+ if(fcntl(fd, F_SETFL, flags) == SOCKET_ERROR)
1714
+ {
1715
+ closeSocketNoThrow(fd);
1716
+ SocketException ex(__FILE__, __LINE__);
1717
+ ex.error = errno;
1718
+ throw ex;
1719
+ }
1720
+ }
1721
+ #endif
1722
+ }
1723
+ #endif
1724
+
1725
+ void
1726
+ IceInternal::setSendBufferSize(SOCKET fd, int sz)
1727
+ {
1728
+ #ifndef ICE_OS_WINRT
1729
+ if(setsockopt(fd, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&sz), int(sizeof(int))) == SOCKET_ERROR)
1730
+ {
1731
+ closeSocketNoThrow(fd);
1732
+ SocketException ex(__FILE__, __LINE__);
1733
+ ex.error = getSocketErrno();
1734
+ throw ex;
1735
+ }
1736
+ #else
1737
+ StreamSocket^ stream = dynamic_cast<StreamSocket^>(fd);
1738
+ if(stream != nullptr)
1739
+ {
1740
+ stream->Control->OutboundBufferSizeInBytes = sz;
1741
+ }
1742
+ #endif
1743
+ }
1744
+
1745
+ int
1746
+ IceInternal::getSendBufferSize(SOCKET fd)
1747
+ {
1748
+ #ifndef ICE_OS_WINRT
1749
+ int sz;
1750
+ socklen_t len = sizeof(sz);
1751
+ if(getsockopt(fd, SOL_SOCKET, SO_SNDBUF, reinterpret_cast<char*>(&sz), &len) == SOCKET_ERROR ||
1752
+ static_cast<unsigned int>(len) != sizeof(sz))
1753
+ {
1754
+ closeSocketNoThrow(fd);
1755
+ SocketException ex(__FILE__, __LINE__);
1756
+ ex.error = getSocketErrno();
1757
+ throw ex;
1758
+ }
1759
+ return sz;
1760
+ #else
1761
+ StreamSocket^ stream = dynamic_cast<StreamSocket^>(fd);
1762
+ if(stream != nullptr)
1763
+ {
1764
+ return stream->Control->OutboundBufferSizeInBytes;
1765
+ }
1766
+ return 0; // Not supported
1767
+ #endif
1768
+ }
1769
+
1770
+ #ifdef ICE_OS_WINRT
1771
+ void
1772
+ IceInternal::setRecvBufferSize(SOCKET, int)
1773
+ {
1774
+ }
1775
+ #else
1776
+ void
1777
+ IceInternal::setRecvBufferSize(SOCKET fd, int sz)
1778
+ {
1779
+ if(setsockopt(fd, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<char*>(&sz), int(sizeof(int))) == SOCKET_ERROR)
1780
+ {
1781
+ closeSocketNoThrow(fd);
1782
+ SocketException ex(__FILE__, __LINE__);
1783
+ ex.error = getSocketErrno();
1784
+ throw ex;
1785
+ }
1786
+ }
1787
+ #endif
1788
+
1789
+ int
1790
+ IceInternal::getRecvBufferSize(SOCKET fd)
1791
+ {
1792
+ #ifndef ICE_OS_WINRT
1793
+ int sz;
1794
+ socklen_t len = sizeof(sz);
1795
+ if(getsockopt(fd, SOL_SOCKET, SO_RCVBUF, reinterpret_cast<char*>(&sz), &len) == SOCKET_ERROR ||
1796
+ static_cast<unsigned int>(len) != sizeof(sz))
1797
+ {
1798
+ closeSocketNoThrow(fd);
1799
+ SocketException ex(__FILE__, __LINE__);
1800
+ ex.error = getSocketErrno();
1801
+ throw ex;
1802
+ }
1803
+ return sz;
1804
+ #else
1805
+ return 0; // Not supported
1806
+ #endif
1807
+ }
1808
+
1809
+ #ifndef ICE_OS_WINRT
1810
+ void
1811
+ IceInternal::setMcastGroup(SOCKET fd, const Address& group, const string& intf)
1812
+ {
1813
+ int rc;
1814
+ if(group.saStorage.ss_family == AF_INET)
1815
+ {
1816
+ struct ip_mreq mreq;
1817
+ mreq.imr_multiaddr = group.saIn.sin_addr;
1818
+ mreq.imr_interface = getInterfaceAddress(intf);
1819
+ rc = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, reinterpret_cast<char*>(&mreq), int(sizeof(mreq)));
1820
+ }
1821
+ else
1822
+ {
1823
+ struct ipv6_mreq mreq;
1824
+ mreq.ipv6mr_multiaddr = group.saIn6.sin6_addr;
1825
+ mreq.ipv6mr_interface = getInterfaceIndex(intf);
1826
+ rc = setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, reinterpret_cast<char*>(&mreq), int(sizeof(mreq)));
1827
+ }
1828
+ if(rc == SOCKET_ERROR)
1829
+ {
1830
+ closeSocketNoThrow(fd);
1831
+ SocketException ex(__FILE__, __LINE__);
1832
+ ex.error = getSocketErrno();
1833
+ throw ex;
1834
+ }
1835
+ }
1836
+ #else
1837
+ void
1838
+ IceInternal::setMcastGroup(SOCKET fd, const Address& group, const string&)
1839
+ {
1840
+ try
1841
+ {
1842
+ //
1843
+ // NOTE: WinRT doesn't allow specyfing the interface.
1844
+ //
1845
+ safe_cast<DatagramSocket^>(fd)->JoinMulticastGroup(group.host);
1846
+ }
1847
+ catch(Platform::Exception^ pex)
1848
+ {
1849
+ throw SocketException(__FILE__, __LINE__, (int)SocketError::GetStatus(pex->HResult));
1850
+ }
1851
+ }
1852
+ #endif
1853
+
1854
+ #ifdef ICE_OS_WINRT
1855
+ void
1856
+ IceInternal::setMcastInterface(SOCKET, const string&, const Address&)
1857
+ {
1858
+ }
1859
+ #else
1860
+ void
1861
+ IceInternal::setMcastInterface(SOCKET fd, const string& intf, const Address& addr)
1862
+ {
1863
+ int rc;
1864
+ if(addr.saStorage.ss_family == AF_INET)
1865
+ {
1866
+ struct in_addr iface = getInterfaceAddress(intf);
1867
+ rc = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, reinterpret_cast<char*>(&iface), int(sizeof(iface)));
1868
+ }
1869
+ else
1870
+ {
1871
+ int interfaceNum = getInterfaceIndex(intf);
1872
+ rc = setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, reinterpret_cast<char*>(&interfaceNum), int(sizeof(int)));
1873
+ }
1874
+ if(rc == SOCKET_ERROR)
1875
+ {
1876
+ closeSocketNoThrow(fd);
1877
+ SocketException ex(__FILE__, __LINE__);
1878
+ ex.error = getSocketErrno();
1879
+ throw ex;
1880
+ }
1881
+ }
1882
+ #endif
1883
+
1884
+ #ifdef ICE_OS_WINRT
1885
+ void
1886
+ IceInternal::setMcastTtl(SOCKET, int, const Address&)
1887
+ {
1888
+ }
1889
+ #else
1890
+ void
1891
+ IceInternal::setMcastTtl(SOCKET fd, int ttl, const Address& addr)
1892
+ {
1893
+ int rc;
1894
+ if(addr.saStorage.ss_family == AF_INET)
1895
+ {
1896
+ rc = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, reinterpret_cast<char*>(&ttl), int(sizeof(int)));
1897
+ }
1898
+ else
1899
+ {
1900
+ rc = setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, reinterpret_cast<char*>(&ttl), int(sizeof(int)));
1901
+ }
1902
+ if(rc == SOCKET_ERROR)
1903
+ {
1904
+ closeSocketNoThrow(fd);
1905
+ SocketException ex(__FILE__, __LINE__);
1906
+ ex.error = getSocketErrno();
1907
+ throw ex;
1908
+ }
1909
+ }
1910
+ #endif
1911
+
1912
+ #ifdef ICE_OS_WINRT
1913
+ void
1914
+ IceInternal::setReuseAddress(SOCKET, bool)
1915
+ {
1916
+ }
1917
+ #else
1918
+ void
1919
+ IceInternal::setReuseAddress(SOCKET fd, bool reuse)
1920
+ {
1921
+ int flag = reuse ? 1 : 0;
1922
+ if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<char*>(&flag), int(sizeof(int))) == SOCKET_ERROR)
1923
+ {
1924
+ closeSocketNoThrow(fd);
1925
+ SocketException ex(__FILE__, __LINE__);
1926
+ ex.error = getSocketErrno();
1927
+ throw ex;
1928
+ }
1929
+ }
1930
+ #endif
1931
+
1932
+
1933
+ #ifdef ICE_OS_WINRT
1934
+ void
1935
+ checkResultAndWait(IAsyncAction^ action)
1936
+ {
1937
+ if(action->Status == Windows::Foundation::AsyncStatus::Started)
1938
+ {
1939
+ IceUtilInternal::CountDownLatch count(1);
1940
+ HRESULT result = 0;
1941
+ action->Completed = ref new AsyncActionCompletedHandler(
1942
+ [&count, &result] (IAsyncAction^ action, Windows::Foundation::AsyncStatus status)
1943
+ {
1944
+ if(status != Windows::Foundation::AsyncStatus::Completed)
1945
+ {
1946
+ result = action->ErrorCode.Value;
1947
+ }
1948
+ count.countDown();
1949
+ });
1950
+ count.await();
1951
+ if(result)
1952
+ {
1953
+ checkErrorCode(__FILE__, __LINE__, result);
1954
+ }
1955
+ }
1956
+ else if(action->Status == Windows::Foundation::AsyncStatus::Error)
1957
+ {
1958
+ checkErrorCode(__FILE__, __LINE__, action->ErrorCode.Value);
1959
+ }
1960
+ }
1961
+ #endif
1962
+
1963
+ Address
1964
+ IceInternal::doBind(SOCKET fd, const Address& addr)
1965
+ {
1966
+ #ifdef ICE_OS_WINRT
1967
+ Address local;
1968
+ try
1969
+ {
1970
+ StreamSocketListener^ listener = dynamic_cast<StreamSocketListener^>(fd);
1971
+ if(listener != nullptr)
1972
+ {
1973
+ if(addr.host == nullptr) // inaddr_any
1974
+ {
1975
+ checkResultAndWait(listener->BindServiceNameAsync(addr.port));
1976
+ }
1977
+ else
1978
+ {
1979
+ checkResultAndWait(listener->BindEndpointAsync(addr.host, addr.port));
1980
+ }
1981
+ local.host = addr.host;
1982
+ local.port = listener->Information->LocalPort;
1983
+ }
1984
+
1985
+ DatagramSocket^ datagram = dynamic_cast<DatagramSocket^>(fd);
1986
+ if(datagram != nullptr)
1987
+ {
1988
+ if(addr.host == nullptr) // inaddr_any
1989
+ {
1990
+ checkResultAndWait(datagram->BindServiceNameAsync(addr.port));
1991
+ }
1992
+ else
1993
+ {
1994
+ checkResultAndWait(datagram->BindEndpointAsync(addr.host, addr.port));
1995
+ }
1996
+ local.host = datagram->Information->LocalAddress;
1997
+ local.port = datagram->Information->LocalPort;
1998
+ }
1999
+ }
2000
+ catch(const Ice::SocketException&)
2001
+ {
2002
+ closeSocketNoThrow(fd);
2003
+ throw;
2004
+ }
2005
+ return local;
2006
+ #else
2007
+ int size = getAddressStorageSize(addr);
2008
+ assert(size != 0);
2009
+
2010
+ if(::bind(fd, &addr.sa, size) == SOCKET_ERROR)
2011
+ {
2012
+ closeSocketNoThrow(fd);
2013
+ SocketException ex(__FILE__, __LINE__);
2014
+ ex.error = getSocketErrno();
2015
+ throw ex;
2016
+ }
2017
+
2018
+ Address local;
2019
+ socklen_t len = static_cast<socklen_t>(sizeof(sockaddr_storage));
2020
+ # ifdef NDEBUG
2021
+ getsockname(fd, &local.sa, &len);
2022
+ # else
2023
+ int ret = getsockname(fd, &local.sa, &len);
2024
+ assert(ret != SOCKET_ERROR);
2025
+ # endif
2026
+ return local;
2027
+ #endif
2028
+ }
2029
+
2030
+ #ifndef ICE_OS_WINRT
2031
+
2032
+ Address
2033
+ IceInternal::getNumericAddress(const std::string& address)
2034
+ {
2035
+ vector<Address> addrs = getAddresses(address, 0, EnableBoth, Ice::Ordered, false, false);
2036
+ if(addrs.empty())
2037
+ {
2038
+ return Address();
2039
+ }
2040
+ else
2041
+ {
2042
+ return addrs[0];
2043
+ }
2044
+ }
2045
+
2046
+ int
2047
+ IceInternal::getSocketErrno()
2048
+ {
2049
+ #if defined(_WIN32)
2050
+ return WSAGetLastError();
2051
+ #else
2052
+ return errno;
2053
+ #endif
2054
+ }
2055
+
2056
+ bool
2057
+ IceInternal::interrupted()
2058
+ {
2059
+ #ifdef _WIN32
2060
+ return WSAGetLastError() == WSAEINTR;
2061
+ #else
2062
+ # ifdef EPROTO
2063
+ return errno == EINTR || errno == EPROTO;
2064
+ # else
2065
+ return errno == EINTR;
2066
+ # endif
2067
+ #endif
2068
+ }
2069
+
2070
+ bool
2071
+ IceInternal::acceptInterrupted()
2072
+ {
2073
+ if(interrupted())
2074
+ {
2075
+ return true;
2076
+ }
2077
+
2078
+ #ifdef _WIN32
2079
+ int error = WSAGetLastError();
2080
+ return error == WSAECONNABORTED ||
2081
+ error == WSAECONNRESET ||
2082
+ error == WSAETIMEDOUT;
2083
+ #else
2084
+ return errno == ECONNABORTED ||
2085
+ errno == ECONNRESET ||
2086
+ errno == ETIMEDOUT;
2087
+ #endif
2088
+ }
2089
+
2090
+ bool
2091
+ IceInternal::noBuffers()
2092
+ {
2093
+ #ifdef _WIN32
2094
+ int error = WSAGetLastError();
2095
+ return error == WSAENOBUFS ||
2096
+ error == WSAEFAULT;
2097
+ #else
2098
+ return errno == ENOBUFS;
2099
+ #endif
2100
+ }
2101
+
2102
+ bool
2103
+ IceInternal::wouldBlock()
2104
+ {
2105
+ #ifdef _WIN32
2106
+ int error = WSAGetLastError();
2107
+ return error == WSAEWOULDBLOCK || error == WSA_IO_PENDING || error == ERROR_IO_PENDING;
2108
+ #else
2109
+ return errno == EAGAIN || errno == EWOULDBLOCK;
2110
+ #endif
2111
+ }
2112
+
2113
+ bool
2114
+ IceInternal::connectFailed()
2115
+ {
2116
+ #if defined(_WIN32)
2117
+ int error = WSAGetLastError();
2118
+ return error == WSAECONNREFUSED ||
2119
+ error == WSAETIMEDOUT ||
2120
+ error == WSAENETUNREACH ||
2121
+ error == WSAEHOSTUNREACH ||
2122
+ error == WSAECONNRESET ||
2123
+ error == WSAESHUTDOWN ||
2124
+ error == WSAECONNABORTED ||
2125
+ error == ERROR_SEM_TIMEOUT ||
2126
+ error == ERROR_NETNAME_DELETED;
2127
+ #else
2128
+ return errno == ECONNREFUSED ||
2129
+ errno == ETIMEDOUT ||
2130
+ errno == ENETUNREACH ||
2131
+ errno == EHOSTUNREACH ||
2132
+ errno == ECONNRESET ||
2133
+ errno == ESHUTDOWN ||
2134
+ errno == ECONNABORTED;
2135
+ #endif
2136
+ }
2137
+
2138
+ bool
2139
+ IceInternal::connectionRefused()
2140
+ {
2141
+ #if defined(_WIN32)
2142
+ int error = WSAGetLastError();
2143
+ return error == WSAECONNREFUSED || error == ERROR_CONNECTION_REFUSED;
2144
+ #else
2145
+ return errno == ECONNREFUSED;
2146
+ #endif
2147
+ }
2148
+
2149
+ bool
2150
+ IceInternal::connectionLost()
2151
+ {
2152
+ #ifdef _WIN32
2153
+ int error = WSAGetLastError();
2154
+ return error == WSAECONNRESET ||
2155
+ error == WSAESHUTDOWN ||
2156
+ error == WSAENOTCONN ||
2157
+ # ifdef ICE_USE_IOCP
2158
+ error == ERROR_NETNAME_DELETED ||
2159
+ # endif
2160
+ error == WSAECONNABORTED;
2161
+ #else
2162
+ return errno == ECONNRESET ||
2163
+ errno == ENOTCONN ||
2164
+ errno == ESHUTDOWN ||
2165
+ errno == ECONNABORTED ||
2166
+ errno == EPIPE;
2167
+ #endif
2168
+ }
2169
+
2170
+ bool
2171
+ IceInternal::connectInProgress()
2172
+ {
2173
+ #ifdef _WIN32
2174
+ int error = WSAGetLastError();
2175
+ return error == WSAEWOULDBLOCK || error == WSA_IO_PENDING || error == ERROR_IO_PENDING;
2176
+ #else
2177
+ return errno == EINPROGRESS;
2178
+ #endif
2179
+ }
2180
+
2181
+ bool
2182
+ IceInternal::notConnected()
2183
+ {
2184
+ #ifdef _WIN32
2185
+ return WSAGetLastError() == WSAENOTCONN;
2186
+ #elif defined(__APPLE__) || defined(__FreeBSD__)
2187
+ return errno == ENOTCONN || errno == EINVAL;
2188
+ #else
2189
+ return errno == ENOTCONN;
2190
+ #endif
2191
+ }
2192
+
2193
+ bool
2194
+ IceInternal::recvTruncated()
2195
+ {
2196
+ #ifdef _WIN32
2197
+ int err = WSAGetLastError();
2198
+ return err == WSAEMSGSIZE || err == ERROR_MORE_DATA;
2199
+ #else
2200
+ // We don't get an error under Linux if a datagram is truncated.
2201
+ return false;
2202
+ #endif
2203
+ }
2204
+
2205
+ void
2206
+ IceInternal::doListen(SOCKET fd, int backlog)
2207
+ {
2208
+ repeatListen:
2209
+ if(::listen(fd, backlog) == SOCKET_ERROR)
2210
+ {
2211
+ if(interrupted())
2212
+ {
2213
+ goto repeatListen;
2214
+ }
2215
+
2216
+ closeSocketNoThrow(fd);
2217
+ SocketException ex(__FILE__, __LINE__);
2218
+ ex.error = getSocketErrno();
2219
+ throw ex;
2220
+ }
2221
+ }
2222
+
2223
+ bool
2224
+ IceInternal::doConnect(SOCKET fd, const Address& addr, const Address& sourceAddr)
2225
+ {
2226
+ if(isAddressValid(sourceAddr))
2227
+ {
2228
+ doBind(fd, sourceAddr);
2229
+ }
2230
+
2231
+ repeatConnect:
2232
+ int size = getAddressStorageSize(addr);
2233
+ assert(size != 0);
2234
+
2235
+ if(::connect(fd, &addr.sa, size) == SOCKET_ERROR)
2236
+ {
2237
+ if(interrupted())
2238
+ {
2239
+ goto repeatConnect;
2240
+ }
2241
+
2242
+ if(connectInProgress())
2243
+ {
2244
+ return false;
2245
+ }
2246
+
2247
+ closeSocketNoThrow(fd);
2248
+ if(connectionRefused())
2249
+ {
2250
+ ConnectionRefusedException ex(__FILE__, __LINE__);
2251
+ ex.error = getSocketErrno();
2252
+ throw ex;
2253
+ }
2254
+ else if(connectFailed())
2255
+ {
2256
+ ConnectFailedException ex(__FILE__, __LINE__);
2257
+ ex.error = getSocketErrno();
2258
+ throw ex;
2259
+ }
2260
+ else
2261
+ {
2262
+ SocketException ex(__FILE__, __LINE__);
2263
+ ex.error = getSocketErrno();
2264
+ throw ex;
2265
+ }
2266
+ }
2267
+
2268
+ #if defined(__linux)
2269
+ //
2270
+ // Prevent self connect (self connect happens on Linux when a client tries to connect to
2271
+ // a server which was just deactivated if the client socket re-uses the same ephemeral
2272
+ // port as the server).
2273
+ //
2274
+ Address localAddr;
2275
+ fdToLocalAddress(fd, localAddr);
2276
+ if(compareAddress(addr, localAddr) == 0)
2277
+ {
2278
+ ConnectionRefusedException ex(__FILE__, __LINE__);
2279
+ ex.error = 0; // No appropriate errno
2280
+ throw ex;
2281
+ }
2282
+ #endif
2283
+ return true;
2284
+ }
2285
+
2286
+ void
2287
+ IceInternal::doFinishConnect(SOCKET fd)
2288
+ {
2289
+ //
2290
+ // Note: we don't close the socket if there's an exception. It's the responsability
2291
+ // of the caller to do so.
2292
+ //
2293
+
2294
+ //
2295
+ // Strange windows bug: The following call to Sleep() is
2296
+ // necessary, otherwise no error is reported through
2297
+ // getsockopt.
2298
+ //
2299
+ #if defined(_WIN32)
2300
+ Sleep(0);
2301
+ #endif
2302
+
2303
+ int val;
2304
+ socklen_t len = static_cast<socklen_t>(sizeof(int));
2305
+ if(getsockopt(fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&val), &len) == SOCKET_ERROR)
2306
+ {
2307
+ SocketException ex(__FILE__, __LINE__);
2308
+ ex.error = getSocketErrno();
2309
+ throw ex;
2310
+ }
2311
+
2312
+ if(val > 0)
2313
+ {
2314
+ #if defined(_WIN32)
2315
+ WSASetLastError(val);
2316
+ #else
2317
+ errno = val;
2318
+ #endif
2319
+ if(connectionRefused())
2320
+ {
2321
+ ConnectionRefusedException ex(__FILE__, __LINE__);
2322
+ ex.error = getSocketErrno();
2323
+ throw ex;
2324
+ }
2325
+ else if(connectFailed())
2326
+ {
2327
+ ConnectFailedException ex(__FILE__, __LINE__);
2328
+ ex.error = getSocketErrno();
2329
+ throw ex;
2330
+ }
2331
+ else
2332
+ {
2333
+ SocketException ex(__FILE__, __LINE__);
2334
+ ex.error = getSocketErrno();
2335
+ throw ex;
2336
+ }
2337
+ }
2338
+
2339
+ #if defined(__linux)
2340
+ //
2341
+ // Prevent self connect (self connect happens on Linux when a client tries to connect to
2342
+ // a server which was just deactivated if the client socket re-uses the same ephemeral
2343
+ // port as the server).
2344
+ //
2345
+ Address localAddr;
2346
+ fdToLocalAddress(fd, localAddr);
2347
+ Address remoteAddr;
2348
+ if(fdToRemoteAddress(fd, remoteAddr) && compareAddress(remoteAddr, localAddr) == 0)
2349
+ {
2350
+ ConnectionRefusedException ex(__FILE__, __LINE__);
2351
+ ex.error = 0; // No appropriate errno
2352
+ throw ex;
2353
+ }
2354
+ #endif
2355
+ }
2356
+
2357
+ SOCKET
2358
+ IceInternal::doAccept(SOCKET fd)
2359
+ {
2360
+ #ifdef _WIN32
2361
+ SOCKET ret;
2362
+ #else
2363
+ int ret;
2364
+ #endif
2365
+
2366
+ repeatAccept:
2367
+ if((ret = ::accept(fd, 0, 0)) == INVALID_SOCKET)
2368
+ {
2369
+ if(acceptInterrupted())
2370
+ {
2371
+ goto repeatAccept;
2372
+ }
2373
+
2374
+ SocketException ex(__FILE__, __LINE__);
2375
+ ex.error = getSocketErrno();
2376
+ throw ex;
2377
+ }
2378
+
2379
+ setTcpNoDelay(ret);
2380
+ setKeepAlive(ret);
2381
+ return ret;
2382
+ }
2383
+
2384
+
2385
+ void
2386
+ IceInternal::createPipe(SOCKET fds[2])
2387
+ {
2388
+ #ifdef _WIN32
2389
+
2390
+ SOCKET fd = createSocketImpl(false, AF_INET);
2391
+ setBlock(fd, true);
2392
+
2393
+ Address addr;
2394
+ memset(&addr.saStorage, 0, sizeof(sockaddr_storage));
2395
+
2396
+ addr.saIn.sin_family = AF_INET;
2397
+ addr.saIn.sin_port = htons(0);
2398
+ addr.saIn.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
2399
+
2400
+ addr = doBind(fd, addr);
2401
+ doListen(fd, 1);
2402
+
2403
+ try
2404
+ {
2405
+ fds[0] = createSocketImpl(false, AF_INET);
2406
+ }
2407
+ catch(...)
2408
+ {
2409
+ ::closesocket(fd);
2410
+ throw;
2411
+ }
2412
+
2413
+ try
2414
+ {
2415
+ setBlock(fds[0], true);
2416
+ # ifndef NDEBUG
2417
+ bool connected = doConnect(fds[0], addr, Address());
2418
+ assert(connected);
2419
+ # else
2420
+ doConnect(fds[0], addr, Address());
2421
+ # endif
2422
+ }
2423
+ catch(...)
2424
+ {
2425
+ // fds[0] is closed by doConnect
2426
+ ::closesocket(fd);
2427
+ throw;
2428
+ }
2429
+
2430
+ try
2431
+ {
2432
+ fds[1] = doAccept(fd);
2433
+ }
2434
+ catch(...)
2435
+ {
2436
+ ::closesocket(fds[0]);
2437
+ ::closesocket(fd);
2438
+ throw;
2439
+ }
2440
+
2441
+ ::closesocket(fd);
2442
+
2443
+ try
2444
+ {
2445
+ setBlock(fds[1], true);
2446
+ }
2447
+ catch(...)
2448
+ {
2449
+ ::closesocket(fds[0]);
2450
+ // fds[1] is closed by setBlock
2451
+ throw;
2452
+ }
2453
+
2454
+ #else
2455
+
2456
+ if(::pipe(fds) != 0)
2457
+ {
2458
+ SyscallException ex(__FILE__, __LINE__);
2459
+ ex.error = getSystemErrno();
2460
+ throw ex;
2461
+ }
2462
+
2463
+ try
2464
+ {
2465
+ setBlock(fds[0], true);
2466
+ }
2467
+ catch(...)
2468
+ {
2469
+ // fds[0] is closed by setBlock
2470
+ closeSocketNoThrow(fds[1]);
2471
+ throw;
2472
+ }
2473
+
2474
+ try
2475
+ {
2476
+ setBlock(fds[1], true);
2477
+ }
2478
+ catch(...)
2479
+ {
2480
+ closeSocketNoThrow(fds[0]);
2481
+ // fds[1] is closed by setBlock
2482
+ throw;
2483
+ }
2484
+
2485
+ #endif
2486
+ }
2487
+
2488
+ #else // ICE_OS_WINRT
2489
+
2490
+ void
2491
+ IceInternal::checkConnectErrorCode(const char* file, int line, HRESULT herr, HostName^ host)
2492
+ {
2493
+ if(herr == E_ACCESSDENIED)
2494
+ {
2495
+ SocketException ex(file, line);
2496
+ ex.error = static_cast<int>(herr);
2497
+ throw ex;
2498
+ }
2499
+ SocketErrorStatus error = SocketError::GetStatus(herr);
2500
+ if(error == SocketErrorStatus::ConnectionRefused)
2501
+ {
2502
+ ConnectionRefusedException ex(file, line);
2503
+ ex.error = static_cast<int>(error);
2504
+ throw ex;
2505
+ }
2506
+ else if(error == SocketErrorStatus::NetworkDroppedConnectionOnReset ||
2507
+ error == SocketErrorStatus::ConnectionTimedOut ||
2508
+ error == SocketErrorStatus::NetworkIsUnreachable ||
2509
+ error == SocketErrorStatus::UnreachableHost ||
2510
+ error == SocketErrorStatus::ConnectionResetByPeer ||
2511
+ error == SocketErrorStatus::SoftwareCausedConnectionAbort)
2512
+ {
2513
+ ConnectFailedException ex(file, line);
2514
+ ex.error = static_cast<int>(error);
2515
+ throw ex;
2516
+ }
2517
+ else if(error == SocketErrorStatus::HostNotFound)
2518
+ {
2519
+ DNSException ex(file, line);
2520
+ ex.error = static_cast<int>(error);
2521
+ //
2522
+ // Don't need to pass a wide string converter as the wide string come from
2523
+ // Windows API.
2524
+ //
2525
+ ex.host = IceUtil::wstringToString(host->RawName->Data(), IceUtil::getProcessStringConverter());
2526
+ throw ex;
2527
+ }
2528
+ else
2529
+ {
2530
+ SocketException ex(file, line);
2531
+ ex.error = static_cast<int>(error);
2532
+ throw ex;
2533
+ }
2534
+ }
2535
+
2536
+ void
2537
+ IceInternal::checkErrorCode(const char* file, int line, HRESULT herr)
2538
+ {
2539
+ if(herr == E_ACCESSDENIED)
2540
+ {
2541
+ SocketException ex(file, line);
2542
+ ex.error = static_cast<int>(herr);
2543
+ throw ex;
2544
+ }
2545
+ SocketErrorStatus error = SocketError::GetStatus(herr);
2546
+ if(error == SocketErrorStatus::NetworkDroppedConnectionOnReset ||
2547
+ error == SocketErrorStatus::SoftwareCausedConnectionAbort ||
2548
+ error == SocketErrorStatus::ConnectionResetByPeer)
2549
+ {
2550
+ ConnectionLostException ex(file, line);
2551
+ ex.error = static_cast<int>(error);
2552
+ throw ex;
2553
+ }
2554
+ else if(error == SocketErrorStatus::HostNotFound)
2555
+ {
2556
+ DNSException ex(file, line);
2557
+ ex.error = static_cast<int>(error);
2558
+ throw ex;
2559
+ }
2560
+ else
2561
+ {
2562
+ SocketException ex(file, line);
2563
+ ex.error = static_cast<int>(error);
2564
+ throw ex;
2565
+ }
2566
+ }
2567
+
2568
+
2569
+ #endif
2570
+
2571
+ #if defined(ICE_USE_IOCP)
2572
+ void
2573
+ IceInternal::doConnectAsync(SOCKET fd, const Address& addr, const Address& sourceAddr, AsyncInfo& info)
2574
+ {
2575
+ //
2576
+ // NOTE: It's the caller's responsability to close the socket upon
2577
+ // failure to connect. The socket isn't closed by this method.
2578
+ //
2579
+ Address bindAddr;
2580
+ if(isAddressValid(sourceAddr))
2581
+ {
2582
+ bindAddr = sourceAddr;
2583
+ }
2584
+ else
2585
+ {
2586
+ memset(&bindAddr.saStorage, 0, sizeof(sockaddr_storage));
2587
+ if(addr.saStorage.ss_family == AF_INET)
2588
+ {
2589
+ bindAddr.saIn.sin_family = AF_INET;
2590
+ bindAddr.saIn.sin_port = htons(0);
2591
+ bindAddr.saIn.sin_addr.s_addr = htonl(INADDR_ANY);
2592
+ }
2593
+ else if(addr.saStorage.ss_family == AF_INET6)
2594
+ {
2595
+ bindAddr.saIn6.sin6_family = AF_INET6;
2596
+ bindAddr.saIn6.sin6_port = htons(0);
2597
+ bindAddr.saIn6.sin6_addr = in6addr_any;
2598
+ }
2599
+ }
2600
+
2601
+ int size = getAddressStorageSize(bindAddr);
2602
+ assert(size != 0);
2603
+
2604
+ if(::bind(fd, &bindAddr.sa, size) == SOCKET_ERROR)
2605
+ {
2606
+ SocketException ex(__FILE__, __LINE__);
2607
+ ex.error = getSocketErrno();
2608
+ throw ex;
2609
+ }
2610
+
2611
+ LPFN_CONNECTEX ConnectEx = NULL; // a pointer to the 'ConnectEx()' function
2612
+ GUID GuidConnectEx = WSAID_CONNECTEX; // The Guid
2613
+ DWORD dwBytes;
2614
+ if(WSAIoctl(fd,
2615
+ SIO_GET_EXTENSION_FUNCTION_POINTER,
2616
+ &GuidConnectEx,
2617
+ sizeof(GuidConnectEx),
2618
+ &ConnectEx,
2619
+ sizeof(ConnectEx),
2620
+ &dwBytes,
2621
+ NULL,
2622
+ NULL) == SOCKET_ERROR)
2623
+ {
2624
+ SocketException ex(__FILE__, __LINE__);
2625
+ ex.error = getSocketErrno();
2626
+ throw ex;
2627
+ }
2628
+
2629
+ if(!ConnectEx(fd, &addr.sa, size, 0, 0, 0, &info))
2630
+ {
2631
+ if(!connectInProgress())
2632
+ {
2633
+ if(connectionRefused())
2634
+ {
2635
+ ConnectionRefusedException ex(__FILE__, __LINE__);
2636
+ ex.error = getSocketErrno();
2637
+ throw ex;
2638
+ }
2639
+ else if(connectFailed())
2640
+ {
2641
+ ConnectFailedException ex(__FILE__, __LINE__);
2642
+ ex.error = getSocketErrno();
2643
+ throw ex;
2644
+ }
2645
+ else
2646
+ {
2647
+ SocketException ex(__FILE__, __LINE__);
2648
+ ex.error = getSocketErrno();
2649
+ throw ex;
2650
+ }
2651
+ }
2652
+ }
2653
+ }
2654
+
2655
+ void
2656
+ IceInternal::doFinishConnectAsync(SOCKET fd, AsyncInfo& info)
2657
+ {
2658
+ //
2659
+ // NOTE: It's the caller's responsability to close the socket upon
2660
+ // failure to connect. The socket isn't closed by this method.
2661
+ //
2662
+
2663
+ if(static_cast<int>(info.count) == SOCKET_ERROR)
2664
+ {
2665
+ WSASetLastError(info.error);
2666
+ if(connectionRefused())
2667
+ {
2668
+ ConnectionRefusedException ex(__FILE__, __LINE__);
2669
+ ex.error = getSocketErrno();
2670
+ throw ex;
2671
+ }
2672
+ else if(connectFailed())
2673
+ {
2674
+ ConnectFailedException ex(__FILE__, __LINE__);
2675
+ ex.error = getSocketErrno();
2676
+ throw ex;
2677
+ }
2678
+ else
2679
+ {
2680
+ SocketException ex(__FILE__, __LINE__);
2681
+ ex.error = getSocketErrno();
2682
+ throw ex;
2683
+ }
2684
+ }
2685
+
2686
+ if(setsockopt(fd, SOL_SOCKET, SO_UPDATE_CONNECT_CONTEXT, NULL, 0) == SOCKET_ERROR)
2687
+ {
2688
+ SocketException ex(__FILE__, __LINE__);
2689
+ ex.error = getSocketErrno();
2690
+ throw ex;
2691
+ }
2692
+ }
2693
+ #endif
2694
+