-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcpstream.c
34 lines (27 loc) · 1 KB
/
tcpstream.c
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
/**
* Melon Software Framework is Copyright (C) 2021 - 2025 Knot126
*
* =============================================================================
*
* Use TCP sockets as streams
*/
#include "error.h"
#include "tcpstream.h"
static DgError DgTCPSocketStream_Open(DgStream *context, const void *tcp_socket, DgStreamOpenFlags flags) {
context->context = (void *) tcp_socket;
return DG_ERROR_SUCCESS;
}
static DgError DgTCPSocketStream_Read(DgStream *context, size_t size, void *buffer) {
return DgTCPSocketRecieve((DgTCPSocket *) context->context, size, buffer);
}
static DgError DgTCPSocketStream_Write(DgStream *context, size_t size, const void *buffer) {
return DgTCPSocketSend((DgTCPSocket *) context->context, size, buffer);
}
DgStreamImp gTCPSocketStreamImp = {
.open = &DgTCPSocketStream_Open,
.read = &DgTCPSocketStream_Read,
.write = &DgTCPSocketStream_Write,
};
void DgStreamForTCPSocket(DgTCPSocket *socket, DgStream *stream) {
DgStreamOpen(stream, &gTCPSocketStreamImp, (void *) socket, 0);
}