On Mon, 19 May 2003 mehul radheshyam choube wrote : >hi all, > following is code for a multi-threaded server which waits for >clients to connect. seperate >thread for each client connection. on connection recieves >requets, work on requets and then send >the result. > > the problem is if 10 clients make connection to server 10 >threads are created but when >clients are finished with there work still a original process & a >thread are running. This is because your original server is never dying. There is no break from the while(1) loop. The join statement at the end is extraneous. > >/* > * kcvsServer. > * Author: Mehul. R. Choube. > * > * A server program which waits for clients to connect. seperate >thread for > * each client connection. on connection recieves requets, work >on requets and > * then send the result. > * > */ > >#define PORT 18000 > >#include "../include/dougnet.h" >#include "../include/session.h" >#include "../include/common.h" >#include "../include/common1.h" > >#include >#include >#include >#include >#include >#include > >ReadConf readConf; >ofstream fpLog; > >int main(int argc, char *argv[]) >{ > int s, t, res; > char tpbuf[16]; > pthread_t tid; > void *thread_result; > > s = openlistener(PORT); > if(s == (int) NULL) { > exit(0); > }/* if(s == (int) NULL) */ > > res = readConf.ReadConfFile(CONF_FILE_PATH); > if(!res) { > printf("error while reading config file %s\n", >CONF_FILE_PATH); > return -1; > }/* if(!res) */ > > std::string logfile; > logfile = readConf.LogDir() + "/" + readConf.LogFileName(); > printf("logfile = %s\n", logfile.c_str()); > > fpLog.open(logfile.c_str(), ios::app); > > while(1) { > if(pollsocket(s, 10000)) { > t = acceptfromlistener(s, tpbuf); > > int res = pthread_create(&tid, NULL, &session, (void *)t); > if(res) { > printf("failed to create thread. %s", strerror(errno)); > }/* if(res) */ > > printf("Connection from %s\n", tpbuf); > > }/* if(pollsocket(s, 10000)) */ > }/* while(1) */ > > res = pthread_join(tid, &thread_result); > if(res != 0) { > perror("error join"); > exit(1); > }/* if(res != 0) */ > > return 0; >}/* main() */ > >___________________________________________________ >Get email that means BUSINESS! me @ mycompany.com. >Just Rs.1499/year. >To start, click http://www.rediffmailpro.com > >_______________________________________________ >This is the Linux C Programming List >: http://lists.linux.org.au/listinfo/linuxcprogramming List