|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +using Microsoft.Quic; |
| 5 | + |
| 6 | +namespace System.Net.Quic; |
| 7 | + |
| 8 | +internal sealed unsafe partial class MsQuicApi |
| 9 | +{ |
| 10 | + public void SetContext(MsQuicSafeHandle handle, void* context) |
| 11 | + { |
| 12 | + bool success = false; |
| 13 | + try |
| 14 | + { |
| 15 | + handle.DangerousAddRef(ref success); |
| 16 | + ApiTable->SetContext(handle.QuicHandle, context); |
| 17 | + } |
| 18 | + finally |
| 19 | + { |
| 20 | + if (success) |
| 21 | + { |
| 22 | + handle.DangerousRelease(); |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + public void* GetContext(MsQuicSafeHandle handle) |
| 28 | + { |
| 29 | + bool success = false; |
| 30 | + try |
| 31 | + { |
| 32 | + handle.DangerousAddRef(ref success); |
| 33 | + return ApiTable->GetContext(handle.QuicHandle); |
| 34 | + } |
| 35 | + finally |
| 36 | + { |
| 37 | + if (success) |
| 38 | + { |
| 39 | + handle.DangerousRelease(); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + public void SetCallbackHandler(MsQuicSafeHandle handle, void* callback, void* context) |
| 45 | + { |
| 46 | + bool success = false; |
| 47 | + try |
| 48 | + { |
| 49 | + handle.DangerousAddRef(ref success); |
| 50 | + ApiTable->SetCallbackHandler(handle.QuicHandle, callback, context); |
| 51 | + } |
| 52 | + finally |
| 53 | + { |
| 54 | + if (success) |
| 55 | + { |
| 56 | + handle.DangerousRelease(); |
| 57 | + } |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + public int SetParam(MsQuicSafeHandle handle, uint param, uint bufferLength, void* buffer) |
| 62 | + { |
| 63 | + bool success = false; |
| 64 | + try |
| 65 | + { |
| 66 | + handle.DangerousAddRef(ref success); |
| 67 | + return ApiTable->SetParam(handle.QuicHandle, param, bufferLength, buffer); |
| 68 | + } |
| 69 | + finally |
| 70 | + { |
| 71 | + if (success) |
| 72 | + { |
| 73 | + handle.DangerousRelease(); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + public int GetParam(MsQuicSafeHandle handle, uint param, uint* bufferLength, void* buffer) |
| 79 | + { |
| 80 | + bool success = false; |
| 81 | + try |
| 82 | + { |
| 83 | + handle.DangerousAddRef(ref success); |
| 84 | + return ApiTable->GetParam(handle.QuicHandle, param, bufferLength, buffer); |
| 85 | + } |
| 86 | + finally |
| 87 | + { |
| 88 | + if (success) |
| 89 | + { |
| 90 | + handle.DangerousRelease(); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + public void RegistrationShutdown(MsQuicSafeHandle registration, QUIC_CONNECTION_SHUTDOWN_FLAGS flags, ulong code) |
| 96 | + { |
| 97 | + bool success = false; |
| 98 | + try |
| 99 | + { |
| 100 | + registration.DangerousAddRef(ref success); |
| 101 | + ApiTable->RegistrationShutdown(registration.QuicHandle, flags, code); |
| 102 | + } |
| 103 | + finally |
| 104 | + { |
| 105 | + if (success) |
| 106 | + { |
| 107 | + registration.DangerousRelease(); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + public int ConfigurationOpen(MsQuicSafeHandle registration, QUIC_BUFFER* alpnBuffers, uint alpnBuffersCount, QUIC_SETTINGS* settings, uint settingsSize, void* context, QUIC_HANDLE** configuration) |
| 113 | + { |
| 114 | + bool success = false; |
| 115 | + try |
| 116 | + { |
| 117 | + registration.DangerousAddRef(ref success); |
| 118 | + return ApiTable->ConfigurationOpen(registration.QuicHandle, alpnBuffers, alpnBuffersCount, settings, settingsSize, context, configuration); |
| 119 | + } |
| 120 | + finally |
| 121 | + { |
| 122 | + if (success) |
| 123 | + { |
| 124 | + registration.DangerousRelease(); |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + public int ConfigurationLoadCredential(MsQuicSafeHandle configuration, QUIC_CREDENTIAL_CONFIG* config) |
| 130 | + { |
| 131 | + bool success = false; |
| 132 | + try |
| 133 | + { |
| 134 | + configuration.DangerousAddRef(ref success); |
| 135 | + return ApiTable->ConfigurationLoadCredential(configuration.QuicHandle, config); |
| 136 | + } |
| 137 | + finally |
| 138 | + { |
| 139 | + if (success) |
| 140 | + { |
| 141 | + configuration.DangerousRelease(); |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + public int ListenerOpen(MsQuicSafeHandle registration, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_LISTENER_EVENT*, int> callback, void* context, QUIC_HANDLE** listener) |
| 147 | + { |
| 148 | + bool success = false; |
| 149 | + try |
| 150 | + { |
| 151 | + registration.DangerousAddRef(ref success); |
| 152 | + return ApiTable->ListenerOpen(registration.QuicHandle, callback, context, listener); |
| 153 | + } |
| 154 | + finally |
| 155 | + { |
| 156 | + if (success) |
| 157 | + { |
| 158 | + registration.DangerousRelease(); |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + public int ListenerStart(MsQuicSafeHandle listener, QUIC_BUFFER* alpnBuffers, uint alpnBuffersCount, QuicAddr* localAddress) |
| 164 | + { |
| 165 | + bool success = false; |
| 166 | + try |
| 167 | + { |
| 168 | + listener.DangerousAddRef(ref success); |
| 169 | + return ApiTable->ListenerStart(listener.QuicHandle, alpnBuffers, alpnBuffersCount, localAddress); |
| 170 | + } |
| 171 | + finally |
| 172 | + { |
| 173 | + if (success) |
| 174 | + { |
| 175 | + listener.DangerousRelease(); |
| 176 | + } |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + public void ListenerStop(MsQuicSafeHandle listener) |
| 181 | + { |
| 182 | + bool success = false; |
| 183 | + try |
| 184 | + { |
| 185 | + listener.DangerousAddRef(ref success); |
| 186 | + ApiTable->ListenerStop(listener.QuicHandle); |
| 187 | + } |
| 188 | + finally |
| 189 | + { |
| 190 | + if (success) |
| 191 | + { |
| 192 | + listener.DangerousRelease(); |
| 193 | + } |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | + public int ConnectionOpen(MsQuicSafeHandle registration, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_CONNECTION_EVENT*, int> callback, void* context, QUIC_HANDLE** connection) |
| 198 | + { |
| 199 | + bool success = false; |
| 200 | + try |
| 201 | + { |
| 202 | + registration.DangerousAddRef(ref success); |
| 203 | + return ApiTable->ConnectionOpen(registration.QuicHandle, callback, context, connection); |
| 204 | + } |
| 205 | + finally |
| 206 | + { |
| 207 | + if (success) |
| 208 | + { |
| 209 | + registration.DangerousRelease(); |
| 210 | + } |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + public void ConnectionShutdown(MsQuicSafeHandle connection, QUIC_CONNECTION_SHUTDOWN_FLAGS flags, ulong code) |
| 215 | + { |
| 216 | + bool success = false; |
| 217 | + try |
| 218 | + { |
| 219 | + connection.DangerousAddRef(ref success); |
| 220 | + ApiTable->ConnectionShutdown(connection.QuicHandle, flags, code); |
| 221 | + } |
| 222 | + finally |
| 223 | + { |
| 224 | + if (success) |
| 225 | + { |
| 226 | + connection.DangerousRelease(); |
| 227 | + } |
| 228 | + } |
| 229 | + } |
| 230 | + |
| 231 | + public int ConnectionStart(MsQuicSafeHandle connection, MsQuicSafeHandle configuration, ushort family, sbyte* serverName, ushort serverPort) |
| 232 | + { |
| 233 | + bool connectionSuccess = false; |
| 234 | + bool configurationSuccess = false; |
| 235 | + try |
| 236 | + { |
| 237 | + connection.DangerousAddRef(ref connectionSuccess); |
| 238 | + configuration.DangerousAddRef(ref configurationSuccess); |
| 239 | + return ApiTable->ConnectionStart(connection.QuicHandle, configuration.QuicHandle, family, serverName, serverPort); |
| 240 | + } |
| 241 | + finally |
| 242 | + { |
| 243 | + if (connectionSuccess) |
| 244 | + { |
| 245 | + connection.DangerousRelease(); |
| 246 | + } |
| 247 | + if (configurationSuccess) |
| 248 | + { |
| 249 | + configuration.DangerousRelease(); |
| 250 | + } |
| 251 | + } |
| 252 | + } |
| 253 | + |
| 254 | + public int ConnectionSetConfiguration(MsQuicSafeHandle connection, MsQuicSafeHandle configuration) |
| 255 | + { |
| 256 | + bool connectionSuccess = false; |
| 257 | + bool configurationSuccess = false; |
| 258 | + try |
| 259 | + { |
| 260 | + connection.DangerousAddRef(ref connectionSuccess); |
| 261 | + configuration.DangerousAddRef(ref configurationSuccess); |
| 262 | + return ApiTable->ConnectionSetConfiguration(connection.QuicHandle, configuration.QuicHandle); |
| 263 | + } |
| 264 | + finally |
| 265 | + { |
| 266 | + if (connectionSuccess) |
| 267 | + { |
| 268 | + connection.DangerousRelease(); |
| 269 | + } |
| 270 | + if (configurationSuccess) |
| 271 | + { |
| 272 | + configuration.DangerousRelease(); |
| 273 | + } |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + public int StreamOpen(MsQuicSafeHandle connection, QUIC_STREAM_OPEN_FLAGS flags, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_STREAM_EVENT*, int> callback, void* context, QUIC_HANDLE** stream) |
| 278 | + { |
| 279 | + bool success = false; |
| 280 | + try |
| 281 | + { |
| 282 | + connection.DangerousAddRef(ref success); |
| 283 | + return ApiTable->StreamOpen(connection.QuicHandle, flags, callback, context, stream); |
| 284 | + } |
| 285 | + finally |
| 286 | + { |
| 287 | + if (success) |
| 288 | + { |
| 289 | + connection.DangerousRelease(); |
| 290 | + } |
| 291 | + } |
| 292 | + } |
| 293 | + |
| 294 | + public int StreamStart(MsQuicSafeHandle stream, QUIC_STREAM_START_FLAGS flags) |
| 295 | + { |
| 296 | + bool success = false; |
| 297 | + try |
| 298 | + { |
| 299 | + stream.DangerousAddRef(ref success); |
| 300 | + return ApiTable->StreamStart(stream.QuicHandle, flags); |
| 301 | + } |
| 302 | + finally |
| 303 | + { |
| 304 | + if (success) |
| 305 | + { |
| 306 | + stream.DangerousRelease(); |
| 307 | + } |
| 308 | + } |
| 309 | + } |
| 310 | + |
| 311 | + public int StreamShutdown(MsQuicSafeHandle stream, QUIC_STREAM_SHUTDOWN_FLAGS flags, ulong code) |
| 312 | + { |
| 313 | + bool success = false; |
| 314 | + try |
| 315 | + { |
| 316 | + stream.DangerousAddRef(ref success); |
| 317 | + return ApiTable->StreamShutdown(stream.QuicHandle, flags, code); |
| 318 | + } |
| 319 | + finally |
| 320 | + { |
| 321 | + if (success) |
| 322 | + { |
| 323 | + stream.DangerousRelease(); |
| 324 | + } |
| 325 | + } |
| 326 | + } |
| 327 | + |
| 328 | + public int StreamSend(MsQuicSafeHandle stream, QUIC_BUFFER* buffers, uint buffersCount, QUIC_SEND_FLAGS flags, void* context) |
| 329 | + { |
| 330 | + bool success = false; |
| 331 | + try |
| 332 | + { |
| 333 | + stream.DangerousAddRef(ref success); |
| 334 | + return ApiTable->StreamSend(stream.QuicHandle, buffers, buffersCount, flags, context); |
| 335 | + } |
| 336 | + finally |
| 337 | + { |
| 338 | + if (success) |
| 339 | + { |
| 340 | + stream.DangerousRelease(); |
| 341 | + } |
| 342 | + } |
| 343 | + } |
| 344 | + |
| 345 | + public void StreamReceiveComplete(MsQuicSafeHandle stream, ulong length) |
| 346 | + { |
| 347 | + bool success = false; |
| 348 | + try |
| 349 | + { |
| 350 | + stream.DangerousAddRef(ref success); |
| 351 | + ApiTable->StreamReceiveComplete(stream.QuicHandle, length); |
| 352 | + } |
| 353 | + finally |
| 354 | + { |
| 355 | + if (success) |
| 356 | + { |
| 357 | + stream.DangerousRelease(); |
| 358 | + } |
| 359 | + } |
| 360 | + } |
| 361 | + |
| 362 | + public int StreamReceiveSetEnabled(MsQuicSafeHandle stream, byte enabled) |
| 363 | + { |
| 364 | + bool success = false; |
| 365 | + try |
| 366 | + { |
| 367 | + stream.DangerousAddRef(ref success); |
| 368 | + return ApiTable->StreamReceiveSetEnabled(stream.QuicHandle, enabled); |
| 369 | + } |
| 370 | + finally |
| 371 | + { |
| 372 | + if (success) |
| 373 | + { |
| 374 | + stream.DangerousRelease(); |
| 375 | + } |
| 376 | + } |
| 377 | + } |
| 378 | +} |
0 commit comments