Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCP connection memory leak in Windows #192

Closed
ZhengShaopeng opened this issue Oct 28, 2021 · 2 comments
Closed

TCP connection memory leak in Windows #192

ZhengShaopeng opened this issue Oct 28, 2021 · 2 comments
Labels

Comments

@ZhengShaopeng
Copy link

TCP connection memory leak in Windows

@ZhengShaopeng
Copy link
Author

#include
#include "co/all.h"

void ClientTest()
{
while (true)
{
tcp::Client cTcp("192.168.42.130", 1864);
if (cTcp.connect(3000))
{
while (true)
{
int r = cTcp.send("Authorization: Basic", strlen("Authorization: Basic"));
if (r <= 0) {
LOG << "client send error: " << cTcp.strerror();
break;
}
char buf[1024] = { 0 };
r = cTcp.recv(buf, 1024, 3000);
if (r < 0) {
LOG << "client recv error: " << cTcp.strerror();
break;
}
else if (r == 0) {
LOG << "server close the connection";
break;
}
else {
LOG << "client recv " << fastring(buf, r) << '\n';
//co::sleep(3000);
}
co::sleep(1000);
}
cTcp.close();
}
co::sleep(1000);
}

}

void TCPconnection(tcp::Connection conn)
{
char recvBuf[1024] = { 0 };
int iRecvSize = conn.recv(recvBuf, 1024, 3000);
while (true)
{
int iSendSize = conn.send("ICY 200 OK\r\n", strlen("ICY 200 OK\r\n"), 3000);
if (iSendSize > 0)
{
memset(recvBuf, 0, sizeof(recvBuf));
int iRecvSize = conn.recv(recvBuf, 1024, 3000);
if (iRecvSize <= 0)
{
break;
}
}
else
{
break;
}
co::sleep(1000);
}
conn.close();

}

int main(int argc, char** argv)
{
flag::init(argc, argv);
log::init();

tcp::Server s1;
s1.on_connection(TCPconnection);
s1.start("0.0.0.0", 1864);


for (int i=0;i<5000;i++)
{
	co::go(ClientTest);
	//co::sleep(20);
}

while (true)
{
	co::sleep(1000);
}
return 0;

}

@idealvin idealvin added the bug label Oct 28, 2021
idealvin added a commit that referenced this issue Oct 28, 2021
@idealvin
Copy link
Owner

@ZhengShaopeng

Thanks for your feedback!

It is a bug on windows, which may cause a leak of 72 bytes every time when co::send() was called. I have fixed it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants