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

C / C++ / MFC

 
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 
GeneralRe: Socket question Pin
Ryan Binns10-Jul-03 17:43
Ryan Binns10-Jul-03 17:43 
OK, you need to think in bytes, not shorts. You are sending 28 bytes - it doesn't matter if an odd number are sent or received. You just restart from whichever byte you were up to. I assume here that iLength is the number of shorts, not the number of bytes.

Sending
You don't need to cache the data locally. Just send it straight from the input array. Try this:
int SendHeader(SOCKET ClientSock, const short *piHeader, int iLength)
{
   int iSentTotal = 0;
   int iSentPass = 0;
   const int iLengthBytes = iLength*sizeof(short);
   const unsigned char *ptr = (const unsigned char*)piHeader;
   while(iSentTotal < iLengthBytes)
   {
      iSentPass = send(ClientSock, ptr, iLengthBytes-iSentTotal, 0);
      if(iSentPass != SOCKET_ERROR)
      {
         iSentTotal += iSentPass;
         ptr += iSentPass;
      }
      else
      {
         if(WSAGetLastError() != WSAEWOULDBLOCK)
            return -1;
      }
   }
   return iSentTotal;
}
Receiving
Again, there's no need to make a local copy of the data before transferring it to the array. If you're worried about the contents in case of an error, don't be. If a function returns an error, all output data from it should be considered undefined, unless stated otherwise. I don't think that your code will even compile. Try this:
int ReceiveHeader(SOCKET ClientSock, short *piHeader, int iLength)
{
   int iRecvTotal = 0;
   int iRecvPass = 0;
   const int iLengthBytes = iLength*sizeof(short);
   unsigned char *ptr = (const unsigned short*)piHeader;
   while(iRecvTotal < iLengthBytes)
   {
      iRecvPass = recv(ClientSock, ptr, iLengthBytes-iRecvTotal, 0);
      if(iRecvPass != SOCKET_ERROR)
      {
         iRecvTotal += iRecvPass;
         ptr += iRecvPass;
      }
      else
      {
         if(WSAGetLastError() != WSAEWOULDBLOCK)
            return -1;
      }
   }
   return iRecvTotal;
}
Hope this helps,


Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

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 
GeneralRe: Updating all active documents Pin
John R. Shaw10-Jul-03 11:42
John R. Shaw10-Jul-03 11:42 

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.