[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] tcp_write() problem from outside callbacks functions
From: |
Yann Suisini |
Subject: |
Re: [lwip-users] tcp_write() problem from outside callbacks functions |
Date: |
Thu, 5 Apr 2007 07:01:22 -0700 (PDT) |
the facts say that you're probably right . (the tcp state in the calback just
before tcp_write is ESTABLISHED , and in the main loop is LISTEN) . But I
really don't know where is the trouble . All is passed by reference with the
same tcp_pcb (tcpweb).
I put the other interesting part of the code here :
(in the receive callback , just in order to test i send data on a '+'
trigger)
Here the connection initialization part:
tcpweb = tcp_new();
if (tcpweb == NULL) debug_printf("Creation error\r\n");
if (tcp_bind(tcpweb, IP_ADDR_ANY, 80) != ERR_OK) debug_printf("Bind
Error\r\n");
tcpweb_listen = tcp_listen(tcpweb);
if (tcpweb_listen == NULL)
{
tcp_abort(tcpweb);
tcpweb = NULL;
}
else
{
tcpweb = tcpweb_listen;
tcp_accept(tcpweb, http_accept_callback);
}
and the callback functions :
err_t http_recv_callback(void *arg, struct tcp_pcb *tpcb, struct pbuf *p,
err_t err)
{
char* rq;
if (p != NULL)
{
rq = p->payload;
if (rq[0] == '+')
{
u32_t bytestosend;
u32_t* newarg;
bytestosend = sizeof(webpage);
newarg = (u32_t*) mem_malloc(sizeof(u32_t));
*newarg = bytestosend;
debug_printf("tcp state:%d\r\n",tpcb->state);
if (tcp_write(tpcb, webpage, sizeof(webpage), 0) !=
ERR_OK)
{
mem_free(newarg);
tcp_close(tpcb);
}
else
{
tcp_arg(tpcb, newarg);
mem_free(newarg);
}
}
tcp_recved(tpcb, p->len);
pbuf_free(p);
}
err_t http_poll_callback(void *arg, struct tcp_pcb *tpcb)
{
if (arg != NULL)
{
u32_t bytestosend = *((u32_t*) arg);
if (bytestosend == 0)
{
mem_free(arg);
tcp_arg(tpcb, NULL);
tcp_close(tpcb);
debug_printf("Closing connection");
}
}
return ERR_OK;
}
err_t http_send_callback(void *arg, struct tcp_pcb *tpcb, u16_t len)
{
u32_t bytestosend;
if (arg != NULL)
{
bytestosend = *((u32_t*) arg);
if ((bytestosend - len) >= 0)
bytestosend -= len;
else
bytestosend = 0;
*((u32_t*) arg) = bytestosend;
}
return ERR_OK;
}
err_t http_accept_callback(void *arg, struct tcp_pcb *newpcb, err_t err)
{
tcp_arg(newpcb, NULL);
tcp_recv(newpcb, http_recv_callback);
tcp_sent(newpcb, http_send_callback);
tcp_poll(newpcb, http_poll_callback, 1);
return ERR_OK;
}
--
View this message in context:
http://www.nabble.com/tcp_write%28%29-problem-from-outside-callbacks-functions-tf3530647.html#a9856382
Sent from the lwip-users mailing list archive at Nabble.com.