-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsck.h
More file actions
45 lines (31 loc) · 1.07 KB
/
sck.h
File metadata and controls
45 lines (31 loc) · 1.07 KB
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
//See sck.c for function documentation.
#ifndef SCK_H
#define SCK_H
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdbool.h>
#include <errno.h>
#define DEFAULT_NETSOCKET_BACKLOG 4
typedef struct NetSocket_s {
int socket_desc;
struct sockaddr_in server;
int errorNumber;
} NetSocket_t;
typedef struct SocketPayload_s {
char * data;
size_t capacity;
int size; //need to accommodate EOF
} SocketPayload_t;
NetSocket_t * newNetSocketClient(char * address, uint16_t port);
bool connectNetSocket(NetSocket_t * socket);
NetSocket_t * newNetSocketServer(uint16_t port);
bool listenNetSocket(NetSocket_t * socket);
NetSocket_t * acceptNetSocket(NetSocket_t * serverSocket);
SocketPayload_t * readNetSocket(NetSocket_t * socket, size_t numBytes);
SocketPayload_t * readLineNetSocket(NetSocket_t * socket);
bool writeNetSocket(NetSocket_t * socket, char * bytes, size_t numBytes);
void destroyNetSocket(NetSocket_t * sock);
void destroySocketPayload(SocketPayload_t * payload);
char * getNetSocketError(NetSocket_t * socket);
void testSock();
#endif /* SCK_H */