我这里采用cubemx生成的lwip工程
在调用netconn_write的时候, 第二个参数字符串数组如果传入的是static const char类型, 就会造成该函数阻塞, 暂时没定位到阻塞点
但是如果改为char类型, 就不会造成阻塞
代码如下, 希望大佬指教
[C] 纯文本查看 复制代码 char http_html_hdr[] =
"HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";
char http_index_html[] =
"<html><head><title>Congrats!</title></head>\
<body><h1 align=\"center\">Hello World!</h1>\
<h2 align=\"center\">Welcome to Fire lwIP HTTP Server!</h1>\
<p align=\"center\">This is a small test page, served by httpserver-netconn.</p>\
<p align=\"center\"><a href=\"http://www.firebbs.cn/forum.php/\">\
<font size=\"6\"> 野火电子论坛 </font> </a></p>\
<a href=\"http://www.firebbs.cn/forum.php/\">\
<p align=\"center\"><img src=\"http://www.firebbs.cn/data/attachment/portal/\
201806/05/163015rhz7mbgbt0zfujzh.jpg\" /></a>\
</body></html>";
uint8_t send_buf[]= "This is a TCP Client test...\n";
/** Serve one HTTP connection accepted in the http thread */
static void
http_server_netconn_serve(struct netconn *conn)
{
struct netbuf *inbuf;
char *buf;
u16_t buflen;
err_t err;
/* 读取数据 */
err = netconn_recv(conn, &inbuf);
if (err == ERR_OK)
{
netbuf_data(inbuf, (void**)&buf, &buflen);
/* 判断是不是HTTP的GET命令*/
if (buflen>=5 &&
buf[0]=='G' &&
buf[1]=='E' &&
buf[2]=='T' &&
buf[3]==' ' &&
buf[4]=='/' )
{
// netconn_write(conn,send_buf,sizeof(send_buf),0);
/* 发送数据头 */
netconn_write(conn, http_html_hdr,
sizeof(http_html_hdr)-1, NETCONN_NOCOPY);
// /* 发送网页数据 */
netconn_write(conn, http_index_html,
sizeof(http_index_html)-1, NETCONN_NOCOPY);
}
}
netconn_close(conn); /* 关闭连接 */
/* 释放inbuf */
netbuf_delete(inbuf);
}
|