Click here to Skip to main content
15,913,587 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: the problem to use OpenDriver in DLL Pin
Ryan Binns11-Jul-03 3:20
Ryan Binns11-Jul-03 3:20 
GeneralRe: the problem to use OpenDriver in DLL Pin
gdzfy11-Jul-03 3:30
gdzfy11-Jul-03 3:30 
GeneralRe: the problem to use OpenDriver in DLL Pin
Ryan Binns11-Jul-03 4:16
Ryan Binns11-Jul-03 4:16 
GeneralRe: the problem to use OpenDriver in DLL Pin
gdzfy11-Jul-03 4:19
gdzfy11-Jul-03 4:19 
GeneralSocket question Pin
georgiek5010-Jul-03 13:44
georgiek5010-Jul-03 13:44 
GeneralRe: Socket question Pin
valikac10-Jul-03 13:52
valikac10-Jul-03 13:52 
GeneralRe: Socket question Pin
georgiek5010-Jul-03 13:57
georgiek5010-Jul-03 13:57 
GeneralRe: Socket question Pin
georgiek5010-Jul-03 14:18
georgiek5010-Jul-03 14:18 
Here are the two functions I have written up for this purpose if it helps:

int ReceiveHeader(SOCKET ClientSock, short iHeader[], int iLength)
{
	// Function to properly fill buffer

	short iHeaderBuffer[14];	// Buffer to hold the header data

	int iReceivedTotal		= 0;	// Total bytes received
	int iReceivedThisPass   = 0;	// Total bytes received in one recv
	int x					= 0;	// For the elements of the array
	int iThisX;						// For the elements of the array

	// Loop until the total bytes received is equal
	// to the total bytes we want; 2 bytes at a time
	while (iReceivedTotal < iLength)
	{
		iThisX = 0;

		for (short i = 0; i < (14 - (iReceivedTotal / 2)); i++)
		{
			iHeader[x] = iHeaderBuffer[i];

			x++;

			iThisX++;	// the number of elements we advance in this loop ONLY
		}
		
		iReceivedThisPass = recv(ClientSock, 
			                     szBuffer, 
								 (28 - iReceivedTotal),
							     0
							    );
		

		if (iReceivedThisPass != SOCKET_ERROR)
		{
			// If an odd number of bytes are sent then go back and 
			// resend because the array is short aligned
			//if ( sizeof(iHeader) % iReceivedThisPass != 0 )
			if ( 28 % iReceivedThisPass != 0 )
			{
				iReceivedThisPass = 0;

				x -= iThisX;

				continue;
			}

			iReceivedTotal += iReceivedThisPass;	// Increment total received

			// Make sure we are not advancing that which we are not receiving
			// eg. if x was 14 and we had received 12 bytes then we would want
			// to subtract 2; we divide iReceivedTotal by two because each
			// element of the array is two bytes
			x -= (14 - (iReceivedTotal / 2));
		}
		else
		{
			if (WSAGetLastError() != WSAEWOULDBLOCK)
				return -1;
		}
	}

	return iReceivedTotal;
}


And this opposite is for sending:

int SendHeader(SOCKET ClientSock, short iHeader[], int iLength)
{
	// Function to properly fill buffer

	short iHeaderBuffer[14];	// Buffer to hold the header data

	int iSentTotal		= 0;	// Total bytes sent
	int iSentThisPass   = 0;	// Total bytes sent in one send
	int x				= 0;	// For the elements of the array
	int iThisX;					// For the elements of the array

	// Loop until the total bytes sent is equal
	// to the total bytes we want; send two bytes at
	// a time

	while (iSentTotal < iLength)
	{
		iThisX = 0;

		for (short i = 0; i < (14 - iSentTotal); i++)
		{
			iHeaderBuffer[i] = iHeader[x];

			x++;

			iThisX++;
		}
		
		iSentThisPass = send(ClientSock, 
			                 (char*) iHeaderBuffer 
						     (28 - iSentTotal),	
						     0
							);

		if (iSentThisPass != SOCKET_ERROR)
		{
			// If an odd number of bytes are sent then go back and 
			// resend because the array is short aligned
			if ( 28 % iSentThisPass != 0 )
			{
				iSentThisPass = 0;

				x -= iThisX;

				continue;
			}
			
			iSentTotal += iSentThisPass;		// Increment total received

			// Make sure we are not advancing that which we are not sending
			// eg. if x was 14 and we had send 12 bytes then we would want
			// to subtract 2; we divide iSentTotal by two because each
			// element of the array is two bytes
			x -= (14 - (iSentTotal / 2));
		}
		else 
		{
			if (WSAGetLastError() != WSAEWOULDBLOCK)
				return -1;
		}
	}
	
	return iSentTotal;
}

GeneralRe: Socket question Pin
Ryan Binns10-Jul-03 17:43
Ryan Binns10-Jul-03 17:43 
GeneralRe: Socket question Pin
Trollslayer11-Jul-03 1:48
mentorTrollslayer11-Jul-03 1:48 
GeneralProgrammatically burning a CD Pin
Martin Hinchy10-Jul-03 12:33
Martin Hinchy10-Jul-03 12:33 
GeneralRe: Programmatically burning a CD Pin
John M. Drescher10-Jul-03 12:42
John M. Drescher10-Jul-03 12:42 
GeneralRe: Programmatically burning a CD Pin
Michael Dunn10-Jul-03 13:27
sitebuilderMichael Dunn10-Jul-03 13:27 
GeneralRe: Programmatically burning a CD Pin
PenguinSource28-Jul-03 2:52
PenguinSource28-Jul-03 2:52 
GeneralRe: Programmatically burning a CD Pin
Ryan Binns10-Jul-03 17:45
Ryan Binns10-Jul-03 17:45 
QuestionHow many lines? Pin
Scozturk10-Jul-03 9:16
professionalScozturk10-Jul-03 9:16 
AnswerRe: How many lines? Pin
David Crow10-Jul-03 10:05
David Crow10-Jul-03 10:05 
AnswerRe: How many lines? Pin
John R. Shaw10-Jul-03 11:15
John R. Shaw10-Jul-03 11:15 
AnswerRe: How many lines? Pin
Nick Parker10-Jul-03 12:21
protectorNick Parker10-Jul-03 12:21 
GeneralRe: How many lines? Pin
georgiek5010-Jul-03 13:41
georgiek5010-Jul-03 13:41 
GeneralMFCCGridControl won't give me a member variable! Pin
adonisv10-Jul-03 9:08
adonisv10-Jul-03 9:08 
GeneralRe: MFCCGridControl won't give me a member variable! Pin
John M. Drescher10-Jul-03 10:19
John M. Drescher10-Jul-03 10:19 
GeneralRe: MFCCGridControl won't give me a member variable! Pin
adonisv10-Jul-03 14:44
adonisv10-Jul-03 14:44 
GeneralUpdating all active documents Pin
Anonymous10-Jul-03 8:24
Anonymous10-Jul-03 8:24 
GeneralRe: Updating all active documents Pin
David Crow10-Jul-03 8:37
David Crow10-Jul-03 8:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.