ReactOS 0.4.15-dev-7953-g1f49173
api.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * This file is part of the lwIP TCP/IP stack.
28 *
29 * Author: Adam Dunkels <adam@sics.se>
30 *
31 */
32#ifndef __LWIP_API_H__
33#define __LWIP_API_H__
34
35#include "lwip/opt.h"
36
37#if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
38
39#include <stddef.h> /* for size_t */
40
41#include "lwip/netbuf.h"
42#include "lwip/sys.h"
43#include "lwip/ip_addr.h"
44#include "lwip/err.h"
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50/* Throughout this file, IP addresses and port numbers are expected to be in
51 * the same byte order as in the corresponding pcb.
52 */
53
54/* Flags for netconn_write (u8_t) */
55#define NETCONN_NOFLAG 0x00
56#define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */
57#define NETCONN_COPY 0x01
58#define NETCONN_MORE 0x02
59#define NETCONN_DONTBLOCK 0x04
60
61/* Flags for struct netconn.flags (u8_t) */
65#define NETCONN_FLAG_WRITE_DELAYED 0x01
67#define NETCONN_FLAG_NON_BLOCKING 0x02
69#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04
72#define NETCONN_FLAG_NO_AUTO_RECVED 0x08
75#define NETCONN_FLAG_CHECK_WRITESPACE 0x10
76
77
78/* Helpers to process several netconn_types by the same code */
79#define NETCONNTYPE_GROUP(t) (t&0xF0)
80#define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
81
83enum netconn_type {
84 NETCONN_INVALID = 0,
85 /* NETCONN_TCP Group */
86 NETCONN_TCP = 0x10,
87 /* NETCONN_UDP Group */
88 NETCONN_UDP = 0x20,
89 NETCONN_UDPLITE = 0x21,
90 NETCONN_UDPNOCHKSUM= 0x22,
91 /* NETCONN_RAW Group */
92 NETCONN_RAW = 0x40
93};
94
97enum netconn_state {
98 NETCONN_NONE,
99 NETCONN_WRITE,
100 NETCONN_LISTEN,
101 NETCONN_CONNECT,
102 NETCONN_CLOSE
103};
104
106enum netconn_evt {
107 NETCONN_EVT_RCVPLUS,
108 NETCONN_EVT_RCVMINUS,
109 NETCONN_EVT_SENDPLUS,
110 NETCONN_EVT_SENDMINUS,
111 NETCONN_EVT_ERROR
112};
113
114#if LWIP_IGMP
116enum netconn_igmp {
117 NETCONN_JOIN,
118 NETCONN_LEAVE
119};
120#endif /* LWIP_IGMP */
121
122/* forward-declare some structs to avoid to include their headers */
123struct ip_pcb;
124struct tcp_pcb;
125struct udp_pcb;
126struct raw_pcb;
127struct netconn;
128struct api_msg_msg;
129
131typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
132
134struct netconn {
136 enum netconn_type type;
138 enum netconn_state state;
140 union {
141 struct ip_pcb *ip;
142 struct tcp_pcb *tcp;
143 struct udp_pcb *udp;
144 struct raw_pcb *raw;
145 } pcb;
147 err_t last_err;
149 sys_sem_t op_completed;
152 sys_mbox_t recvmbox;
153#if LWIP_TCP
156 sys_mbox_t acceptmbox;
157#endif /* LWIP_TCP */
159#if LWIP_SOCKET
160 int socket;
161#endif /* LWIP_SOCKET */
162#if LWIP_SO_SNDTIMEO
165 s32_t send_timeout;
166#endif /* LWIP_SO_RCVTIMEO */
167#if LWIP_SO_RCVTIMEO
170 int recv_timeout;
171#endif /* LWIP_SO_RCVTIMEO */
172#if LWIP_SO_RCVBUF
175 int recv_bufsize;
179 s16_t recv_avail;
180#endif /* LWIP_SO_RCVBUF */
182 u8_t flags;
183#if LWIP_TCP
186 size_t write_offset;
190 struct api_msg_msg *current_msg;
191#endif /* LWIP_TCP */
193 netconn_callback callback;
194};
195
197#define API_EVENT(c,e,l) if (c->callback) { \
198 (*c->callback)(c, e, l); \
199 }
200
202#define NETCONN_SET_SAFE_ERR(conn, err) do { \
203 SYS_ARCH_DECL_PROTECT(lev); \
204 SYS_ARCH_PROTECT(lev); \
205 if (!ERR_IS_FATAL((conn)->last_err)) { \
206 (conn)->last_err = err; \
207 } \
208 SYS_ARCH_UNPROTECT(lev); \
209} while(0);
210
211/* Network connection functions: */
212#define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
213#define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
214struct
215netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
216 netconn_callback callback);
217err_t netconn_delete(struct netconn *conn);
219#define netconn_type(conn) (conn->type)
220
221err_t netconn_getaddr(struct netconn *conn, ip_addr_t *addr,
222 u16_t *port, u8_t local);
223#define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
224#define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
225
226err_t netconn_bind(struct netconn *conn, ip_addr_t *addr, u16_t port);
227err_t netconn_connect(struct netconn *conn, ip_addr_t *addr, u16_t port);
228err_t netconn_disconnect (struct netconn *conn);
229err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
230#define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
231err_t netconn_accept(struct netconn *conn, struct netconn **new_conn);
232err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf);
233err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf);
234void netconn_recved(struct netconn *conn, u32_t length);
235err_t netconn_sendto(struct netconn *conn, struct netbuf *buf,
237err_t netconn_send(struct netconn *conn, struct netbuf *buf);
238err_t netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size,
239 u8_t apiflags, size_t *bytes_written);
240#define netconn_write(conn, dataptr, size, apiflags) \
241 netconn_write_partly(conn, dataptr, size, apiflags, NULL)
242err_t netconn_close(struct netconn *conn);
243err_t netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx);
244
245#if LWIP_IGMP
246err_t netconn_join_leave_group(struct netconn *conn, ip_addr_t *multiaddr,
247 ip_addr_t *netif_addr, enum netconn_igmp join_or_leave);
248#endif /* LWIP_IGMP */
249#if LWIP_DNS
250err_t netconn_gethostbyname(const char *name, ip_addr_t *addr);
251#endif /* LWIP_DNS */
252
253#define netconn_err(conn) ((conn)->last_err)
254#define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
255
257#define netconn_set_nonblocking(conn, val) do { if(val) { \
258 (conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
259} else { \
260 (conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
262#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
263
265#define netconn_set_noautorecved(conn, val) do { if(val) { \
266 (conn)->flags |= NETCONN_FLAG_NO_AUTO_RECVED; \
267} else { \
268 (conn)->flags &= ~ NETCONN_FLAG_NO_AUTO_RECVED; }} while(0)
270#define netconn_get_noautorecved(conn) (((conn)->flags & NETCONN_FLAG_NO_AUTO_RECVED) != 0)
271
272#if LWIP_SO_SNDTIMEO
274#define netconn_set_sendtimeout(conn, timeout) ((conn)->send_timeout = (timeout))
276#define netconn_get_sendtimeout(conn) ((conn)->send_timeout)
277#endif /* LWIP_SO_SNDTIMEO */
278#if LWIP_SO_RCVTIMEO
280#define netconn_set_recvtimeout(conn, timeout) ((conn)->recv_timeout = (timeout))
282#define netconn_get_recvtimeout(conn) ((conn)->recv_timeout)
283#endif /* LWIP_SO_RCVTIMEO */
284#if LWIP_SO_RCVBUF
286#define netconn_set_recvbufsize(conn, recvbufsize) ((conn)->recv_bufsize = (recvbufsize))
288#define netconn_get_recvbufsize(conn) ((conn)->recv_bufsize)
289#endif /* LWIP_SO_RCVBUF*/
290
291#ifdef __cplusplus
292}
293#endif
294
295#endif /* LWIP_NETCONN */
296
297#endif /* __LWIP_API_H__ */
static int state
Definition: maze.c:121
USHORT port
Definition: uri.c:228
void netconn_close(struct netconn *conn)
Definition: net.c:250
BOOL netconn_recv(struct netconn *conn, void *buf, size_t len, int flags, int *recvd)
Definition: net.c:539
BOOL netconn_send(struct netconn *conn, const void *msg, size_t len, int *sent)
Definition: net.c:424
signed short s16_t
Definition: cc.h:29
signed long s32_t
Definition: cc.h:30
unsigned long u32_t
Definition: cc.h:25
unsigned char u8_t
Definition: cc.h:23
unsigned short u16_t
Definition: cc.h:24
s8_t err_t
Definition: err.h:47
#define local
Definition: zutil.h:30
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble GLdouble t
Definition: gl.h:2047
GLsizeiptr size
Definition: glext.h:5919
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
Definition: ip_addr.h:64
int const JOCTET * dataptr
Definition: jpeglib.h:1031
static IPrintDialogCallback callback
Definition: printdlg.c:326
Definition: ip.h:89
Definition: dhcpd.h:62
Definition: name.c:39
Definition: types.h:144
Definition: pbuf.h:79