MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / async_pipe_create

Function async_pipe_create

lib/asyncpipe.c:9–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7static volatile long pipe_serial_nunber;
8
9int async_pipe_create(hamlib_async_pipe_t **pipe_out,
10 unsigned long pipe_buffer_size, unsigned long pipe_connect_timeout_millis)
11{
12 DWORD error_code;
13 CHAR pipe_name[MAX_PATH];
14 hamlib_async_pipe_t *pipe;
15
16 pipe = calloc(1, sizeof(hamlib_async_pipe_t));
17
18 if (pipe == NULL)
19 {
20 return -RIG_ENOMEM;
21 }
22
23 if (pipe_buffer_size == 0)
24 {
25 pipe_buffer_size = PIPE_BUFFER_SIZE_DEFAULT;
26 }
27
28 SNPRINTF(pipe_name, sizeof(pipe_name),
29 "\\\\.\\Pipe\\Hamlib.%08lx.%08lx",
30 GetCurrentProcessId(),
31 InterlockedIncrement(&pipe_serial_nunber)
32 );
33
34 pipe->read = CreateNamedPipe(
35 pipe_name,
36 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
37 PIPE_TYPE_BYTE | PIPE_WAIT,
38 1, // Number of pipes
39 pipe_buffer_size, // Out buffer size
40 pipe_buffer_size, // In buffer size
41 pipe_connect_timeout_millis, // Timeout in ms
42 NULL);
43
44 if (!pipe->read)
45 {
46 free(pipe);
47 return -RIG_EINTERNAL;
48 }
49
50 pipe->write = CreateFile(
51 pipe_name,
52 GENERIC_WRITE,
53 0, // No sharing
54 NULL,
55 OPEN_EXISTING,
56 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
57 NULL // Template file
58 );
59
60 if (pipe->write == INVALID_HANDLE_VALUE)
61 {
62 error_code = GetLastError();
63 CloseHandle(pipe->read);
64 free(pipe);
65 SetLastError(error_code);
66 return -RIG_EINTERNAL;

Callers 2

create_sync_data_pipeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected