generated from bearycool11/AI_memory_Loops
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio_socket.h
59 lines (47 loc) · 1.63 KB
/
io_socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef UNIFIED_IO_H
#define UNIFIED_IO_H
#include <libwebsockets.h>
#include <stddef.h> // For size_t
// Buffer and Retry Constants
#define BUFFER_SIZE 2048
#define LOG_FILE "io_socket.log"
#define RETRY_LIMIT 5
// IO Types
typedef enum {
IO_TYPE_TCP,
IO_TYPE_WEBSOCKET
} io_type_t;
// Unified IO Structure
typedef struct {
io_type_t type; // IO type (TCP/WebSocket)
int tcp_socket; // TCP socket descriptor
struct lws *websocket; // WebSocket handle
struct lws_context *ws_context; // WebSocket context
} unified_io_t;
// IO Configuration Structure
typedef struct {
const char *address; // Address or hostname
int port; // Port number
io_type_t type; // IO type
} io_config_t;
// Known Configurations Array
extern io_config_t known_configs[];
extern int config_count;
// Logging Utility
void log_message(const char *level, const char *message);
// TCP/IP Functions
int init_tcp_socket(const char *ip, int port);
int tcp_send(int socket, const char *message);
int tcp_receive(int socket, char *buffer, size_t buffer_size);
// WebSocket Functions
struct lws_context *init_websocket_context();
struct lws *connect_websocket(struct lws_context *ctx, const char *address, int port);
void websocket_send(struct lws *wsi, const char *message);
// Unified IO Functions
unified_io_t *init_unified_io(io_config_t *config);
void send_message(unified_io_t *io, const char *message);
void receive_message(unified_io_t *io, char *buffer, size_t buffer_size);
void cleanup_unified_io(unified_io_t *io);
// Dynamic Logic Loop
unified_io_t *dynamic_io_loop();
#endif // UNIFIED_IO_H