Embedded WebSockets Experiment

Dependencies:   mbed MD5

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers api_msg.h Source File

api_msg.h

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_MSG_H__
00033 #define __LWIP_API_MSG_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/ip_addr.h"
00042 #include "lwip/err.h"
00043 #include "lwip/sys.h"
00044 #include "lwip/igmp.h"
00045 #include "lwip/api.h"
00046 
00047 #ifdef __cplusplus
00048 extern "C" {
00049 #endif
00050 
00051 /* IP addresses and port numbers are expected to be in
00052  * the same byte order as in the corresponding pcb.
00053  */
00054 /** This struct includes everything that is necessary to execute a function
00055     for a netconn in another thread context (mainly used to process netconns
00056     in the tcpip_thread context to be thread safe). */
00057 struct api_msg_msg {
00058   /** The netconn which to process - always needed: it includes the semaphore
00059       which is used to block the application thread until the function finished. */
00060   struct netconn *conn;
00061   /** Depending on the executed function, one of these union members is used */
00062   union {
00063     /** used for do_send */
00064     struct netbuf *b;
00065     /** used for do_newconn */
00066     struct {
00067       u8_t proto;
00068     } n;
00069     /** used for do_bind and do_connect */
00070     struct {
00071       struct ip_addr *ipaddr;
00072       u16_t port;
00073     } bc;
00074     /** used for do_getaddr */
00075     struct {
00076       struct ip_addr *ipaddr;
00077       u16_t *port;
00078       u8_t local;
00079     } ad;
00080     /** used for do_write */
00081     struct {
00082       const void *dataptr;
00083       size_t len;
00084       u8_t apiflags;
00085     } w;
00086     /** used for do_recv */
00087     struct {
00088       u16_t len;
00089     } r;
00090 #if LWIP_IGMP
00091     /** used for do_join_leave_group */
00092     struct {
00093       struct ip_addr *multiaddr;
00094       struct ip_addr *interface;
00095       enum netconn_igmp join_or_leave;
00096     } jl;
00097 #endif /* LWIP_IGMP */
00098 #if TCP_LISTEN_BACKLOG
00099     struct {
00100       u8_t backlog;
00101     } lb;
00102 #endif /* TCP_LISTEN_BACKLOG */
00103   } msg;
00104 };
00105 
00106 /** This struct contains a function to execute in another thread context and
00107     a struct api_msg_msg that serves as an argument for this function.
00108     This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
00109 struct api_msg {
00110   /** function to execute in tcpip_thread context */
00111   void (* function)(struct api_msg_msg *msg);
00112   /** arguments for this function */
00113   struct api_msg_msg msg;
00114 };
00115 
00116 #if LWIP_DNS
00117 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
00118     it has its own struct (to avoid struct api_msg getting bigger than necessary).
00119     do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
00120     (see netconn_gethostbyname). */
00121 struct dns_api_msg {
00122   /** Hostname to query or dotted IP address string */
00123   const char *name;
00124   /** Rhe resolved address is stored here */
00125   struct ip_addr *addr;
00126   /** This semaphore is posted when the name is resolved, the application thread
00127       should wait on it. */
00128   sys_sem_t sem;
00129   /** Errors are given back here */
00130   err_t *err;
00131 };
00132 #endif /* LWIP_DNS */
00133 
00134 void do_newconn         ( struct api_msg_msg *msg);
00135 void do_delconn         ( struct api_msg_msg *msg);
00136 void do_bind            ( struct api_msg_msg *msg);
00137 void do_connect         ( struct api_msg_msg *msg);
00138 void do_disconnect      ( struct api_msg_msg *msg);
00139 void do_listen          ( struct api_msg_msg *msg);
00140 void do_send            ( struct api_msg_msg *msg);
00141 void do_recv            ( struct api_msg_msg *msg);
00142 void do_write           ( struct api_msg_msg *msg);
00143 void do_getaddr         ( struct api_msg_msg *msg);
00144 void do_close           ( struct api_msg_msg *msg);
00145 #if LWIP_IGMP
00146 void do_join_leave_group( struct api_msg_msg *msg);
00147 #endif /* LWIP_IGMP */
00148 
00149 #if LWIP_DNS
00150 void do_gethostbyname(void *arg);
00151 #endif /* LWIP_DNS */
00152 
00153 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
00154 void netconn_free(struct netconn *conn);
00155 
00156 #ifdef __cplusplus
00157 }
00158 #endif
00159 
00160 #endif /* LWIP_NETCONN */
00161 
00162 #endif /* __LWIP_API_MSG_H__ */