|
|
|
Re: data gets corrupted (c sockets) | |
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
|
I had to go and open my big mouth...Well, I could not replicate "corrupted" data at the end of the file, but rather "missing" data... Delaying before closing the socket file-descriptor seems to fix it. I first tried setting the SO_LINGER and TCP_LINGER2 socket-options both to no avail -- I don't know why but I'm sure that someone else on this list can supply both an explanation and also a much nicer solution; nonetheless, ugly though it is, this one worked for me.
-- David Favro
>From a40b0524d82aa27195f0b9bd157323bdc557745d Mon Sep 17 00:00:00 2001
From: David Favro <df-git@xxxxxxxxxxxxxxxx>
Date: Mon, 14 Jun 2010 19:30:02 -0400
Subject: [PATCH 1/5] The ugly fix.
---
test-dude-webserver/test-webserver.c | 16 ++++++++++++++++
1 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/test-dude-webserver/test-webserver.c b/test-dude-webserver/test-webserver.c
index 0462a88..f3e9734 100644
--- a/test-dude-webserver/test-webserver.c
+++ b/test-dude-webserver/test-webserver.c
@@ -7,6 +7,9 @@
#include <string.h>
#include <time.h>
#include <netinet/tcp.h>
+#include <sys/ioctl.h>
+#include <asm/ioctls.h> // TIOCOUTQ (SIOCOUTQ)
+#include <linux/sockios.h> // SIOCOUTQ
#define ROOTPATH "/root/htmldocs" //just for testing, I'll change later
@@ -110,6 +113,19 @@ int main(int argc, char *argv[])
if (sbytes != rbytes) printf("%d\n", sbytes); //just for debugging purposes
}
close(file);
+ for ( ; ; )
+ {
+ int value;
+ if ( ioctl(newsockfd, SIOCOUTQ, &value) < 0 )
+ error("ioctl(SIOCOUTQ) failed");
+ if ( value > 0 )
+ {
+ printf( "%d bytes left to send.\n", value );
+ sleep(1);
+ }
+ else
+ break;
+ }
close(newsockfd);
}
return 0;
--
1.6.3.3
[Netdev] [Ethernet Bridging] [Linux 802.1Q VLAN] [Linux Wireless] [Kernel Newbies] [Security] [Linux for Hams] [Netfilter] [Git] [Bugtraq] [Photo] [Yosemite] [Yosemite News and Information] [MIPS Linux] [ARM Linux] [Linux RAID] [Linux PCI] [Linux Admin] [Samba] [Video 4 Linux] [Linux Resources]