H
Heiko Neuhaus
Hello all,
i am Cygwin to create a simple server application. Everything seems to work
fine but when i use the process manager i can see that my app is leaking
handles. If i run it under native linux it crashes after seveal minutes -
which seems to be caused from this error.
// Dummy
class tSockInfo
{
public:
int iPort;
char chIP[4]; int iSocketZ;
bool bAllForward;
int iSocket;
tSockInfo() { bAllForward = false; iSocket = -1; iSocketZ = -1; };
};
// Thread-Procedure
void* dummyThreadProc (void* pArgs)
{
tSockInfo* sockinfo = (tSockInfo*)pArgs;
int q;
close (sockinfo->iSocket);
delete ((tSockInfo*)pArgs);
pthread_exit (NULL);
}
// Main-Routine
int main()
{
int iSocket = socket (AF_INET, SOCK_STREAM, 0);
sockaddr_in saddr = {0};
saddr.sin_family = AF_INET;
saddr.sin_port = htons (socksport);
saddr.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (iSocket, (sockaddr*)(&saddr), sizeof (saddr)))
{
die ("Unable to bind socket to port. Exiting.");
}
if (listen (iSocket, 5))
{
die ("Unable to listen on port. Exiting.");
}
while (1)
{
int iLen = 0;
sockaddr asin;
int ASock = accept (iSocket, (sockaddr*)&asin, &iLen);
if (ASock < 0)
{
die ("Accept returned invalid socket. Exiting.");
}
else
{
tSockInfo* sock = new tSockInfo;
sock->iSocket = ASock;
pthread_t iThreadID;
pthread_create (&iThreadID, NULL, dummyThreadProc, sock);
}
}
}
i am Cygwin to create a simple server application. Everything seems to work
fine but when i use the process manager i can see that my app is leaking
handles. If i run it under native linux it crashes after seveal minutes -
which seems to be caused from this error.
// Dummy
class tSockInfo
{
public:
int iPort;
char chIP[4]; int iSocketZ;
bool bAllForward;
int iSocket;
tSockInfo() { bAllForward = false; iSocket = -1; iSocketZ = -1; };
};
// Thread-Procedure
void* dummyThreadProc (void* pArgs)
{
tSockInfo* sockinfo = (tSockInfo*)pArgs;
int q;
close (sockinfo->iSocket);
delete ((tSockInfo*)pArgs);
pthread_exit (NULL);
}
// Main-Routine
int main()
{
int iSocket = socket (AF_INET, SOCK_STREAM, 0);
sockaddr_in saddr = {0};
saddr.sin_family = AF_INET;
saddr.sin_port = htons (socksport);
saddr.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (iSocket, (sockaddr*)(&saddr), sizeof (saddr)))
{
die ("Unable to bind socket to port. Exiting.");
}
if (listen (iSocket, 5))
{
die ("Unable to listen on port. Exiting.");
}
while (1)
{
int iLen = 0;
sockaddr asin;
int ASock = accept (iSocket, (sockaddr*)&asin, &iLen);
if (ASock < 0)
{
die ("Accept returned invalid socket. Exiting.");
}
else
{
tSockInfo* sock = new tSockInfo;
sock->iSocket = ASock;
pthread_t iThreadID;
pthread_create (&iThreadID, NULL, dummyThreadProc, sock);
}
}
}