lwip-users
[Top][All Lists]
Advanced

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

Re: [lwip-users] lwIP and xil_printf


From: Nicolas Pinault
Subject: Re: [lwip-users] lwIP and xil_printf
Date: Wed, 04 Jul 2007 09:56:29 +0200
User-agent: Thunderbird 2.0.0.4 (Windows/20070604)

Hi,
Hi,

I have encountered several problems and I don't know if it's due to lwIP but I never encountered any problems whenever I used the function xil_printf.

At some locations in my code, if I use this function, the server is behaving in a weird way. I'm using OPB Uartlite and whenever I try to display the content of a
variable, it crashes the server or my echo function is not responding at all. If I do a text only xil_printf, everything works fine.

#include "config.h"   // DEFAULT_PORT
#include "global.h"   // server_accept()
#include "lwip/tcp.h" // tcp_new(), tcp_bind(), tcp_listen(), tcp_accept()
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
 
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "xparameters.h"

err_t server_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
  struct connection_state *cs;
 
  /* Allocate memory for the structure that holds the state of the
     connection. */
  cs = mem_malloc(sizeof(struct connection_state));

  if(cs == NULL) {
     xil_printf("could not malloc memory for server_state\r\n");
    return ERR_MEM;
  }
 
  /* Initialize the structure. */
  cs->data = "">   cs->left = 0;

  /* Tell TCP that this is the structure we wish to be passed for our
     callbacks. */
  tcp_arg(pcb, cs);

  /* Tell TCP that we wish to be informed of incoming data by a call
     to the http_recv() function. */
  tcp_recv(pcb, server_recv);
  tcp_err(pcb, server_err);
  tcp_poll(pcb, server_poll, 1);

  xil_printf("Connection established with client %s on port %d.\r\n", getRemoteHostAddress(pcb->remote_ip), (int)(pcb->local_port));
  return ERR_OK;
}

The getRemoteHostAddress is char*. Thanks for your help,

Antoine.

Generaly speaking, printf is a non re-entrant function. If, at least, 2 tasks print a message at the same time, the behavior is unpredictable.
Please note that the same thing apply to malloc and free functions.
You have to check that xil_printf and mem_malloc are re-entrant functions. If not, you have to add a protection mechanism.

Nicolas

reply via email to

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