2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Interfaces for TCP/IP handling (Windows and Unix like systems)
23 * @author Christian Wuerdig, copied from liblpp created by Sebastian Hack
28 #ifndef FIRM_NET_FIRMNET_H
29 #define FIRM_NET_FIRMNET_H
37 #include <sys/socket.h>
38 #include <sys/types.h>
39 #include <sys/resource.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
57 typedef size_t ssize_t;
58 typedef unsigned __int16 uint16_t;
59 typedef unsigned __int32 uint32_t;
66 #include <netinet/in.h>
71 * Establishes a TCP/IP connection to @p host at port @p port.
72 * @param host Hostname to connect to
73 * @param port Port number
74 * @return The file descriptor on success, -1 otherwise
76 int firmnet_connect_tcp(const char *host, uint16_t port);
79 * Closes connection established on socket @p fd.
80 * @param fd The file descriptor identifying the connection
82 void firmnet_close_socket(int fd);
85 * Send message of size @p n from buffer @p buf to file descriptor @p fd.
86 * @param fd The file descriptor, the message should be send to.
87 * @param buf The buffer containing the message
88 * @param n The length of the message.
89 * @return Number of bytes written or -1 on failure.
91 ssize_t firmnet_send(int fd, const void *buf, size_t n);
94 * Try to read some bytes but block until a certain amount is read.
95 * @param fd The file descriptor.
96 * @param buf The buffer to read into.
97 * @param try The amount of bytes to try to read.
98 * @param at_least block until this many bytes are read.
99 * @return The number of bytes read or -1 on error.
101 ssize_t firmnet_recv(int fd, void *buf, size_t try, size_t at_least);