- implemented get_irg_value_param_type()
[libfirm] / ir / net / firmnet.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief   Interfaces for TCP/IP handling (Windows and Unix like systems)
23  * @author  Christian Wuerdig, copied from liblpp created by Sebastian Hack
24  * @date    17.11.2006
25  * @version $Id$
26  */
27
28 #ifndef FIRM_NET_FIRMNET_H
29 #define FIRM_NET_FIRMNET_H
30
31 #ifdef _WIN32
32 #include <winsock.h>
33 #include <io.h>
34
35 #else /* _WIN32 */
36 #include <sys/time.h>
37 #include <sys/socket.h>
38 #include <sys/types.h>
39 #include <sys/resource.h>
40 #include <sys/wait.h>
41
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
44 #include <netdb.h>
45
46 #include <unistd.h>
47
48 /* solaris fix */
49 #ifndef INADDR_NONE
50 #define INADDR_NONE (in_addr_t)(-1)
51 #endif
52
53 #endif /* _WIN32 */
54
55 #include <signal.h>
56 #include <errno.h>
57 #include <stdlib.h>
58 #include <stdio.h>
59 #include <string.h>
60
61 #ifdef _MSC_VER
62
63 typedef size_t                          ssize_t;
64 typedef unsigned __int16        uint16_t;
65 typedef unsigned __int32        uint32_t;
66
67 #else /* _MSC_VER */
68
69 #include <stdint.h>
70 #include <unistd.h>
71 #include <errno.h>
72 #include <netinet/in.h>
73
74 #endif /* _MSC_VER */
75
76 /**
77  * Establishes a TCP/IP connection to @p host at port @p port.
78  * @param host Hostname to connect to
79  * @param port Port number
80  * @return The file descriptor on success, -1 otherwise
81  */
82 int firmnet_connect_tcp(const char *host, uint16_t port);
83
84 /**
85  * Closes connection established on socket @p fd.
86  * @param fd The file descriptor identifying the connection
87  */
88 void firmnet_close_socket(int fd);
89
90 /**
91  * Send message of size @p n from buffer @p buf to file descriptor @p fd.
92  * @param fd   The file descriptor, the message should be send to.
93  * @param buf  The buffer containing the message
94  * @param n    The length of the message.
95  * @return Number of bytes written or -1 on failure.
96  */
97 ssize_t firmnet_send(int fd, const void *buf, size_t n);
98
99 /**
100  * Try to read some bytes but block until a certain amount is read.
101  * @param fd The file descriptor.
102  * @param buf The buffer to read into.
103  * @param try The amount of bytes to try to read.
104  * @param at_least block until this many bytes are read.
105  * @return The number of bytes read or -1 on error.
106  */
107 ssize_t firmnet_recv(int fd, void *buf, size_t try, size_t at_least);
108
109 #endif