Skip to content

Commit cb4e784

Browse files
danielinuxjaromil
authored andcommitted
Added missing files
1 parent f9c3e21 commit cb4e784

3 files changed

Lines changed: 71 additions & 0 deletions

File tree

src/h2_session.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "h2_session.h"
2+
3+
enum dohd_h2_stream_close_action dohd_h2_stream_close_action(int has_request,
4+
int owner_matches)
5+
{
6+
if (!has_request || !owner_matches)
7+
return DOHD_H2_STREAM_CLOSE_IGNORE;
8+
9+
return DOHD_H2_STREAM_CLOSE_DESTROY;
10+
}

src/h2_session.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef DOHD_H2_SESSION_H
2+
#define DOHD_H2_SESSION_H
3+
4+
enum dohd_h2_stream_close_action {
5+
DOHD_H2_STREAM_CLOSE_IGNORE = 0,
6+
DOHD_H2_STREAM_CLOSE_DESTROY = 1,
7+
};
8+
9+
enum dohd_h2_stream_close_action dohd_h2_stream_close_action(int has_request,
10+
int owner_matches);
11+
12+
#endif

test/test_h2_session.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* dohd test unit for HTTP/2 session helpers */
2+
3+
#include <stdio.h>
4+
#include "../src/h2_session.h"
5+
6+
static int tests_run = 0;
7+
static int tests_passed = 0;
8+
9+
#define TEST_ASSERT(cond, msg) do { \
10+
tests_run++; \
11+
if (!(cond)) { \
12+
fprintf(stderr, "FAIL: %s\n", msg); \
13+
return 0; \
14+
} \
15+
tests_passed++; \
16+
fprintf(stderr, "PASS: %s\n", msg); \
17+
} while (0)
18+
19+
static int test_stream_close_ignores_detached_stream(void)
20+
{
21+
TEST_ASSERT(dohd_h2_stream_close_action(0, 0) ==
22+
DOHD_H2_STREAM_CLOSE_IGNORE,
23+
"stream close ignores missing request");
24+
TEST_ASSERT(dohd_h2_stream_close_action(1, 0) ==
25+
DOHD_H2_STREAM_CLOSE_IGNORE,
26+
"stream close ignores owner mismatch");
27+
return 1;
28+
}
29+
30+
static int test_stream_close_destroys_owned_request(void)
31+
{
32+
TEST_ASSERT(dohd_h2_stream_close_action(1, 1) ==
33+
DOHD_H2_STREAM_CLOSE_DESTROY,
34+
"stream close destroys matching request");
35+
return 1;
36+
}
37+
38+
int main(void)
39+
{
40+
int ok = 1;
41+
42+
fprintf(stderr, "=== HTTP/2 Session Helper Tests ===\n");
43+
44+
ok &= test_stream_close_ignores_detached_stream();
45+
ok &= test_stream_close_destroys_owned_request();
46+
47+
fprintf(stderr, "\n%d/%d tests passed\n", tests_passed, tests_run);
48+
return ok ? 0 : 1;
49+
}

0 commit comments

Comments
 (0)