C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 09-14-2006, 08:26 PM   #1
30 Helens Agree
 
neandrake's Avatar
 
Join Date: Jan 2002
Posts: 607
problem with send function

i've been working on wrapper class for winsock functions, and i've been tracing down a lag-style issue (the program freeze-lags) and it comes from my send function. if someone could help me out and point out any issues that would really help me out.

Code:
//typical call would be ::perSend(crchat, 1024);
//usually though, the crchat is not 1024 in length. i've tried adding an if(...)break to stop
//when the delimiter was hit, but it didn't do anything.

INT PEER::perSend(CHAR *databuff, INT len)
{
	char *zbuff = databuff;

	while (len > 0)
	{
		iSentBytes = send(sckPeer, zbuff, 1, 0);
		if (iSentBytes == SOCKET_ERROR)
		{
			if ((iError = WSAGetLastError()) != WSAEWOULDBLOCK)
				return -1;
		}

		iTSentBytes += iSentBytes;
		zbuff++;
		len--;
	}

	return iTSentBytes;
}
__________________

AIM: Neandrake
EMAIL: nta0 @ yahoo . com

Operating System: Windows XP SP2
Compiler: GCC
IDE: Notepad++


Don't give up your freedom to think - www.cognitiveliberty.org
neandrake is offline   Reply With Quote
Old 09-14-2006, 08:42 PM   #2
Gawking at stupidity
 
Join Date: Jul 2004
Posts: 2,324
What delimiter? Have you tried running your program through a debugger to see what's going on? Why are you sending the characters one at a time instead of all at once?
__________________
If you understand what you're doing, you're not learning anything.

Ignore any "advice" esbo tries to give you. It's wrong.
itsme86 is offline   Reply With Quote
Old 09-14-2006, 11:15 PM   #3
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,700
> if ((iError = WSAGetLastError()) != WSAEWOULDBLOCK)
And if it is WOULDBLOCK, you skip a character and try and send the next one?

Do you have something else which you can usefully do for a few mS whilst the network clears some of the backlog?

How about trying to send as much as possible with each send call, since it returns with the actual amount sent. Using this its possible to advance through the message buffer.
Code:
	while (len > 0)
	{
		iSentBytes = send(sckPeer, zbuff, len, 0);
		if (iSentBytes == SOCKET_ERROR)
		{
			if ((iError = WSAGetLastError()) != WSAEWOULDBLOCK)
				return -1;
		}
		else
		{
			iTSentBytes += iSentBytes;
			zbuff += iSentBytes;
			len -= iSentBytes;
		}
	}
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Salem is offline   Reply With Quote
Old 09-15-2006, 11:13 AM   #4
30 Helens Agree
 
neandrake's Avatar
 
Join Date: Jan 2002
Posts: 607
thankyou both for replies. I had originally the function to send everything at once, but I had problems with receiving only the first character 1024 times. I changed it this way and it seemed to work. I will definately try salem's approach, however I did some more debugging, and the lag occurs after the perSend function. So it must be a windows thing. the call is sent from a dialog process function, and there is no lag if the perSend function is not called. But the lag occurs after the send (which nothing else happens, except a return to end the function).
__________________

AIM: Neandrake
EMAIL: nta0 @ yahoo . com

Operating System: Windows XP SP2
Compiler: GCC
IDE: Notepad++


Don't give up your freedom to think - www.cognitiveliberty.org
neandrake is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pure virtual function mixed with regular virtual function problem johnnyboldt C++ Programming 3 10-28-2009 09:25 AM
Getting an error with OpenGL: collect2: ld returned 1 exit status Lorgon Jortle C++ Programming 6 05-08-2009 08:18 PM
Didn't quite know where to post this.......compiler problem... incognito C++ Programming 5 02-08-2003 07:42 PM
Interface Question smog890 C Programming 11 06-03-2002 05:06 PM
I need help with passing pointers in function calls vien_mti C Programming 3 04-24-2002 10:00 AM


All times are GMT -6. The time now is 06:56 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22