提交 8cf4ecd8 authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi 提交者: José Luis Millán

Remove unused code

上级 ff17d135
...@@ -66,7 +66,6 @@ public: ...@@ -66,7 +66,6 @@ public:
return this->uvHandle; return this->uvHandle;
} }
void Start(); void Start();
void Write(const uint8_t* data, size_t len, TcpConnectionHandler::onSendCallback* cb);
void Write( void Write(
const uint8_t* data1, const uint8_t* data1,
size_t len1, size_t len1,
......
...@@ -47,10 +47,6 @@ public: ...@@ -47,10 +47,6 @@ public:
return this->closed; return this->closed;
} }
void Write(const uint8_t* data, size_t len); void Write(const uint8_t* data, size_t len);
void Write(const std::string& data)
{
Write(reinterpret_cast<const uint8_t*>(data.c_str()), data.size());
}
/* Callbacks fired by UV events. */ /* Callbacks fired by UV events. */
public: public:
......
...@@ -174,101 +174,6 @@ void TcpConnectionHandler::Start() ...@@ -174,101 +174,6 @@ void TcpConnectionHandler::Start()
MS_THROW_ERROR("error setting peer IP and port"); MS_THROW_ERROR("error setting peer IP and port");
} }
void TcpConnectionHandler::Write(
const uint8_t* data, size_t len, TcpConnectionHandler::onSendCallback* cb)
{
MS_TRACE();
if (this->closed)
{
if (cb)
{
(*cb)(false);
delete cb;
}
return;
}
if (len == 0)
{
if (cb)
{
(*cb)(false);
delete cb;
}
return;
}
// First try uv_try_write(). In case it can not directly write all the given
// data then build a uv_req_t and use uv_write().
uv_buf_t buffer = uv_buf_init(reinterpret_cast<char*>(const_cast<uint8_t*>(data)), len);
int written = uv_try_write(reinterpret_cast<uv_stream_t*>(this->uvHandle), &buffer, 1);
// All the data was written. Done.
if (written == static_cast<int>(len))
{
// Update sent bytes.
this->sentBytes += written;
if (cb)
{
(*cb)(true);
delete cb;
}
return;
}
// Cannot write any data at first time. Use uv_write().
else if (written == UV_EAGAIN || written == UV_ENOSYS)
{
// Set written to 0 so pendingLen can be properly calculated.
written = 0;
}
// Any other error.
else if (written < 0)
{
MS_WARN_DEV("uv_try_write() failed, trying uv_write(): %s", uv_strerror(written));
// Set written to 0 so pendingLen can be properly calculated.
written = 0;
}
size_t pendingLen = len - written;
auto* writeData = new UvWriteData(pendingLen);
writeData->req.data = static_cast<void*>(writeData);
std::memcpy(writeData->store, data + written, pendingLen);
writeData->cb = cb;
buffer = uv_buf_init(reinterpret_cast<char*>(writeData->store), pendingLen);
int err = uv_write(
&writeData->req,
reinterpret_cast<uv_stream_t*>(this->uvHandle),
&buffer,
1,
static_cast<uv_write_cb>(onWrite));
if (err != 0)
{
MS_WARN_DEV("uv_write() failed: %s", uv_strerror(err));
if (cb)
(*cb)(false);
// Delete the UvWriteData struct (it will delete the store and cb too).
delete writeData;
}
else
{
// Update sent bytes.
this->sentBytes += pendingLen;
}
}
void TcpConnectionHandler::Write( void TcpConnectionHandler::Write(
const uint8_t* data1, const uint8_t* data1,
size_t len1, size_t len1,
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论