public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] help in tcp/ip stack !!!
@ 2001-06-04 18:07 wangwei
  2001-06-05  5:53 ` Jonathan Larmour
  0 siblings, 1 reply; 8+ messages in thread
From: wangwei @ 2001-06-04 18:07 UTC (permalink / raw)
  To: ecos-discuss

[-- Attachment #1: Type: text/plain, Size: 886 bytes --]

Hi,all
help me !!
I make a tcp server in ecos. when client connect with it , appliaction
dynamically create a thread to communicate with client.
the client is running in linux, and can be run in background .
At normal, the server can running stably.
When I make a shell to run lots of client program in background,more than 30
clients,the server in ecos give "EXH 4" error.
In this application, My memory in ecos is more than 3M ,there is enough
memory for malloc. And when thread which run server program is ended, the
memory it used can be free .So I think memory cann't cause this problem.

I had met the "EXH 4" error before . When I try ipaq nanox package in ecos ,
it call nanosleep() in a no posix thread , and cause a "EXH 4" error.
so I suspect it is caused by the same reason .but I can't find out .

The program is in attachment . Does anybody read it and help me !!
thanks.

[-- Attachment #2: my_thread.h --]
[-- Type: text/plain, Size: 269 bytes --]

typedef struct EXTEND_THREAD_PARAM {
	char thread_name[50];
	cyg_handle_t handle;
	void * stack_base;
	void * memp;
	cyg_thread thread_instance;
	void * private;
	} Extend_Thread_Param;
typedef struct CLIENT_DATA{
	int sfd;
	struct sockaddr_in cliaddr;
	} client_data;

[-- Attachment #3: tcp_test.c --]
[-- Type: text/x-c, Size: 3859 bytes --]

#include <cyg/kernel/kapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <network.h>
#include <pkgconf/net.h>
#include <pkgconf/system.h>
#include <cyg/infra/testcase.h>
#include "my_thread.h"

static cyg_mbox mbox0,mbox1;
static cyg_handle_t m0,m1;
cyg_thread tdeamon,tcreater;
cyg_handle_t h_deamon,h_creater;
static int living_thread;

#define THREADNAME "testthread"

#define THREAD_STACK_SIZE 4096
char stack[2][THREAD_STACK_SIZE];

extern void * Malloc_Thread(int size)
{
        int true_size;
	void *p;
	Extend_Thread_Param *tp;
        // the true_size will include the thread parameter
        true_size=size+sizeof(Extend_Thread_Param);
        p=malloc(true_size);     
	tp=(Extend_Thread_Param *) p;
	tp->memp=p;
	tp->stack_base=p+sizeof(Extend_Thread_Param);
	return p;
}

void test( Extend_Thread_Param *p)

{
	Extend_Thread_Param my_thread_param;
	client_data *clidata;
	char net_addr[16],*addr,str[20];
	int i,j;

	sprintf(str,"0123456789\n");
	bzero(net_addr,sizeof(net_addr));
	my_thread_param=*p;
	clidata=my_thread_param.private;
	addr=inet_ntoa(clidata->cliaddr.sin_addr);
	sprintf(net_addr,"%s",addr);
	//printf("the stack is %x\n",(unsigned int ) p);
	//diag_printf("connect by %s,0x%x\n",net_addr,clidata->cliaddr.sin_port);
	i=rand()%50;
	for(j=0;j<i;j++)
	  write(clidata->sfd,str,11);
	
	close(clidata->sfd);
	free(clidata);
	cyg_mbox_put(m0,(void *)&my_thread_param);
	
	

	/*
	//printf("%s Param_thread_param address is %x\n",p->thread_name,
	//		(cyg_addrword_t)&my_thread_param);
	cyg_thread_delay(100+rand()%2000);
	//printf("%s is end \n",my_thread_param.thread_name);
	cyg_mbox_put(m0,(void *)&my_thread_param);
	*/
}


void deamon_thread(void)
{
	Extend_Thread_Param  *p,ThreadParam;
	while(1)
	{
	 p=(Extend_Thread_Param *) cyg_mbox_get(m0);
	 ThreadParam=*p;
	 cyg_thread_kill(ThreadParam.handle);
	 free(ThreadParam.memp);
	 living_thread--;
	}
}

void thread_creater()
{
	Extend_Thread_Param *tp;
	void *p;
	int sfd;
	struct sockaddr_in sock_host;
	
    	init_all_network_interfaces();
//	TNR_INIT();
	diag_printf("now server come in\n");

	sfd=socket(AF_INET,SOCK_STREAM,0);
	sock_host.sin_family=AF_INET;
	sock_host.sin_port=htons(9001);
	sock_host.sin_addr.s_addr=htonl(INADDR_ANY);
	bind(sfd,(struct sockaddr *)&sock_host,sizeof(sock_host));
	listen(sfd,8);
	while(1)
	{
	 client_data *client;
	 int cliaddr_len=sizeof(client->cliaddr),i;
	 client=malloc(sizeof(client_data)); 
	 client->sfd=accept(sfd,(struct sockaddr *)&(client->cliaddr),&cliaddr_len);
	 {
	   p=Malloc_Thread(THREAD_STACK_SIZE);
	   tp=(Extend_Thread_Param *)p;
	   sprintf(tp->thread_name,"client%d",i);
	   i++;
	   tp->private=client;
	   cyg_thread_create(14,test,(cyg_addrword_t)tp,
			tp->thread_name,tp->stack_base,THREAD_STACK_SIZE,
			&(tp->handle),&(tp->thread_instance));
	   cyg_thread_resume(tp->handle);
	   living_thread++;
	 }
	}
//	TNR_PRINT_ACTIVITY();
	 
/*
	int i=0,j;
	living_thread=0;
	for(;;)
	{
	 for(j=0;j<100;j++){
	 p=Malloc_Thread(THREAD_STACK_SIZE);
	 tp=(Extend_Thread_Param *)p;
	 sprintf(tp->thread_name,"%s%d",THREADNAME,i);
	 cyg_thread_create(14,test,(cyg_addrword_t)tp,
			tp->thread_name,tp->stack_base,THREAD_STACK_SIZE,
			&(tp->handle),&(tp->thread_instance));
	 cyg_thread_resume(tp->handle);
	 i++;living_thread++;
	 }
	 printf("thread created %d,leave %d\n",i,living_thread);
	 cyg_thread_delay(1000);
	}
*/
}

void cyg_user_start(void)
{
  
    cyg_mbox_create(&m0,&mbox0);
    cyg_mbox_create(&m1,&mbox1);
    

    cyg_thread_create(11,thread_creater,(cyg_addrword_t)0,
		     "Thread create",(void *)stack[0],THREAD_STACK_SIZE,
		     &h_creater,&tcreater);
    cyg_thread_create(10,deamon_thread,(cyg_addrword_t)0,
		     "Thread deamon",(void *)stack[1],THREAD_STACK_SIZE,
		     &h_deamon,&tdeamon);
    cyg_thread_resume(h_deamon);
    cyg_thread_resume(h_creater);
}


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2001-06-11 12:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-04 18:07 [ECOS] help in tcp/ip stack !!! wangwei
2001-06-05  5:53 ` Jonathan Larmour
2001-06-06  3:34   ` wangwei
2001-06-06  6:46     ` Jonathan Larmour
2001-06-07 21:00       ` wangwei
2001-06-07 21:14         ` Jonathan Larmour
2001-06-10 17:41           ` wangwei
2001-06-11 12:55             ` Jonathan Larmour

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).