[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] DHCP server offer timing
From: |
kuwa |
Subject: |
Re: [lwip-users] DHCP server offer timing |
Date: |
Thu, 18 Mar 2004 14:09:30 +0900 (LMT) |
Hi, Leon and everyone,
From: address@hidden
Subject: Re: [lwip-users] DHCP server offer timing
Date: Sat, 13 Mar 2004 11:57:00 +0900 (LMT)
> For now, I am wondering how / where should I call dhcp_start()...
> Should it be called within TCP/IP task? (same context as TCP/IP context?)
> Should also DHPC timers are called within TCP/IP task?
Based on my assumption:
dhcp_start() and DHCP timers should be called
inside the tcpip_thread() for mutli-threaded environment
I try to make DHCP start API which is for calling dhcp_start() inside
tcpip_thread() context.
This seems to solve my problem of multi-threaded safety, however I
don't think this is smart way and code. So I send this as FYI.
I cannot simply create diffs because in my system lwIP is fairly
modified and currently not arranged. Sorry for incovenience.
Add new file src/api/api_dhcp.c:
This is an API function.
Application thread just calls this function same as dhcp_start().
-----------------------------------------------------
#include "lwip/opt.h"
#if defined(LWIP_DHCP) && defined(DHCP_USE_API)
#include "lwip/api.h"
#include "lwip/api_msg.h"
#include "lwip/api_dhcp.h"
#include "lwip/memp.h"
err_t
api_dhcp_start(struct netif *netif)
{
struct netconn *conn;
struct api_msg *msg;
err_t err = ERR_OK;
if (netif == NULL) {
return ERR_ARG;
}
conn = memp_malloc(MEMP_NETCONN);
if (conn == NULL) {
return ERR_MEM;
}
conn->err = ERR_OK;
if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) {
memp_free(MEMP_NETCONN, conn);
return ERR_MEM;
}
if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) {
memp_free(MEMP_NETCONN, conn);
return ERR_MEM;
}
msg->type = API_MSG_START_DHCP; /* Start DHCP */
msg->msg.conn = conn;
msg->msg.msg.w.dataptr = netif;
api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL);
memp_free(MEMP_API_MSG, msg);
err = conn->err;
memp_free(MEMP_NETCONN, conn);
return err;
}
#endif
-----------------------------------------------------
Add new file src/include/lwip/api_dhcp.h:
-----------------------------------------------------
#ifndef __LWIP_API_DHCP_H__
#define __LWIP_API_DHCP_H__
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/netif.h"
#include "lwip/err.h"
#if defined(LWIP_DHCP) && defined(DHCP_USE_API)
err_t api_dhcp_start(struct netif *netif);
#endif
#endif /* __LWIP_API_DHCP_H__ */
-----------------------------------------------------
Add do_dhcp_start() in src/api/api_msg.c:
This function registers two DHCP timers and calls dhcp_start() inside
tcpip_thread().
-----------------------------------------------------
#if defined(LWIP_DHCP) && defined(DHCP_USE_API)
static void
dhcp_fine_timer(void *arg)
{
dhcp_fine_tmr();
sys_timeout(DHCP_FINE_TIMER_MSECS,
(sys_timeout_handler)dhcp_fine_timer, NULL);
}
static void
dhcp_coarse_timer(void *arg)
{
dhcp_coarse_tmr();
sys_timeout((u32_t)DHCP_COARSE_TIMER_SECS * 1000,
(sys_timeout_handler)dhcp_coarse_timer, NULL);
}
static void
do_dhcp_start(struct api_msg_msg *msg)
{
extern err_t dhcp_start(struct netif *);
sys_timeout(DHCP_FINE_TIMER_MSECS,
(sys_timeout_handler)dhcp_fine_timer, NULL);
sys_timeout((u32_t)DHCP_COARSE_TIMER_SECS * 1000,
(sys_timeout_handler)dhcp_coarse_timer, NULL);
msg->conn->err = dhcp_start((struct netif *)msg->msg.w.dataptr);
sys_mbox_post(msg->conn->mbox, NULL);
}
#endif /* defined(LWIP_DHCP) && defined(DHCP_USE_API) */
-----------------------------------------------------
Registers the above do_dhcp_start() to api_msg_decode table in
src/api/api_msg.c.
-----------------------------------------------------
typedef void (* api_msg_decode)(struct api_msg_msg *msg);
static api_msg_decode decode[API_MSG_MAX] = {
do_newconn,
do_delconn,
do_bind,
do_connect,
do_disconnect,
do_listen,
do_accept,
do_send,
do_recv,
do_write,
do_close
#if defined(LWIP_DHCP) && defined(DHCP_USE_API)
,
do_dhcp_start
#endif
};
-----------------------------------------------------
Registers new api message type "API_MSG_START_DHCP" in
src/include/lwip/api_msg.h:
-----------------------------------------------------
enum api_msg_type {
API_MSG_NEWCONN,
API_MSG_DELCONN,
API_MSG_BIND,
API_MSG_CONNECT,
API_MSG_DISCONNECT,
API_MSG_LISTEN,
API_MSG_ACCEPT,
API_MSG_SEND,
API_MSG_RECV,
API_MSG_WRITE,
API_MSG_CLOSE,
#if defined(LWIP_DHCP) && defined(DHCP_USE_API)
API_MSG_START_DHCP,
#endif
API_MSG_MAX
};
-----------------------------------------------------
--
Shuji KUWAHARA