int ChunkOutputStream::chunkedWrite( IOVec &iov, int &headerTotal, const char * pBuf, int size) { //printf( "****ChunkOutputStream::chunkedWrite()\n" ); IOVec::iterator iter = iov.end(); int bytes = buildIovec( iov, pBuf, size ); int total = bytes + headerTotal; int ret = m_pOS->writev( iov, total ); assert( m_iCurSize == 0 ); if ( ret >= total ) { iov.clear(); headerTotal = 0; m_iCurSize = 0; return size; } else if ( ret >= 0 ) { if( ret >= headerTotal ) { if ( ret == headerTotal ) { iov.clear(); } else { ret -= headerTotal; m_iTotalPending = bytes - ret; iov.setBegin( iter ); iov.finish( ret ); m_pLastBufBegin = pBuf; m_iLastBufLen = size; } headerTotal = 0; } else { if ( ret ) { headerTotal -= ret; iov.finish( ret ); } iov.setEnd( iter ); } return 0; } else iov.setEnd( iter ); return ret; }
int SpdyStream::write(const char *buf, int len) { IOVec iov; const char *p = buf; const char *pEnd = buf + len; int allowed; if (getState() == HIOS_DISCONNECTED) return LS_FAIL; while(pEnd - p > 0) { allowed = getDataFrameSize(pEnd - p); if (allowed <= 0) break; iov.append(p, allowed); if (sendData(&iov, allowed) == -1) return LS_FAIL; p += allowed; iov.clear(); } return p - buf; }