ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

api.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 #ifndef __LWIP_API_H__
00033 #define __LWIP_API_H__
00034 
00035 #include "lwip/opt.h"
00036 
00037 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
00038 
00039 #include <stddef.h> /* for size_t */
00040 
00041 #include "lwip/netbuf.h"
00042 #include "lwip/sys.h"
00043 #include "lwip/ip_addr.h"
00044 #include "lwip/err.h"
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 /* Throughout this file, IP addresses and port numbers are expected to be in
00051  * the same byte order as in the corresponding pcb.
00052  */
00053 
00054 /* Flags for netconn_write (u8_t) */
00055 #define NETCONN_NOFLAG    0x00
00056 #define NETCONN_NOCOPY    0x00 /* Only for source code compatibility */
00057 #define NETCONN_COPY      0x01
00058 #define NETCONN_MORE      0x02
00059 #define NETCONN_DONTBLOCK 0x04
00060 
00061 /* Flags for struct netconn.flags (u8_t) */
00065 #define NETCONN_FLAG_WRITE_DELAYED            0x01
00066 
00067 #define NETCONN_FLAG_NON_BLOCKING             0x02
00068 
00069 #define NETCONN_FLAG_IN_NONBLOCKING_CONNECT   0x04
00070 
00072 #define NETCONN_FLAG_NO_AUTO_RECVED           0x08
00073 
00075 #define NETCONN_FLAG_CHECK_WRITESPACE         0x10
00076 
00077 
00078 /* Helpers to process several netconn_types by the same code */
00079 #define NETCONNTYPE_GROUP(t)    (t&0xF0)
00080 #define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
00081 
00083 enum netconn_type {
00084   NETCONN_INVALID    = 0,
00085   /* NETCONN_TCP Group */
00086   NETCONN_TCP        = 0x10,
00087   /* NETCONN_UDP Group */
00088   NETCONN_UDP        = 0x20,
00089   NETCONN_UDPLITE    = 0x21,
00090   NETCONN_UDPNOCHKSUM= 0x22,
00091   /* NETCONN_RAW Group */
00092   NETCONN_RAW        = 0x40
00093 };
00094 
00097 enum netconn_state {
00098   NETCONN_NONE,
00099   NETCONN_WRITE,
00100   NETCONN_LISTEN,
00101   NETCONN_CONNECT,
00102   NETCONN_CLOSE
00103 };
00104 
00106 enum netconn_evt {
00107   NETCONN_EVT_RCVPLUS,
00108   NETCONN_EVT_RCVMINUS,
00109   NETCONN_EVT_SENDPLUS,
00110   NETCONN_EVT_SENDMINUS,
00111   NETCONN_EVT_ERROR
00112 };
00113 
00114 #if LWIP_IGMP
00115 
00116 enum netconn_igmp {
00117   NETCONN_JOIN,
00118   NETCONN_LEAVE
00119 };
00120 #endif /* LWIP_IGMP */
00121 
00122 /* forward-declare some structs to avoid to include their headers */
00123 struct ip_pcb;
00124 struct tcp_pcb;
00125 struct udp_pcb;
00126 struct raw_pcb;
00127 struct netconn;
00128 struct api_msg_msg;
00129 
00131 typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
00132 
00134 struct netconn {
00136   enum netconn_type type;
00138   enum netconn_state state;
00140   union {
00141     struct ip_pcb  *ip;
00142     struct tcp_pcb *tcp;
00143     struct udp_pcb *udp;
00144     struct raw_pcb *raw;
00145   } pcb;
00147   err_t last_err;
00149   sys_sem_t op_completed;
00152   sys_mbox_t recvmbox;
00153 #if LWIP_TCP
00154 
00156   sys_mbox_t acceptmbox;
00157 #endif /* LWIP_TCP */
00158 
00159 #if LWIP_SOCKET
00160   int socket;
00161 #endif /* LWIP_SOCKET */
00162 #if LWIP_SO_RCVTIMEO
00163 
00165   int recv_timeout;
00166 #endif /* LWIP_SO_RCVTIMEO */
00167 #if LWIP_SO_RCVBUF
00168 
00170   int recv_bufsize;
00174   s16_t recv_avail;
00175 #endif /* LWIP_SO_RCVBUF */
00176 
00177   u8_t flags;
00178 #if LWIP_TCP
00179 
00181   size_t write_offset;
00185   struct api_msg_msg *current_msg;
00186 #endif /* LWIP_TCP */
00187 
00188   netconn_callback callback;
00189 };
00190 
00192 #define API_EVENT(c,e,l) if (c->callback) {         \
00193                            (*c->callback)(c, e, l); \
00194                          }
00195 
00197 #define NETCONN_SET_SAFE_ERR(conn, err) do { \
00198   SYS_ARCH_DECL_PROTECT(lev); \
00199   SYS_ARCH_PROTECT(lev); \
00200   if (!ERR_IS_FATAL((conn)->last_err)) { \
00201     (conn)->last_err = err; \
00202   } \
00203   SYS_ARCH_UNPROTECT(lev); \
00204 } while(0);
00205 
00206 /* Network connection functions: */
00207 #define netconn_new(t)                  netconn_new_with_proto_and_callback(t, 0, NULL)
00208 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
00209 struct
00210 netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
00211                                              netconn_callback callback);
00212 err_t   netconn_delete(struct netconn *conn);
00214 #define netconn_type(conn) (conn->type)
00215 
00216 err_t   netconn_getaddr(struct netconn *conn, ip_addr_t *addr,
00217                         u16_t *port, u8_t local);
00218 #define netconn_peer(c,i,p) netconn_getaddr(c,i,p,0)
00219 #define netconn_addr(c,i,p) netconn_getaddr(c,i,p,1)
00220 
00221 err_t   netconn_bind(struct netconn *conn, ip_addr_t *addr, u16_t port);
00222 err_t   netconn_connect(struct netconn *conn, ip_addr_t *addr, u16_t port);
00223 err_t   netconn_disconnect (struct netconn *conn);
00224 err_t   netconn_listen_with_backlog(struct netconn *conn, u8_t backlog);
00225 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG)
00226 err_t   netconn_accept(struct netconn *conn, struct netconn **new_conn);
00227 err_t   netconn_recv(struct netconn *conn, struct netbuf **new_buf);
00228 err_t   netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf);
00229 void    netconn_recved(struct netconn *conn, u32_t length);
00230 err_t   netconn_sendto(struct netconn *conn, struct netbuf *buf,
00231                        ip_addr_t *addr, u16_t port);
00232 err_t   netconn_send(struct netconn *conn, struct netbuf *buf);
00233 err_t   netconn_write(struct netconn *conn, const void *dataptr, size_t size,
00234                       u8_t apiflags);
00235 err_t   netconn_close(struct netconn *conn);
00236 err_t   netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx);
00237 
00238 #if LWIP_IGMP
00239 err_t   netconn_join_leave_group(struct netconn *conn, ip_addr_t *multiaddr,
00240                                  ip_addr_t *netif_addr, enum netconn_igmp join_or_leave);
00241 #endif /* LWIP_IGMP */
00242 #if LWIP_DNS
00243 err_t   netconn_gethostbyname(const char *name, ip_addr_t *addr);
00244 #endif /* LWIP_DNS */
00245 
00246 #define netconn_err(conn)               ((conn)->last_err)
00247 #define netconn_recv_bufsize(conn)      ((conn)->recv_bufsize)
00248 
00250 #define netconn_set_nonblocking(conn, val)  do { if(val) { \
00251   (conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \
00252 } else { \
00253   (conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0)
00254 
00255 #define netconn_is_nonblocking(conn)        (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0)
00256 
00258 #define netconn_set_noautorecved(conn, val)  do { if(val) { \
00259   (conn)->flags |= NETCONN_FLAG_NO_AUTO_RECVED; \
00260 } else { \
00261   (conn)->flags &= ~ NETCONN_FLAG_NO_AUTO_RECVED; }} while(0)
00262 
00263 #define netconn_get_noautorecved(conn)        (((conn)->flags & NETCONN_FLAG_NO_AUTO_RECVED) != 0)
00264 
00265 #if LWIP_SO_RCVTIMEO
00266 
00267 #define netconn_set_recvtimeout(conn, timeout)      ((conn)->recv_timeout = (timeout))
00268 
00269 #define netconn_get_recvtimeout(conn)               ((conn)->recv_timeout)
00270 #endif /* LWIP_SO_RCVTIMEO */
00271 #if LWIP_SO_RCVBUF
00272 
00273 #define netconn_set_recvbufsize(conn, recvbufsize)  ((conn)->recv_bufsize = (recvbufsize))
00274 
00275 #define netconn_get_recvbufsize(conn)               ((conn)->recv_bufsize)
00276 #endif /* LWIP_SO_RCVBUF*/
00277 
00278 #ifdef __cplusplus
00279 }
00280 #endif
00281 
00282 #endif /* LWIP_NETCONN */
00283 
00284 #endif /* __LWIP_API_H__ */

Generated on Sat May 26 2012 04:32:07 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.