The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > IP Networking
Google UNIX.COM


IP Networking Questions involving TCP/IP, Routers, Hubs, Network protocols, etc go here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Checking the file if it exists ksmbabu Shell Programming and Scripting 3 04-02-2008 02:16 AM
checking a connection azmathshaikh Shell Programming and Scripting 3 08-20-2005 01:26 AM
Folder Exists borncrazy UNIX for Dummies Questions & Answers 5 06-18-2004 10:48 PM
: /var/adm/utmp exists! dangral SUN Solaris 2 02-27-2004 07:17 AM
Please help me with this script meant for checking /etc/passwd if a name exists TRUEST Shell Programming and Scripting 4 03-04-2002 07:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2007
Registered User
 

Join Date: Apr 2002
Location: New Jersey
Posts: 31
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Smile checking a connection still exists?

Hi I have a bit of c code which I'm trying to use as a relay between apache and a scgi cluster.
Example of problem code is below:

while((n = recv(scgiSock, local_data, MAX_LENGTH, 0)) > 0)
{
time(&t2);
time_now = t2 - t1;
if(time_now > TIMEOUT)
throw 1;
#ifdef UN_NES_DEBUG
logger("scgi : length := ", 1, n);
#endif
logger("sending data: length = ", 1, n);
logger("send ret:= %d", 1, send(receiveSock, local_data, n, 0));
count++;
bzero(local_data, MAX_LENGTH + 1);
sum += n;
logger("Receiving data: current sum = ", 1, sum);
}

I'm encountering a slight but probably easily solveable problem; sometimes apache drops the connection and as a result my program crashes out when trying to send data back on the socket.
Is there any way to check that the socket is still alive before sending data?

Cheers.
Fish.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-13-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
Quote:
Originally Posted by fishman2001 View Post
Is there any way to check that the socket is still alive before sending data?
option 1. Use select() to tell you if there is anything to read and when you can write, if the connection drops then you will be told you can read something and will then get the appropriate error returned by "recv", only "send" if select tells you can write.

option 2. install a SIGPIPE signal handler around the send() to catch any raised signal, then restore the handler after the send.
Reply With Quote
  #3 (permalink)  
Old 12-14-2007
Registered User
 

Join Date: Apr 2002
Location: New Jersey
Posts: 31
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
thanks,
I'm actually using the select() function when I receive information from apache. but I didn't know you could use it to check for sending as well. I'll have to look into that a bit more. would you happend to have any examples of using select in a send situation?

I'm might as well set up the SIGPIPE signal error capture as well. you have any good examples of this?

Cheers.
Fish.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes


The 50 most popular UNIX and Linux searches.
Google Search Cloud for The UNIX and Linux Forums
"inappropriate ioctl for device" 421 service not available, remote server has closed connection ^m arg list too long ascii eof autosys awk trim bash eval bash exec bash for loop boot: cannot open kernel/sparcv9/unix close_wait command copy/move folder in unix curses.h dead.letter export display find grep grep multiple lines grep or grep recursive grep unique inappropriate ioctl for device logrotate.conf lynx javascript mailx attachment mget mtime perl array length ping port read awk output into multiple variables replace space by comma , perl script scp recursive segmentation fault(coredump) sftp script snoop unix stale nfs file handle syn_sent tar exclude unix unix .profile unix com unix forum unix forums unix interview questions unix memory usage unix mtime unix simulator unix.com vi tab size while loop within while loop shell script


All times are GMT -7. The time now is 03:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101