socket close() -w- pthreads linux (suse) SMP

Thread Tools Search this Thread
Top Forums Programming socket close() -w- pthreads linux (suse) SMP
# 1  
Old 02-05-2008
socket close() -w- pthreads linux (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:
extern void *handleclient(void *arg) {
int rd = -1;
long mcount = 0;
char buf[BSZ];
                         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);

The reuse of file descriptors still causes EBADF in some cases. The parent process is simple in an accept() loop creating handler threads till MAXTHREADS then recycling. As you see the handler does nothing but read till error and then exits.
I'm still getting EBADF on some closes and as a result having incrementing numbers of close-wait connects.

Any ideas?
# 2  
Old 02-06-2008
Never mind. Logic error. Was inadvertently reusing a thread.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. IP Networking

Is it necessary to close socket after a unstop loop?

Is the last two line necessary? #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> int main(void) { struct sockaddr_in stSockAddr; ... (0 Replies)
Discussion started by: vistastar
0 Replies

2. UNIX and Linux Applications

any way to close socket

I have written a socker program. I have executed that program many times without closing the socket. So I want to find which all sockets binded with which file descriptor. Is there any way to close those socket, which have been opened in that program's execution. please help me!.. (3 Replies)
Discussion started by: pa.chidhambaram
3 Replies

3. HP-UX

Close Socket at HP-UX

Hi all, I have a HP-UX 11.23 that have a Server establishing connections on port 8888 . The problem is that when i need to stop and restart the Server, the connections mantain the same state and i need to wait about 20-30 minutes before all connections finishes. The connections remain at... (2 Replies)
Discussion started by: Renato Gregio
2 Replies

4. HP-UX

socket close hangs and CPU go to 100%

Hello, I'm currently having a problem with HPUX. The application is a C app. It's a socket server. It runs mostly fine, but under some circumstances (I can not replicate it), the app hangs and the CPU goes to 100%. I have use gdb to attach to the app, and it was doing a close(). the... (0 Replies)
Discussion started by: arico
0 Replies

5. Linux Benchmarks

Dual Intel Xeon 2.4Ghz - Linux 2.4.26 SMP

System: CPU/Speed: Dual Intel Xeon 2.4Ghz Ram: 2 GB DDR 266 SDRAM Motherboard: SuperMicro X5DE8-GG Bus: 533MHz/400MHz system bus - Cache: 512KB HD Controller: EIDE Serverworks™ GC-SL Chipset Extra GCC compiler flags: -s... (3 Replies)
Discussion started by: Neo
3 Replies

6. UNIX for Dummies Questions & Answers

SMP support in Linux 7.3

What is the SMP support like when you are running Linux 7.3 on a system with 2-4 CPUs? (3 Replies)
Discussion started by: AngryRabbi
3 Replies

7. Programming

C Prog to close a socket in established state

I have a SUN environment running an WebLogic that communicates w/a 3rd party running IIS. When the IIS site goes down (frequently), I am stuck with sockets in an ESTABLISHED state, and cannot seem to figure out how to avoid this. No exceptions are thrown as I can still open connections to the IIS... (1 Reply)
Discussion started by: teledelux
1 Replies
Login or Register to Ask a Question