[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] Writing a proxy server - how "non-reentrant" is lwip raw AP

From: wurzel
Subject: [lwip-users] Writing a proxy server - how "non-reentrant" is lwip raw API?
Date: Tue, 14 Jun 2011 17:13:11 -0700

I'm using raw API to write a TCP proxy server.  For now,
I simply want it to forward all data bidirectionally
(for performance checking).

I've read some of the discussions about lwip and reentrancy
but they seemed to refer more to what I would call MT-safe
(multi-thread safe) or rather, not-safe.

My question is, can I call tcp_write from within a tcp_recv
callback?  In this code, I've opened a pair of TCP pcbs and
each one's state struct has a "mate" field that points to
the other side's state struct to I can get its pcb.

static err_t my_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
        struct my_state_st *rs = (struct my_state_st *) arg;
        err_t   snderr;
        struct pbuf *q;

        if (p == NULL) {
                // Close connection <snip>

        if (p->tot_len != 0) {
                for (q = p; q != NULL; q = q->next) {
                        // Write data to the other TCP connection
                        snderr = tcp_write(rs->mate->mypcb, q->payload, q->len, 

                        if (snderr != ERR_OK) {
                                // Print error message
                        } else {
                                // force buffer flush for lowest possible 

                tcp_recved(pcb, p->tot_len);

        return ERR_OK;

By the strictest definition of "non-reentrant" this might not be 
legal.  On the other hand, this seems like a commonly-desired case,
so I'm hoping it is expected to work?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]