- get_entity_nr() now takes an cont entity
[libfirm] / ir / net / firmnet.h
1 #ifndef _FIRMNET_H_
2 #define _FIRMNET_H_
3
4 #ifdef _WIN32
5 #include <winsock.h>
6 #include <io.h>
7
8 #else /* _WIN32 */
9 #include <sys/time.h>
10 #include <sys/socket.h>
11 #include <sys/types.h>
12 #include <sys/resource.h>
13 #include <sys/wait.h>
14
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
17 #include <netdb.h>
18
19 #include <unistd.h>
20 #endif /* _WIN32 */
21
22 #include <signal.h>
23 #include <errno.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27
28 #ifdef _MSC_VER
29
30 typedef size_t                          ssize_t;
31 typedef unsigned __int16        uint16_t;
32 typedef unsigned __int32        uint32_t;
33
34 #else /* _MSC_VER */
35
36 #include <stdint.h>
37 #include <unistd.h>
38 #include <errno.h>
39 #include <netinet/in.h>
40
41 #endif /* _MSC_VER */
42
43 /**
44  * Establishes a TCP/IP connection to @p host at port @p port.
45  * @param host Hostname to connect to
46  * @param port Port number
47  * @return The file descriptor on success, -1 otherwise
48  */
49 int firmnet_connect_tcp(const char *host, uint16_t port);
50
51 /**
52  * Closes connection established on socket @p fd.
53  * @param fd The file descriptor identifying the connection
54  */
55 void firmnet_close_socket(int fd);
56
57 /**
58  * Send message of size @p n from buffer @p buf to file descriptor @p fd.
59  * @param fd   The file descriptor, the message should be send to.
60  * @param buf  The buffer containing the message
61  * @param n    The length of the message.
62  * @return Number of bytes written or -1 on failure.
63  */
64 ssize_t firmnet_send(int fd, const void *buf, size_t n);
65
66 /**
67  * Try to read some bytes but block until a certain amount is read.
68  * @param fd The file descriptor.
69  * @param buf The buffer to read into.
70  * @param try The amount of bytes to try to read.
71  * @param at_least block until this many bytes are read.
72  * @return The number of bytes read or -1 on error.
73  */
74 ssize_t firmnet_recv(int fd, void *buf, size_t try, size_t at_least);
75
76 #endif /* _FIRMNET_H_ */