master
hpp 61 lines 1.86 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 socket.hpp
8
9 Abstract:
10
11 This file contains socket helper function declarations.
12
13 --*/
14
15 #pragma once
16
17 #include <wil/resource.h>
18
19 namespace wsl::windows::common::socket {
20
21 // Sets SO_UPDATE_ACCEPT_CONTEXT on a socket accepted via AcceptEx to mark it as connected.
22 void SetAcceptContext(_In_ SOCKET AcceptedSocket, _In_ SOCKET ListenSocket, _In_ const std::source_location& Location = std::source_location::current());
23
24 std::optional<wil::unique_socket> CancellableAccept(
25 _In_ SOCKET ListenSocket,
26 _In_ DWORD Timeout,
27 _In_opt_ HANDLE ExitHandle,
28 _In_ const std::source_location& Location = std::source_location::current());
29
30 std::pair<DWORD, DWORD> GetResult(
31 _In_ SOCKET Socket, _In_ OVERLAPPED& Overlapped, _In_ DWORD Timeout, _In_ HANDLE ExitHandle, _In_ const std::source_location& Location);
32
33 int Receive(
34 _In_ SOCKET Socket,
35 _In_ gsl::span<gsl::byte> Buffer,
36 _In_opt_ HANDLE ExitHandle = nullptr,
37 _In_ DWORD Flags = MSG_WAITALL,
38 _In_ DWORD Timeout = INFINITE,
39 _In_ const std::source_location& Location = std::source_location::current());
40
41 std::vector<gsl::byte> Receive(
42 _In_ SOCKET Socket,
43 _In_opt_ HANDLE ExitHandle = nullptr,
44 _In_ DWORD Timeout = INFINITE,
45 _In_ const std::source_location& Location = std::source_location::current());
46
47 int ReceiveNoThrow(
48 _In_ SOCKET Socket,
49 _In_ gsl::span<gsl::byte> Buffer,
50 _In_opt_ HANDLE ExitHandle = nullptr,
51 _In_ DWORD Flags = MSG_WAITALL,
52 _In_ DWORD Timeout = INFINITE,
53 _In_ const std::source_location& Location = std::source_location::current());
54
55 int Send(
56 _In_ SOCKET Socket,
57 _In_ gsl::span<const gsl::byte> Buffer,
58 _In_opt_ HANDLE ExitHandle = nullptr,
59 _In_ const std::source_location& Location = std::source_location::current());
60
61 } // namespace wsl::windows::common::socket