[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] lwip_accept acceptmbox is NULL
From: |
Emmanuel Baguia Jr. |
Subject: |
[lwip-users] lwip_accept acceptmbox is NULL |
Date: |
Tue, 7 Oct 2008 02:44:15 -0700 (PDT) |
Hello! Good day! I recently use lwIP (port for win32) and found it useful for our project. But somehow, I needed some light. I have create a simple client/server application in which I use the APIs being introduced in lwip/sockets.h. Here are some code snippets from my server application:
s = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
/* bind any port number */
memset(&localAddr, 0, sizeof(localAddr));
localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = INADDR_ANY;
localAddr.sin_port = htons(LOCAL_PORT);
error = bind(s, (struct sockaddr *) &localAddr, sizeof(localAddr));
if(error<0)
{
printf("ERROR: cannot bind port TCP %u\n",LOCAL_PORT);
}
error = listen(s, 10);
if( error == -1 )
{
return 1;
}
else
{
while( 1 )
{
if( accept( s, (struct sockaddr *) &localAddr, (u32_t *) &addr_len ) == -1 )
{
return 1;
}
}
}
My problem here is that the acceptmbox value is NULL inside the accept()
function which will prompt to "invalid acceptmbox" assertion message. I have read some discussions that the acceptmbox is initialized in the lwip_listen() function which will eventually call the netconn_listen function. The same issue I got when using the APIs from the lwip/api.h. Here are some code snippets using the APIs:
struct netconn *conn, *newconn;
conn = netconn_new(NETCONN_TCP);
printf("http_test: socket created !\n");
netconn_bind(conn, NULL, 8084);
printf("http_test: socket binded !\n");
netconn_listen(conn);
printf("http_test: socket listen !\n");
// Where I placed the acceptmbox initialization
while( 1 )
{
newconn = netconn_accept(conn);
printf("http_test: socket accept !\n");
}
netconn_close(conn);
Until I noticed that I needed to initialize the acceptmbox if it is null after calling netconn_listen and before calling the netconn_accept.
if( conn->acceptmbox == NULL )
{
conn->acceptmbox = sys_mbox_new(DEFAULT_ACCEPTMBOX_SIZE);
}
Then everything worked! :) Is there a way to do this in the lwip/socket.h? Or maybe I just missed something?
Thank you very much.
Emmanuel
- [lwip-users] lwip_accept acceptmbox is NULL,
Emmanuel Baguia Jr. <=