-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket.h
48 lines (41 loc) · 1 KB
/
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
#ifndef PLXR_SOCKET_H
#define PLXR_SOCKET_H
#include <netinet/in.h>
/* creates & binds a new listener socket
* returns a new file descriptor on success or -1 on failure
*/
int
plxr_socket_listen(struct sockaddr_in *addr, int port);
/* wrapper around inet_ntop
*/
const char *
plxr_socket_ntop(struct sockaddr *addr);
// TODO: move read / write logic under a nicer abstraction.
// right now the server logic has to worry about too many low level issues.
/* Writes to a socket `fd` with a specified timeout in milliseconds from a buffer `data`.
*
* returns
* number of bytes wrote on success
* -1 on error
*/
int
plxr_socket_write_timeout(
int fd,
const char *data,
size_t data_len,
int timeout_milliseconds
);
/* Read from a socket `fd` with a specified timeout in milliseconds into a buffer at `data`
*
* returns
* number of bytes read on success
* -1 on error
*/
int
plxr_socket_read_timeout(
int fd,
char *data,
size_t data_max,
int timeout_milliseconds
);
#endif /* PLXR_SOCKET_H */