金牌会员
 
- 积分
- 1341
- 金钱
- 1341
- 注册时间
- 2016-4-22
- 在线时间
- 187 小时
|
发表于 2016-9-28 17:50:56
|
显示全部楼层
初始化你看战舰V3的demo就行了,没几行代码。
/**
* A new incoming connection has been accepted.
*/
//ò»¸öDÂμĽøà′μÄᬽ󱻽¨á¢
static err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
struct http_state *hs;
struct tcp_pcb_listen *lpcb = (struct tcp_pcb_listen*)arg;
LWIP_UNUSED_ARG(err);
LWIP_DEBUGF(HTTPD_DEBUG, ("http_accept %p / %p\r\n", (void*)pcb, arg));
//printf("%d, %d\r\n", pcb->remote_port,pcb->remote_ip.addr);
/* Decrease the listen backlog counter */
tcp_accepted(lpcb); //¼õD¡¼àìyàۼƼÆêyÆ÷
/* Set priority */
tcp_setprio(pcb, HTTPD_TCP_PRIO);//éèÖÃóÅÏè¼¶
/* Allocate memory for the structure that holds the state of the
connection - initialized by that function. */
hs = http_state_alloc(); //éêÇëÄú′æ
if (hs == NULL) { //Äú′æéêÇëê§°ü
LWIP_DEBUGF(HTTPD_DEBUG, ("http_accept: Out of memory, RST\r\n"));
return ERR_MEM;
}
/* Tell TCP that this is the structure we wish to be passed for our callbacks.*/
tcp_arg(pcb, hs); //í¨ÖaTCP hsÕa¸ö½á11ìåÔú»Øμ÷ÖDêÇÎòÃÇÏ£íû±»′«μYμÄ
/* Set up the various callback functions */
tcp_recv(pcb, http_recv); //×¢2átcp_recvμÄ»Øμ÷oˉêy
tcp_err(pcb, http_err); //×¢2átcp_errμÄ»Øμ÷oˉêy
tcp_poll(pcb, http_poll, HTTPD_POLL_INTERVAL); //×¢2átcp_pollμÄ»Øμ÷oˉêy
tcp_sent(pcb, http_sent); //×¢2átcp_sentμÄ»Øμ÷oˉêy
return ERR_OK;
}
/**
* Initialize the httpd with the specified local address.
*/
//ê1óÃÖ¸¶¨μı¾μØμØÖ·3õê¼»ˉhttpdμØÖ·
static void httpd_init_addr(struct ip_addr *local_addr)
{
struct tcp_pcb *pcb;
err_t err;
pcb = tcp_new(); //′′½¨pcb¿ØÖÆ¿é
LWIP_ASSERT("httpd_init: tcp_new failed", pcb != NULL);
tcp_setprio(pcb, HTTPD_TCP_PRIO); //éèÖÃpcbóÅÏè¼¶
/* set SOF_REUSEADDR here to explicitly bind httpd to multiple interfaces */
err = tcp_bind(pcb, local_addr, HTTPD_SERVER_PORT); //°ó¶¨±¾μØμØÖ·óë¶Ë¿úoÅ
LWIP_ASSERT("httpd_init: tcp_bind failed", err == ERR_OK);
pcb = tcp_listen(pcb); //éèÖÃpcb½øèë¼àìy
LWIP_ASSERT("httpd_init: tcp_listen failed", pcb != NULL);
/* initialize callback arg and accept callback */
tcp_arg(pcb, pcb);
tcp_accept(pcb, http_accept); //éèÖÃtcp_acceptμÄ»Øμ÷oˉêy
} |
|