-
Notifications
You must be signed in to change notification settings - Fork 29
/
tcp.h
38 lines (29 loc) · 1.14 KB
/
tcp.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
/* tcp.h
* By Ron
* Created August, 2008
*
* (See LICENSE.txt)
*
* Platform-independent module for creating/sending TCP sockets for IPv4 TCP connections.
*/
#ifndef __TCP_H__
#define __TCP_H__
#include "types.h"
/* Must be called before any other functions. */
void winsock_initialize();
/* Connect to the remote server on the given port. Prints an error to the screen and
* returns -1 if it fails; otherwise, returns the new socket. */
int tcp_connect(char *host, uint16_t port);
/* Puts a socket into listening mode on the given address (use '0.0.0.0' for any).
* Returns -1 on an error, or the socket if successful. */
int tcp_listen(char *address, uint16_t port);
/* Accepts a connection on a listening socket. Returns the new socket if successful
* or -1 if fails. */
int tcp_accept(int listen, char **address, uint16_t *port);
/* Send data over the socket. Can use built-in IO functions, too. */
size_t tcp_send(int s, void *data, size_t length);
/* Receive data from the socket. Can use built-in IO functions, too. */
size_t tcp_recv(int s, void *buffer, size_t buffer_length);
/* Close the socket. */
int tcp_close(int s);
#endif