In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "linux server side does not receive data when sending data", so the editor summarizes the following content to you, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "linux server side sends data when the opposite end does not receive how to solve" article.
For this situation, we generally recommend adding some defensive measures from the following aspects:
Set the upper limit of the send buffer size of each send connection (such as 2m, or less than this value). When the data on a certain connection cannot be sent out, when the data is stored in the send buffer, first judge the maximum remaining space in the buffer. If the remaining space is already less than the size of the data we want to put in, that is to say, the data size in the buffer will exceed the upper limit we specify. If there is a problem with the connection, close the connection and reclaim the corresponding resources (such as emptying the buffer, recycling socket resources, etc.). The sample code is as follows:
/ / outputBuffer_ is the send buffer object
Size_t remainingLen = outputBuffer_.remainingBytes ()
/ / if the length of the data added to the buffer exceeds the maximum remaining amount of the send buffer
If (remainingLen
< dataToAppend.length()) { forceClose() return } outputBuffer_.append(static_cast(dataToAppend.c_str()), dataToAppend.length()); 还有另外一种场景,当有一部分数据已经积压在发送缓冲区了,此后服务器端未产生新的待发送的数据,此时如果不做任何处理,发送缓冲区的数据会一直积压,但是发送缓冲区的数据容量也不会超过上限。如果不做任何处理的话,该数据会一直在缓冲区中积压,白白浪费系统资源。对于这种情况一般我们会设置一个定时器,每隔一段时间(如 3 秒)去检查一下各路连接的发送缓冲区中是否还有数据未发送出去,也就是说如果一个连接超过一定时间内还存在未发送出去的数据,我们也认为该连接出现了问题,我们可以关闭该路连接并回收相应的资源(如清空缓冲区、回收套接字资源等)。示例代码如下: //每3秒检测一次 const int SESSION_CHECK_INTERVAL = 3000; SetTimer(SESSION_CHECK_TIMER_ID, SESSION_CHECK_INTERVAL); void CSessionManager::OnTimer() { for (auto iter = m_mapSession.begin(); iter != m_mapSession.end(); ++iter) { if (!CheckSession(iter->Value))
{
/ / close session and recycle related resources
Iter- > value- > ForceClose ()
Iter = m_mapSession.erase (iter)
}
}
}
Void CSessionManager::CheckSession (CSession* pSession)
{
If (! pSession- > GetConnection (). OutputBuffer.IsEmpty ())
Return false
Return true
} the above is about the article "how to solve the problem when sending data from the linux server?". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.