thread blocked while deleting a socket.


 
Thread Tools Search this Thread
Special Forums IP Networking thread blocked while deleting a socket.
# 1  
Old 02-27-2012
thread blocked while deleting a socket.

Hello to all,

I have below function, but the thread will be bloked at the line
delete pListenSocket; // Close and delete
If I put some cpu timing switching function prior to it, then no blocking pop up.
Code:
    printf("xyz\n");  // or sleep(100);
    delete pListenSocket; // Close and delete

Can I get some help from any one? Thanks a lot!

Marco. PP

the function
Code:
int Socketpair (int domain, int type, int protocol, Socket ** ppReadSocket, Socket ** ppWriteSocket)
{
	Socket * pListenSocket = NULL;
	Socket * pConnectSocket = NULL;
	Socket * pAcceptSocket = NULL;
    IpAddress listenAddr;
    uint16 listenPort;
    IpAddress remoteAddr;
    uint16 remotePort;
	int saved_errno = -1;

    //
    // Create the listener socket
    //
	pListenSocket = SocketFactory::NewSocket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (pListenSocket == NULL)
    {
        gErrorMsg (fMessageLogSettings, __func__) << "failed to create listener\n";
		return -1;
    }
    if (pListenSocket->Bind (kSoftwareLoopbackIp, 0) < 0)
    {
        gErrorMsg (fMessageLogSettings, __func__) << "failed to bind listener\n";
		goto tidy_up_and_fail;
    }
    pListenSocket->Getsockname (listenAddr, listenPort);
    {
        char debugTxt[32];
        listenAddr.Get (debugTxt, sizeof (debugTxt));
        gAlwaysMsg(fMessageLogSettings, __func__) << "listener bound to " << debugTxt << ":" << listenPort << endl;
    }

	if (pListenSocket->Listen (1) < 0)
    {
        gErrorMsg (fMessageLogSettings, __func__) << "failed to listen\n";
		goto tidy_up_and_fail;
    }

    //
    // Create the connector socket
    //
	pConnectSocket = SocketFactory::NewSocket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if (pConnectSocket == NULL)
    {
        gErrorMsg (fMessageLogSettings, __func__) << "failed to create connector\n";
		goto tidy_up_and_fail;
    }

    //
    // Connect. This would normally block, burt since this is on the lookback, it
    // should come right back
    //
	if (pConnectSocket->Connect(kSoftwareLoopbackIp, listenPort) < 0)
    {
        gErrorMsg (fMessageLogSettings, __func__) << "failed to connect to listener\n";
		goto tidy_up_and_fail;
    }

    //
    // Accept the connection we just tried
    //
	pAcceptSocket = pListenSocket->Accept (remoteAddr, remotePort);
	if (pAcceptSocket == NULL)
    {
        gErrorMsg (fMessageLogSettings, __func__) << "failed to accept\n";
		goto tidy_up_and_fail;
    }
    pAcceptSocket->Getsockname (remoteAddr, remotePort);
    {
        char debugTxt[32];
        remoteAddr.Get (debugTxt, sizeof (debugTxt));
        gAlwaysMsg (fMessageLogSettings, __func__) << "accepted connection from " << debugTxt << ":" << remotePort << endl;
    }

    delete pListenSocket; // Close and delete

    // We always make the connector non-blocking
    pConnectSocket->SetSocketNonBlocking (true);

    fSocketList.push_back (pConnectSocket);
    fSocketList.push_back (pAcceptSocket);
	*ppReadSocket = pConnectSocket;
	*ppWriteSocket = pAcceptSocket;
    gAlwaysMsg(fMessageLogSettings, __func__) << "returning sockets "
        << pConnectSocket->SocketDescriptor()
        << " and "
        << pAcceptSocket->SocketDescriptor()
        << endl;

	return 0;

 tidy_up_and_fail:
	if (saved_errno < 0)
		saved_errno = errno;
	if (pListenSocket != NULL)
    {
		delete pListenSocket;
    }
	if (pConnectSocket == NULL)
    {
		delete pConnectSocket;
    }
	if (pAcceptSocket == NULL)
    {
		delete pAcceptSocket;
    }

	EVUTIL_SET_SOCKET_ERROR(saved_errno);
	return -1;

}


Last edited by jim mcnamara; 02-27-2012 at 08:19 AM.. Reason: please use code tags
# 2  
Old 02-27-2012
Whose API is this? Google comes up pretty dry. Usually, it seems you SocketFactory.CreateSocket() and Socket.close().
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

2. Solaris

Killing a thread having a listener socket

Hi All I have a separate thread ListenerThread having a socket listening to info broadcasted by some remote server. This is created in my main thread. Because of requirements, once the separate thread is started I need to avoid any blocking function on the main thread. Once it comes to the... (2 Replies)
Discussion started by: manustone
2 Replies

3. Programming

Error with socket operation on non-socket

Dear Experts, i am compiling my code in suse 4.1 which is compiling fine, but at runtime it is showing me for socket programming error no 88 as i searched in errno.h it is telling me socket operation on non socket, what is the meaning of this , how to deal with this error , please... (1 Reply)
Discussion started by: vin_pll
1 Replies

4. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

5. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

6. AIX

Nim Thread Blocked On "hostname"

hello i'm running on two P570 aix 5.3 8 cpus 48 Gram hacmp 5.4 ver and i got this massage on my errpt : nim thread blocked "hostname" any one got this masaage? what i can do ? i can leave with this massage? best regards ariec (2 Replies)
Discussion started by: ariec
2 Replies

7. IP Networking

Can we write a multiple thread to receive from a single socket file descriptor

Hi Friends, I have written a program which will listener for more than 1000 requests per second from a single socket descriptor and then it will process those requestes. Its taking X amount of time. Now i want to reduce that time. Will I can write multiple threads to receive the... (2 Replies)
Discussion started by: pa.chidhambaram
2 Replies

8. IP Networking

BitTorrent port 6969 blocked... how to get around the blocked port

Due to the massive Upload speeds killing .... or overstressing our schools network...... my school has blocked port 6969 (the most common BitTorrent port). So I cant connect to the tracker anymore, in other words no more downloading from school :( Does anyone know how I can get around the ports... (1 Reply)
Discussion started by: PenguinDevil
1 Replies
Login or Register to Ask a Question