| 399 | } |
| 400 | |
| 401 | int CHttpBlockingSocket::ReadHttpHeaderLine(char* pch, int nSize, int nSecs) |
| 402 | // reads an entire header line through CRLF (or socket close) |
| 403 | // inserts zero string terminator, object maintains a buffer |
| 404 | { |
| 405 | int nBytesThisTime = m_nReadBuf; |
| 406 | ptrdiff_t nLineLength = 0; |
| 407 | char* pch1 = m_pReadBuf; |
| 408 | char* pch2 = NULL; |
| 409 | |
| 410 | do |
| 411 | { |
| 412 | // look for lf (assume preceded by cr) |
| 413 | if( (pch2=(LPSTR)memchr(pch1 , '\n', nBytesThisTime))!=NULL ) |
| 414 | { |
| 415 | ASSERT( (pch2)>m_pReadBuf ); |
| 416 | ASSERT( *(pch2 - 1)=='\r' ); |
| 417 | nLineLength = (pch2 - m_pReadBuf) + 1; |
| 418 | if( nLineLength>=nSize ) |
| 419 | nLineLength = nSize - 1; |
| 420 | memcpy(pch, m_pReadBuf, nLineLength); // copy the line to caller |
| 421 | m_nReadBuf -= static_cast<unsigned int>(nLineLength); |
| 422 | memmove(m_pReadBuf, pch2 + 1, m_nReadBuf); // shift remaining characters left |
| 423 | break; |
| 424 | } |
| 425 | pch1 += nBytesThisTime; |
| 426 | nBytesThisTime = Receive(m_pReadBuf + m_nReadBuf, nSizeRecv - m_nReadBuf, nSecs); |
| 427 | if( nBytesThisTime<=0 ) |
| 428 | { // sender closed socket or line longer than buffer |
| 429 | throw CBlockingSocketException(_T("ReadHeaderLine")); |
| 430 | } |
| 431 | m_nReadBuf += nBytesThisTime; |
| 432 | } while( true ); |
| 433 | |
| 434 | *(pch + nLineLength) = _T('\0'); |
| 435 | |
| 436 | return static_cast<unsigned int>(nLineLength); |
| 437 | } |
| 438 | |
| 439 | // reads remainder of a transmission through buffer full or socket close |
| 440 | // (assume headers have been read already) |
nothing calls this directly
no test coverage detected