bool cConnection::Write(void) { int size; if (!BufferReset) { BufferReset = true; Buffer.Read(); } size = Socket->send(Buffer.GetWithPos(), Buffer.GetRemaining() ); if (size != SOCKET_ERROR) { if (!Buffer.Read(size)) { return WriteCallback(); } } return false; }
int Mp3OutputStream::InternalEncode(PBYTE buffer, int index, int count) { int raw_audio_lenght = count, encoded = 0; bool lame_result; #ifndef Mp3OutputStream_Buffering if (!(lame_result = LameEncodeChunk(global_fags, buffer, index, count, bytes_per_sample, m_outBuffer, m_outBufferLenght, encoded))) { encoded = -1; Global::DebugWrite(_T("Lame_encDll.EncodeChunk failed with the error code {0}"), lame_result); } #else while (count > 0) { if (m_inBufferPos > 0) { auto toCopy = std::min(count, m_inBufferLenght - m_inBufferPos); std::copy(buffer + index, buffer + index + toCopy, m_inBuffer + m_inBufferPos); m_inBufferPos += toCopy; index += toCopy; count -= toCopy; if (m_inBufferPos >= m_inBufferLenght) { m_inBufferPos = 0; if ((lame_result = LameEncodeChunk(global_fags, m_inBuffer, 0, bytes_per_sample, m_inBufferLenght, m_outBuffer, encoded))) { if (lame_result && WriteCallback && encoded > 0) { WriteCallback(m_inBufferLenght, (char*) m_outBuffer, encoded); } } else { ::OutputDebugString(_T("Lame_encDll.EncodeChunk failed with the error code {0}")); } } } else { if (count >= m_inBufferLenght) { if ((lame_result = LameEncodeChunk(global_fags, (PBYTE)buffer, index, m_inBufferLenght, bytes_per_sample, m_outBuffer, encoded))) { if (lame_result && WriteCallback && encoded > 0) { WriteCallback(m_inBufferLenght - index, (char*) m_outBuffer, encoded); } } else { ::OutputDebugString(_T("Lame_encDll.EncodeChunk failed with the error code {0}")); } count -= m_inBufferLenght; index += m_inBufferLenght; } else { std::copy(buffer + index, buffer + index + count, m_inBuffer); m_inBufferPos = count; index += count; count = 0; } } } #endif return encoded; }
void Socket::BurstPush() { if(AcquireSendLock()) WriteCallback(); }