[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem
From: |
Martin Velek |
Subject: |
Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem |
Date: |
Tue, 22 Feb 2011 13:29:20 +0100 |
Probably you want to set the backlog to a value "0", zero. It will
have no effect because of this check.
tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
{
/*...some code...*/
#if TCP_LISTEN_BACKLOG
lpcb->accepts_pending = 0;
lpcb->backlog = (backlog ? backlog : 1);
#endif /* TCP_LISTEN_BACKLOG */
/*...some code...*/
}
Obviously zero is not a proper value. Everytime, one client will wait.
If you want only one client, you have to close the listen socket after
accepting a connection and then reopen it. Ugly way, has anyone a
better idea?
Regards
Martin
On 22 February 2011 08:15, Mrutyunjay <address@hidden> wrote:
> hi ,
> I am using lwip (STABLE-1.3.2) in two different f/w with rtthreads on TI
> luminary processor LM3S6965.
>
> I am not able to restrict listen queue to zero ( I need only one active
> connection on listening socket)
>
> 1. using blocking api . if i set MAXCLIENT = 0
>
> if i set TCP_LISTEN_BACKLOG 0 , I can see 1 active connection and 8 in
> queue , 9th connection is rejected.
>
> if i set TCP_LISTEN_BACKLOG 1 , I can see 1 active connection and 1 in
> queue.
>
> I am passing MAXCLIENT for listen queue as follows
>
> listen(server_socket, MAXCLIENT) == -1) // control the listen queue
> accordingly note use : 0 for blocking 1 for non blocking f/w
>
> ---------------code snippet ---------------
> #define MAXCLIENT 0 // only one active connection.
> #define OFFLINE_PORT 5000 // listen on tcp 5000 port
> if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) == -1)
> {
> !sock error handling !
> }
> /* Local Setting to receive connection
> * initialize the server address (LM Module as Server)
> */
> server_addr.sin_family = AF_INET;
> server_addr.sin_port = htons(OFFLINE_PORT);
> server_addr.sin_addr.s_addr = INADDR_ANY;
> rt_memset(&(server_addr.sin_zero),8, sizeof(server_addr.sin_zero));
>
> /* bind the connection on specified port to ANY Local IP address
> * i.e bind the socket to server address
> */
> if (bind(server_socket, (struct sockaddr *)&server_addr, sizeof(struct
> sockaddr)) == -1)
> {
> /* Bind fails Error handling !
> }
>
> /* Listen on Socket
> * Keep Server on listening mode
> */
> if (listen(server_socket, MAXCLIENT) == -1)
> {
> // Listen error handling
> }
> while(1) // wait for connection
> {
>
> //save one level stack
> sin_size = sizeof(struct sockaddr_in);
>
> /* connection socket accepts a client request,
> * this function call is a blocking type
> */
> connected = accept(server_socket, (struct sockaddr *)&client_addr,
> &sin_size);
> /* returns a successful connection socket */
>
> /* Accept the return of client addr point to client's address
> information*/
> rt_kprintf("\nI got a connection from (%s , %d)\n",
> inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
>
> while(1) // read and process responce from client until disconnected
> or sock error
> {
> bytes_received = read_bytes_from_socket(connected,(unsigned char
> *)&request_header.header,sizeof(request_header.header));
> if(bytes_received <= 0)
> {
> lwip_close(connected);
> break ; // get out of connected loop processing and wait for
> next connection .
> }
> else
> {
> // process incomming data and respond to clients .
> }
> } // end while client connected
>
> }// End while // wating for conection loop
> ---------------
>
> 2. using non blocking api (select ,read ,write )
>
> if i set TCP_LISTEN_BACKLOG 0 or 1, I still get 8 queue connections
>
>
>
>
>
>
> Regards,
> Mrutyunjay B Patel
> Regards,
> Mrutyunjay B Patel
>
> _______________________________________________
> lwip-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/lwip-users
>
- [lwip-users] TCP_LISTEN_BACKLOG setting problem, Mrutyunjay, 2011/02/22
- Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem, Simon Goldschmidt, 2011/02/22
- Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem, Mrutyunjay, 2011/02/22
- Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem, Simon Goldschmidt, 2011/02/22
- Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem, Mrutyunjay, 2011/02/22
- Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem, Kieran Mansley, 2011/02/22
- Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem, Simon Goldschmidt, 2011/02/22
- Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem, Kieran Mansley, 2011/02/22
Re: [lwip-users] TCP_LISTEN_BACKLOG setting problem,
Martin Velek <=