Hi all:
I'm porting lwIP 1.3 on uCOSII 2.86 that is running BF531
Profitting from other's help, I have made PING work in the port. Now, I want to use the httpserver-netconn as a demo to verify my port,but it can't work. The httpserver program is from "contrib-1.3.0\contrib\apps\httpserver", here post the code for convenience:
void http_server_serve(struct netconn *conn)
{
struct netbuf *inbuf;
char *buf;
u16_t buflen;
//get input
inbuf = netconn_recv(conn);
if (netconn_err(conn) == ERR_OK)
netbuf_data(inbuf, &buf, &buflen);
//send http reply
if ((buflen >= 5) && (buf[0] == 'G') && (buf[0] == 'E') && (buf[0] == 'T') && (buf[0] == ' ') && (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);
}
//close accept conn
netconn_close(conn);
//del inbuf returned from netconn_recv
netbuf_delete(inbuf);
}
int http_server()
{
struct netconn *listen_conn, *accept_conn;
//creat listen conn
listen_conn = netconn_new(NETCONN_TCP);
//bind IP & PORT
netconn_bind(listen_conn, NULL, 80);
//set listen_conn into LISTIEN state
netconn_listen(listen_conn);
while (1)
{
accept_conn = netconn_accept(listen_conn);
http_server_serve(accept_conn);
netconn_delete(accept_conn);
}
return 0;
}
When I sent a http request using TELNET program in my pc, the netconn_accept() returned, and I had noticed SYN/SYN+ACK/ACK packages in Ethereal, I think that meas the TCP connection(accept_conn) have established.
But when I stepped into netconn_recv() in http_server_serve() fun, I found the conn->state is equal to zero, namely NETCONN_NONE. Finally, netconn_recv() return a null pointer, and the port is crashed.
Here, Is something wrong? Since the connection had been established , should state field of the connection be NETCONN_CONNECT , not be NETCONN_NONE ? From Ethereal's output, the connection have closed, which proved by debugging into following if-block in netconn_recv() fun:
if (p == NULL) {
memp_free(MEMP_NETBUF, buf);
/* Avoid to lose any previous error code */
if (conn->err == ERR_OK) {
conn->err = ERR_CLSD;
}
return NULL;
}
Can someone help me? Any suggestion is well appreciated.