Skip to content

Commit cd30972

Browse files
committed
remove data.txt from repository
1 parent 5f39e64 commit cd30972

File tree

3 files changed

+424
-71
lines changed

3 files changed

+424
-71
lines changed

.github/workflows/make.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

include/stream.h

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,109 @@
22
#define AIONIC_STREAM_H
33

44
#include "parser.h"
5+
#include <pthread.h>
6+
#include <stdint.h>
7+
#include <stdbool.h>
58

9+
// Stream operation result codes
10+
typedef enum {
11+
STREAM_SUCCESS = 0,
12+
STREAM_ERROR_NULL,
13+
STREAM_ERROR_INVALID_FD,
14+
STREAM_ERROR_MEMORY,
15+
STREAM_ERROR_TIMEOUT,
16+
STREAM_ERROR_CLOSED,
17+
STREAM_ERROR_OVERFLOW
18+
} StreamResult;
19+
20+
// Stream statistics structure
21+
typedef struct {
22+
uint64_t bytes_sent; // For network streams: bytes sent
23+
uint64_t bytes_received; // For network streams: bytes received
24+
uint64_t chunks_sent; // For network streams: number of chunks sent
25+
uint64_t operations_count; // For both: number of operations
26+
uint64_t total_time_ns; // For both: total time in nanoseconds
27+
uint64_t bytes_written; // For buffer streams: bytes written
28+
uint64_t bytes_read; // For buffer streams: bytes read
29+
} StreamStats;
30+
31+
// Stream configuration options
32+
typedef struct {
33+
size_t buffer_size;
34+
bool chunked_encoding;
35+
uint32_t timeout_ms;
36+
bool non_blocking;
37+
uint8_t priority;
38+
} StreamConfig;
39+
40+
// Stream callback function types
41+
typedef void (*StreamDataCallback)(const char* data, size_t length, void* user_data);
42+
typedef void (*StreamErrorCallback)(StreamResult error, void* user_data);
43+
44+
// Original StreamData structure with enhancements
645
typedef struct {
746
int client_fd;
847
char *buffer;
948
size_t buffer_size;
1049
size_t buffer_position;
11-
int is_active;
12-
int chunked_encoding;
50+
bool is_active;
51+
bool chunked_encoding;
52+
53+
// Enhanced features
54+
pthread_mutex_t mutex;
55+
StreamConfig config;
56+
StreamStats stats;
57+
StreamDataCallback data_callback;
58+
StreamErrorCallback error_callback;
59+
void* user_data;
60+
uint64_t last_activity_ns;
1361
} StreamData;
1462

15-
// Stream buffer structure for in-memory operations
63+
// Enhanced StreamBuffer structure
1664
typedef struct {
1765
char *data;
1866
size_t size;
1967
size_t pos;
2068
size_t capacity;
69+
70+
// Enhanced features
71+
pthread_mutex_t mutex;
72+
StreamStats stats;
73+
bool auto_expand;
74+
size_t max_capacity;
2175
} StreamBuffer;
2276

23-
// Stream functions
77+
// Original stream functions (maintained for compatibility)
2478
int stream_init(StreamData *stream, int client_fd);
2579
int stream_send_chunk(StreamData *stream, const char *data, size_t length);
2680
int stream_end(StreamData *stream);
2781
int stream_response(int client_fd, RouteResponse *response);
2882
void stream_cleanup(StreamData *stream);
2983

30-
// Stream buffer functions
84+
// Enhanced stream functions
85+
int stream_init_ex(StreamData *stream, int client_fd, const StreamConfig *config);
86+
int stream_send_chunk_ex(StreamData *stream, const char *data, size_t length, uint32_t timeout_ms);
87+
StreamResult stream_send_with_callback(StreamData *stream, const char *data, size_t length,
88+
StreamDataCallback callback, void* user_data);
89+
void stream_get_stats(const StreamData *stream, StreamStats *stats);
90+
void stream_set_callbacks(StreamData *stream, StreamDataCallback data_cb,
91+
StreamErrorCallback error_cb, void* user_data);
92+
93+
// Original stream buffer functions (maintained for compatibility)
3194
int stream_buffer_init(StreamBuffer *stream, size_t initial_size);
3295
int stream_buffer_write(StreamBuffer *stream, const void *data, size_t size);
3396
int stream_buffer_read(StreamBuffer *stream, void *data, size_t size);
3497
void stream_buffer_reset(StreamBuffer *stream);
3598
void stream_buffer_cleanup(StreamBuffer *stream);
3699

100+
// Enhanced stream buffer functions
101+
int stream_buffer_init_ex(StreamBuffer *stream, size_t initial_size, bool auto_expand, size_t max_capacity);
102+
StreamResult stream_buffer_write_ex(StreamBuffer *stream, const void *data, size_t size, bool expand);
103+
StreamResult stream_buffer_read_ex(StreamBuffer *stream, void *data, size_t size, bool advance);
104+
void stream_buffer_get_stats(const StreamBuffer *stream, StreamStats *stats);
105+
106+
// Utility functions
107+
const char* stream_result_to_string(StreamResult result);
108+
void stream_print_stats(const StreamData *stream);
109+
37110
#endif // AIONIC_STREAM_H

0 commit comments

Comments
 (0)