The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > IP Networking
.
google unix.com



IP Networking Learn TCP/IP, Internet Protocol, Routing, Routers, Network protocols in this UNIX and Linux forum.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Problem with memory leak kshk123 HP-UX 2 05-25-2009 07:01 AM
memory leak problem sonali High Level Programming 5 05-25-2009 06:55 AM
Memory leak in pthread mindTeaser UNIX for Advanced & Expert Users 4 05-18-2009 01:30 AM
Memory leak of fork() whererush High Level Programming 7 05-11-2006 11:51 AM
about virtual memory and memory leak shriashishpatil High Level Programming 4 02-20-2006 11:31 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 07-16-2005
lenna lenna is offline
Registered User
  
 

Join Date: Jul 2005
Posts: 3
memory leak?

Hi All,

my client server application can work in two modes:
1) one direction - only client sends msgs to server
2) two directions - server gives 'answers' to client.

when program run in the first mode it looks OK, but when server answers to client than client's application exit its operation after a short while. I am trying to find the problem but have some taugh time.

this is the function that reads the data in the client side (in which I have problems):


Code:

int TCPClient::readSocketData(int s,
              char *decodeUnifiedMsgForServer,			
              int n,			
	 bool& isMsg
             )
{
	int bcount;							int br;							
	bcount = 0;
	br = 0;
	while (bcount < n)					
	{
		if ((br = recv(s,decodeUnifiedMsgForServer,n-bcount,0)) > 0)
		{
			isMsg = true;
			bcount += br;							decodeUnifiedMsgForServer+= br;              
		}
		else if (br < 0)             /* signal an error to the caller */
		{
			return(-1);
		}
		else							             {
			return bcount;
		}
		//Y 17_04_05 -
		Sleep(0);
		//Y.
                   }
  return(bcount);
}
after buffer (decodeUnifiedMsgForServer) is filled by the function above I decode the data into the relevant data classes as follows:


Code:

void BrainControlComData::decodeMsg(char* decodeUnifiedMsgForServer)
{



	if(strlen(decodeUnifiedMsgForServer) == 0)			
             {
		char* error = "probably an error (see Q1 below)";
	}


	char* msg = decodeUnifiedMsgForServer;
	int size = 4;

	int lenCursorData;
	int lenManipData;
	int lenVzData;

//places 1 - 12 in msg are reserved for total size/ isEventMsg/ MsgID

	int Web_lenOfClass;					
// decode len of msg
	memcpy(&Web_lenOfClass, msg, size);
	int lenOfClass = ntohl(Web_lenOfClass);

	int Web_MsgID;						
// decode msg ID
	memcpy(&Web_MsgID, msg + MSG_ID_LOCATION, size);
	int msgID = ntohl(Web_MsgID);



	//Y 6_07_05 -
	int counter = 12;

	int len = 0;
	len = comData[CURSOR_DATA]->decodeMsg(msg + counter);
	counter += len;

	len = comData[STATE_DATA]->decodeMsg(msg);
}
the first 3 bytes in the buffer are integers (general data such as - total len, msgID etc.) and I decode them in the 2nd function. afterwards I send the buffer into specific data classes that decode the relevant data they need using the fuction decodeMsg.

my questions are as follows:

1) why is the length of the buffer (decodeUnifiedMsgForServer) is always 0 and not equals to the length of the msg received from server? I know that the data is received from the server because it is logged correctly, but still when I check length of msg it equas 0 (first 'if' in second function) - any ideas?

2) when I remarked the line that calls the decodeMsg the application 'behaved' OK and client didn't exit its operation. I think that this error has something to do with memory leak. maybe if I understood the first question I could understand this one as well.

Thank you so much for your help,
Lenna
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:17 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0