void TcpConnection::send(const StringPiece& message) { if (state_ == kConnected) { sendInLoop(message); } }
void TcpConnection::send(Buffer* buf) { if (state_ == kConnected) { sendInLoop(buf->peek(), buf->readableBytes()); buf->retrieveAll(); } }
void TcpConnection::send(const void* data, size_t len) { if (state_ == kConnected) { if (loop_->isInLoopThread()) { sendInLoop(data, len); } else { loop_->runInLoop(std::bind(&TcpConnection::sendInLoop, this, data, len)); } } }
void TcpConnection::send(NetBuffer* buffer) { if (state_ == kConnected) { if (loop_->isInLoopThread()) { sendInLoop(buffer->peek(), buffer->readableBytes()); buffer->retrieveAll(); } else { loop_->runInLoop(std::bind(&TcpConnection::sendInLoop2, shared_from_this(), buffer->retrieveAllAsString())); } } }
void TcpConnection::send(ByteBuffer* buffer) { if (state_ == kConnected) { if (loop_->isInLoopThread()) { sendInLoop(buffer->peek(), buffer->readableBytes()); buffer->retrieveAll(); } else { loop_->runInLoop(std::bind(static_cast<void(TcpConnection::*)(const std::string&)>(&TcpConnection::sendInLoop), shared_from_this(), buffer->retrieveAllAsString())); } } }
void TcpConnection::send(const char* msg) { if(state_ == kConnected) { if(loop_->isInLoopThread()) { size_t len = strlen(msg); // 此处用sizeof 会出错 原因为字符串长度不对 size_t sizeLen = sizeof(msg); // 这里sizeof 求2的是指针长度 printf("%s %s msg = %s len = %zu sizeLen = %zu\n", __FILE__, __FUNCTION__, msg, len, sizeLen); sendInLoop(msg, len); } else { } } }
void TcpConnection::sendInLoop(const StringPiece& message) { sendInLoop(message.data(), message.size()); }
void TcpConnection::sendInLoop(const std::string& buffer) { sendInLoop(buffer.data(), buffer.size()); }