HomeNewsFeaturesLicensingDownloadsScreenshotsFAQRoadmap Contact Us
Search:
5 Online

Community

Discussion Topics Recent Postings User Contributions General Articles Example Documentation Credits

Licensed Developer

Programmer's Manual Artists Manual Tutorials and Articles

Programming: Game Code

Game Code Overview Server Side Game Code Client Side Game Code

Programming: System

Alphabetical Function List Renderer File System Collision & Ray Casting Low Level Audio Game Audio The Console Console Variable List Multiplayer Localisation Maths Library Memory Manager Model File Formats Texture Formats

Art: Overviews

Specifications Shaders Particle Systems Lens Flares Cipher console Cipher file types Tutorials Reference

Art: Tools

Shader Designer Particle Designer 3dsmax tools Model Conversion Font Generator

Cipher Engine
Game Development Search Engine
GameDev.net
You are not signed in - [sign in] [register]

winsock_TcpRead Bugfix

Overview

Author: firefox
Date Submitted: 2004-01-11 16:59:52

Source Code

/*
==========================
winsock_TcpRead

Reads bytes off the network.
returns the number of bytes we got. <0 is an error
If it successfully reads data from the network, address will
hold the address of the machine that sent the data
==========================
*/
int winsock_TcpRead(int socket, byte* buf, int len, netaddress_t* address)
{
	int bytesread, totalbytesread;
	byte *b2;

	totalbytesread = 0;

	b2 = buf;
	do{
		bytesread = recv(socket, b2, len - totalbytesread, 0);
		b2 += bytesread;
		totalbytesread += bytesread;
	}while((bytesread != SOCKET_ERROR) && bytesread!=0 && bytesread != WSAECONNRESET && totalbytesread<len);

	// convert the returned address
	return bytesread;
}


Description

Up there you can find a corrected version of winsock_TcpRead. The current version produces totally strange output when reading bigger chunks of data via TCP.

The reason for this was a wrong buffer handling. Instead of adding all the Input received by the recv function, the buffer was overwritten everytime, therefore containing the last chunk of data received instead of the full data.

I noticed this when using the REALLY great URL Retrieval Code Snippet by RichardGreen. Thanks Richard, great work!

[Recent Contributions] [Recent Source Code]

User Contributed Comments

JiuQ 11th January, 2004 20:05
actually, it's a bugfix for the URL retrieval resource, as you won't have this the winsock_TcpRead function if you haven't applied Richard's changes.


RichardGreen 11th January, 2004 20:45
Yep, its my fault - i should have tested it with bigger urls, i just tried it with a full site and got a random part of the html source.

Thanks for the fix firefox.

Richard Green




Register and Sign In to discuss this article