LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2011, 06:33 PM   #16
Lantzvillian
Member
 
Registered: Oct 2007
Location: BC, Canada
Distribution: Fedora, Debian
Posts: 210

Original Poster
Rep: Reputation: 41

which would be fine if the client was on the server.. but if it was on a different machine.. a ctrl c would just kill the client and the tcp stack would issue a FIN... and so changing the code to deal with that wouldn't do jack no?
 
Old 02-13-2011, 06:50 PM   #17
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
The SIGPIPE signal is caused by the write(sockfd, "DATA-ACK", strlen("DATA-ACK")); trying to write to a connection the other end has already dropped. Use send(sockfd, "DATA-ACK", strlen("DATA-ACK"), MSG_NOSIGNAL); instead. It will return (ssize_t)-1 with errno set to EPIPE instead of raising the SIGPIPE signal.
Hope this helps,
Nominal Animal

Last edited by Nominal Animal; 03-21-2011 at 07:59 AM.
 
Old 02-13-2011, 06:55 PM   #18
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Nominal animal is dead on. Thanks for that, I couldn't think of what to append and change.
 
Old 02-13-2011, 07:24 PM   #19
Lantzvillian
Member
 
Registered: Oct 2007
Location: BC, Canada
Distribution: Fedora, Debian
Posts: 210

Original Poster
Rep: Reputation: 41
nominal animal made me think... yeah catch that error so I tried:

Code:
if((write(sockfd, "DATA-ACK", strlen("DATA-ACK"))) == -1) {
	  fprintf(fp, "%s,disconnect\n",inet_ntoa(client_addr.sin_addr));
	  fclose(fp);
	  printf("can't catch SIGPIPE signal\n");
	  printf("Error on read\n");
	  close(sockfd);
	  pthread_exit(NULL);
      }
Which in turn worked, and as the clients disconnect the threads are terminated.. so score!

Thanks guys for the help!! I gotta factor this code now for epoll and then profile all three and compare them - I'll definately be using this forum more. Again, super grateful!
 
Old 02-13-2011, 07:28 PM   #20
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Glad to know that we helped. If your problem is solved, mark the thread as solved and give rep or whatever
 
  


Reply

Tags
[c]



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Multithreaded RPC server failed using TCP client (Redhat) yadavamitesh Linux - Newbie 10 06-12-2009 03:30 AM
Multithreaded Numbercrunching /IO not producing the performance gain i expected qwijibow Programming 10 02-27-2008 08:41 PM
problems in multithreaded send()/recv() using tcp socket arslanali Programming 2 05-26-2007 09:00 AM
Multithreaded TCP Client examples daveseff Programming 1 03-31-2005 11:29 PM
tcp/ip multithreaded server stops accepting connection debjyotidas Linux - Networking 2 07-23-2004 12:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration