C++ and Unix Domain Sockets

I having estrange problems with a C++ class that abstracts me of Unix domain sockets.

After calling accept function all starts behaving rarely and I don’t know why.

The following function accepts new requests but after it returns, a simple call to any function gets locked!


UnixSocketClient *Accept(int d)
	{
		sockaddr_un  *clientUnixAddr;
		int	clientUnAddrSize	= sizeof(sockaddr_un);
		int clientSD;

		clientSD			= accept(d,
									(sockaddr *) clientUnixAddr,
									(socklen_t *) &clientUnAddrSize);
		int *bkp = new int;
		memcpy(bkp, &clientSD, sizeof(int));
// it doesn't work passing clientSD only! I have to memcpy() always, why!!!!!????
		return new UnixSocketClient(*bkp, clientUnixAddr);
	}


For instance.


UnixSocketClient *c = Accept(socketDesc);
// but when I invoke Send() method it gets executed normally until it reach the return point. There gets blocked.

c->Send("hello");

I Also tried doing a simple:


cout << "after" << endl; 

with the same result.

I know the accept function returns correctly because I started the debugger but the immediately next function (or method) stops at return point.

:expressionless: :expressionless:

More problems.


	UnixSocketServer *srv = new UnixSocketServer("/tmp/sock");
	srv->Listen();
	while(true)
	{
		srv->Accept();
		cout << "new cli" << endl;
	}

The code above looks fine for me but when I call "srv->Accept() ", it works the first time but, the next iteration srv points to nothing(NULL).

YES, srv points to NULL after calling srv->Accept() .


UnixSocketClient *UnixSocketServer::Accept()
{
		sockaddr_un  *clientUnixAddr;
		int	clientUnAddrSize	= sizeof(sockaddr_un);
		int clientSD;
		if ((clientSD			= accept(_registerSD,
										(sockaddr *) clientUnixAddr,
										(socklen_t *) &clientUnAddrSize)) < 0)
			throw UnixSocketException("UnixSocketServer::Accept: Error accepting Unix domain client");


		return new UnixSocketClient(clientSD, clientUnixAddr);
	}