int DESC::ProcessInput() { ssize_t bytes_read; if (!m_lpInputBuffer) { sys_err("DESC::ProcessInput : nil input buffer"); return -1; } buffer_adjust_size(m_lpInputBuffer, m_iMinInputBufferLen); bytes_read = socket_read(m_sock, (char *) buffer_write_peek(m_lpInputBuffer), buffer_has_space(m_lpInputBuffer)); if (bytes_read < 0) return -1; else if (bytes_read == 0) return 0; buffer_write_proceed(m_lpInputBuffer, bytes_read); if (!m_pInputProcessor) sys_err("no input processor"); #ifdef _IMPROVED_PACKET_ENCRYPTION_ else { if (cipher_.activated()) { cipher_.Decrypt(const_cast<void*>(buffer_read_peek(m_lpInputBuffer)), buffer_size(m_lpInputBuffer)); } int iBytesProceed = 0; // false가 리턴 되면 다른 phase로 바뀐 것이므로 다시 프로세스로 돌입한다! while (!m_pInputProcessor->Process(this, buffer_read_peek(m_lpInputBuffer), buffer_size(m_lpInputBuffer), iBytesProceed)) { buffer_read_proceed(m_lpInputBuffer, iBytesProceed); iBytesProceed = 0; } buffer_read_proceed(m_lpInputBuffer, iBytesProceed); } #else else if (!m_bEncrypted)
int CPeerBase::Send() { if (buffer_size(m_outBuffer) <= 0) return 0; int iBufferLeft = fdwatch_get_buffer_size(m_fdWatcher, m_fd); int iBytesToWrite = MIN(iBufferLeft, buffer_size(m_outBuffer)); if (iBytesToWrite == 0) return 0; int result = socket_write(m_fd, (const char *) buffer_read_peek(m_outBuffer), iBytesToWrite); if (result == 0) { buffer_read_proceed(m_outBuffer, iBytesToWrite); if (buffer_size(m_outBuffer) != 0) fdwatch_add_fd(m_fdWatcher, m_fd, this, FDW_WRITE, true); } return (result); }
const void * CPeerBase::GetRecvBuffer() { return buffer_read_peek(m_inBuffer); }