@@ -665,8 +665,11 @@ void TcpConnectionImpl::forceClose()
665
665
}
666
666
});
667
667
}
668
-
668
+ #ifndef _WIN32
669
+ void TcpConnectionImpl::sendInLoop (const void *buffer, size_t length)
670
+ #else
669
671
void TcpConnectionImpl::sendInLoop (const char *buffer, size_t length)
672
+ #endif
670
673
{
671
674
loop_->assertInLoopThread ();
672
675
if (status_ != ConnStatus::Connected)
@@ -720,8 +723,8 @@ void TcpConnectionImpl::sendInLoop(const char *buffer, size_t length)
720
723
node->msgBuffer_ = std::shared_ptr<MsgBuffer>(new MsgBuffer);
721
724
writeBufferList_.push_back (std::move (node));
722
725
}
723
- writeBufferList_.back ()->msgBuffer_ ->append (buffer + sendLen,
724
- remainLen);
726
+ writeBufferList_.back ()->msgBuffer_ ->append (
727
+ static_cast < const char *>(buffer) + sendLen, remainLen);
725
728
if (!ioChannelPtr_->isWriting ())
726
729
ioChannelPtr_->enableWriting ();
727
730
if (highWaterMarkCallback_ &&
@@ -800,7 +803,7 @@ void TcpConnectionImpl::send(const std::shared_ptr<MsgBuffer> &msgPtr)
800
803
});
801
804
}
802
805
}
803
- void TcpConnectionImpl::send (const char *msg, uint64_t len)
806
+ void TcpConnectionImpl::send (const char *msg, size_t len)
804
807
{
805
808
if (loop_->isInLoopThread ())
806
809
{
@@ -834,6 +837,47 @@ void TcpConnectionImpl::send(const char *msg, uint64_t len)
834
837
});
835
838
}
836
839
}
840
+ void TcpConnectionImpl::send (const void *msg, size_t len)
841
+ {
842
+ if (loop_->isInLoopThread ())
843
+ {
844
+ std::lock_guard<std::mutex> guard (sendNumMutex_);
845
+ if (sendNum_ == 0 )
846
+ {
847
+ #ifndef _WIN32
848
+ sendInLoop (msg, len);
849
+ #else
850
+ sendInLoop (static_cast <const char *>(msg), len);
851
+ #endif
852
+ }
853
+ else
854
+ {
855
+ ++sendNum_;
856
+ auto buffer =
857
+ std::make_shared<std::string>(static_cast <const char *>(msg),
858
+ len);
859
+ auto thisPtr = shared_from_this ();
860
+ loop_->queueInLoop ([thisPtr, buffer]() {
861
+ thisPtr->sendInLoop (buffer->data (), buffer->length ());
862
+ std::lock_guard<std::mutex> guard1 (thisPtr->sendNumMutex_ );
863
+ --thisPtr->sendNum_ ;
864
+ });
865
+ }
866
+ }
867
+ else
868
+ {
869
+ auto buffer =
870
+ std::make_shared<std::string>(static_cast <const char *>(msg), len);
871
+ auto thisPtr = shared_from_this ();
872
+ std::lock_guard<std::mutex> guard (sendNumMutex_);
873
+ ++sendNum_;
874
+ loop_->queueInLoop ([thisPtr, buffer]() {
875
+ thisPtr->sendInLoop (buffer->data (), buffer->length ());
876
+ std::lock_guard<std::mutex> guard1 (thisPtr->sendNumMutex_ );
877
+ --thisPtr->sendNum_ ;
878
+ });
879
+ }
880
+ }
837
881
void TcpConnectionImpl::send (const std::string &msg)
838
882
{
839
883
if (loop_->isInLoopThread ())
@@ -1215,8 +1259,11 @@ void TcpConnectionImpl::sendFileInLoop(const BufferNodePtr &filePtr)
1215
1259
ioChannelPtr_->enableWriting ();
1216
1260
}
1217
1261
}
1218
-
1262
+ #ifndef _WIN32
1263
+ ssize_t TcpConnectionImpl::writeInLoop (const void *buffer, size_t length)
1264
+ #else
1219
1265
ssize_t TcpConnectionImpl::writeInLoop (const char *buffer, size_t length)
1266
+ #endif
1220
1267
{
1221
1268
#ifdef USE_OPENSSL
1222
1269
if (!isEncrypted_)
@@ -1255,7 +1302,7 @@ ssize_t TcpConnectionImpl::writeInLoop(const char *buffer, size_t length)
1255
1302
len = sslEncryptionPtr_->sendBufferPtr_ ->size ();
1256
1303
}
1257
1304
memcpy (sslEncryptionPtr_->sendBufferPtr_ ->data (),
1258
- buffer + sendTotalLen,
1305
+ static_cast < const char *>( buffer) + sendTotalLen,
1259
1306
len);
1260
1307
ERR_clear_error ();
1261
1308
auto sendLen = SSL_write (sslEncryptionPtr_->sslPtr_ ->get (),
0 commit comments