Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ca1e5e3975f9da575f62c5f6a431b2d1f8b3ea0f (plain) (blame)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifdef __cplusplus
extern "C" {
#endif

#ifndef _ETSOCKET_H_
#define _ETSOCKET_H_

#include "etDatatypes.h"

/*
 * Data structure representing an etSocket
 * etSocket is used to establish a tcp connection
 * Must be initialized with etSocket_construct and cleaned up with etSocket_destruct
 */
typedef struct {
	etOSSocketData socket;
}
etSocket;

/*
 * Data structure representing an etServerSocket
 * etServerSocket can open a port that clients can connect to via tcp
 * Must be initialized with etServerSocket_construct and cleaned up with etServerSocket_destruct
 */
typedef struct {
	etOSSocketData serverSocket;
}
etServerSocket;

/*
 * Constructs a new etSocket and connects to the specified host
 * @param self: pointer to etSocket
 * @param address: address of the host to connect to
 * @param port: port of the host
 * @return: 0 on success
 */
int etSocket_construct(etSocket* self, const char* address, short port);

/*
 * Destructs the etSocket
 * @param self: pointer to etSocket
 * @return: 0 on success
 */
int etSocket_destruct(etSocket* self);

/*
 * Receives data from an etSocket
 * @param self: pointer to etSocket
 * @param buffer: buffer for received data
 * @param length: max length of received data
 * @return: length of received data, -1 when failed
 */
int etSocket_recv(etSocket* self, uint8* buffer, size_t length);

/*
 * Sends data over the etSocket
 * @param self: pointer to etSocket
 * @param buffer: buffer that holds the data to be sent
 * @param length: length of the data
 * @return: length of sent data, -1 when failed
 */
int etSocket_send(etSocket* self, uint8* buffer, size_t length);


/*
 * Constructs a new etServerSocket and starts to listen on the specified port
 * @param self: pointer to etServerSocket
 * @param port: port number
 * @return: 0 on success
 */
int etServerSocket_construct(etServerSocket* self, short port);

/*
 * Destructs an etServerSocket
 * @param self: pointer to etServerSocket
 * @return: 0 on success
 */
int etServerSocket_destruct(etServerSocket* self);

/*
 * Accepts a new connection
 * @param self: pointer to etServerSocket
 * @param socket: pointer to the etSocket for the new connection
 */
int etServerSocket_accept(etServerSocket* self, etSocket* socket);


#endif /* _ETSOCKET_H_ */

#ifdef __cplusplus
}
#endif

Back to the top