LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-27-2013, 11:54 AM   #1
Brandon9000
Member
 
Registered: Apr 2012
Location: Florida
Distribution: Many
Posts: 111

Rep: Reputation: Disabled
Socket Rarely Lasts


I have some code that is writing to a TCP client socket. The socket is non-blocking. Actually, I am a middle man between a VNC server and client (never mind why). It works for awhile and then quits. Before, during, and after the error, the value of errno in this client code is 11 (it is perpetually 11). The server side (the recipient of my socket connection), which I didn't write, often has the message: "Connection has been gracefully closed." Other times the server says "Failed to recv data from socket." Here is the code. The variable len is the size of the message to be sent.

for (int i=1; true; i++)
{
lenSent = write(serverSocket,sendBuf, len);
if (lenSent >= len)
break;
if (i > 20)
{
oss.clear();
oss << "Error writing to server. Error number is ";
oss << errno;
oss << ": ";
oss << strerror(errno);
LG1->Log(oss.str().c_str(), ERRORS, COMMUNICATION );
break;
}
usleep(100);
}

When I print out lenSent, it is always equal to len until the error occurs. A typical output would be:

len lenSent
---- -----------
1000 1000
1000 1000
1000 1000
1000 1000
1000 873
1000 -1
1000 -1
1000 -1
1000 -1

lenSent then remains -1 even on subsequent calls to write(). Any ideas? Is the socket just flaking out for network reasons having nothing to do with my code?

Thanks in advance.

Brandon

Last edited by Brandon9000; 02-27-2013 at 12:30 PM.
 
  


Reply



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
How long lasts a recommendation letter? xeon123 General 6 05-26-2012 11:52 AM
Occasional hum, lasts a few minutes? lugoteehalt Linux - Hardware 5 02-23-2009 04:43 AM
Battery only lasts 15 minutes in Hardy Jugney Linux - Laptop and Netbook 5 05-20-2008 02:09 AM
ACPI rarely does anything cjames53 Linux - Laptop and Netbook 0 03-05-2005 08:01 PM
battery only lasts 2hours!! WIth WIndows it could do 6h dimgr Linux - Laptop and Netbook 5 11-15-2004 07:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:53 AM.

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