![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| any way to close socket | pa.chidhambaram | UNIX and Linux Applications | 3 | 02-01-2008 07:12 AM |
| Close Socket at HP-UX | Renato Gregio | HP-UX | 2 | 08-14-2007 07:04 AM |
| socket close hangs and CPU go to 100% | arico | HP-UX | 0 | 08-22-2006 09:35 AM |
| Suse LINUX | hassan2 | Linux | 1 | 06-24-2004 06:38 AM |
| C Prog to close a socket in established state | teledelux | High Level Programming | 1 | 10-03-2001 08:42 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
socket close() -w- pthreads linux 2.6.18.2-34 (suse) SMP
Interesting issue. There was some discussion on the LKML last year regarding the potential problems in concurrent applications reusing file descriptors in various scenarios. The main issue is that the reuse of a file descriptor and reception of data in a threaded application can be confused pretty easily.
Alan Cox suggested using shutdown() before close() to deal with one of the most glaring reuse problems. This doesn't seem to work 100% either. If I have code like this: Code:
extern void *handleclient(void *arg) {
int rd = -1;
long mcount = 0;
VHNDL in;
char buf[BSZ];
pthread_detach(pthread_self());
pthread_mutex_lock(&socketstable);
memcpy(&in,arg,sizeof(in));
pthread_mutex_unlock(&socketstable);
while ( (rd = read(in.c_sock,buf,BSZ)) > 0) {
printf("TID %d: Read message %d from peer at %s = %s\n",pthread_self(),mcount++,inet_ntoa(in.peer.sin_addr),buf);
bzero(buf,BSZ);
}
/*pthread_mutex_lock(&socketstable);*/
shutdown(in.c_sock,SHUT_RDWR);
close(in.c_sock);
/*pthread_mutex_unlock(&socketstable);*/
pthread_exit(NULL);
}
I'm still getting EBADF on some closes and as a result having incrementing numbers of close-wait connects. Any ideas? |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Never mind. Logic error. Was inadvertently reusing a thread.
|
|||
| Google The UNIX and Linux Forums |