Exemple #1
0
 ~UdpReceiverEntry()
 {
     if (retryData) delete[] retryData; // MORE - should I release the values pointed to as well - not a big deal as quitting anyway...
     if (send_flow_socket) send_flow_socket->Release();
     if (data_socket) data_socket->Release();
     if (output_queue) delete [] output_queue;
     if (maxPktsPerQ) delete [] maxPktsPerQ;
 }
int ReceiveThread::run()
{
    ISocket * socket = ISocket::create(3456);
    ISocket * client = socket->accept();
    StringBuffer result;
    readResults(client, parallelBlocked, false, result, nullptr, 0);
    client->Release();
    socket->Release();
    finishedReading.signal();
    return 0;
}
 virtual void Unbind()
 {
     if (serversock) {
         ISocket *sock = serversock;
         serversock = NULL;
         try {
             sock->close();
         }
         catch (IJSOCK_Exception *) {
             sock->Release();
             throw; // TBD
         }
         sock->Release();
     }
 }
ISmartSocket *CSmartSocketFactory::connect_timeout( unsigned timeoutms)
{
    SmartSocketEndpoint *ss = nextSmartEndpoint();
    if (!ss)
        throw createSmartSocketException(0, "smartsocket failed to get nextEndpoint");

    ISocket *sock = NULL;
    SocketEndpoint ep;
    try 
    {
        {
            synchronized block(lock);
            ss->checkHost(dnsInterval);
            ep = ss->ep;
        }
        if (timeoutms)
            sock = ISocket::connect_timeout(ep, timeoutms);
        else
            sock = ISocket::connect(ep);

        return new CSmartSocket(sock, ep, this);
    }
    catch (IException *e)
    {
        StringBuffer s("CSmartSocketFactory::connect ");
        ep.getUrlStr(s);
        EXCLOG(e,s.str());
        ss->status=false;
        if (sock)
            sock->Release();
        throw;
    }
}
void CThorTransferGroup::send(SocketEndpoint &ep, CThorRowArray & group)
{
    ISocket * sendSkt = ISocket::connect_wait(ep, 360*120*1000); // give it plenty of time, sequential in nature *could* be delayed in other side listening
    sendSkt->set_block_mode(BF_SYNC_TRANSFER_PULL,0,TRANSFER_TIMEOUT);
    MemoryBuffer mb;
    group.serialize(serializer,mb,false);
    sendSkt->send_block(mb.toByteArray(),mb.length());
    sendSkt->close();
    sendSkt->Release();
}
HRESULT CServer::OnConnectionClosed()
{
   // retrieve socket 
   CCOMSocketServer::Socket *pSocket = m_pSocketServer->GetSocket();

   if (pSocket)
   {
      ISocket *pISocket = reinterpret_cast<ISocket *>(pSocket->GetUserPtr());

      if (pISocket)
      {
         Fire_OnConnectionClosed(pISocket);

         pISocket->Release();
      }

      pSocket->SetUserPtr(0);

      return S_OK;
   }

   return Error(L"Internal error: failed to obtain ISocket");
}
void DoServerConnect()
{
#if defined( USE_MPI )
	ISocket *pSocket = CreateIPSocket();
	if ( !pSocket )
	{
		printf( "Error creating a socket.\n" );
		assert( false );
		return;
	}
	else if ( !pSocket->BindToAny( VMPI_SERVICE_PORT ) )
	{	
		printf( "Error binding a socket to port %d.\n", VMPI_SERVICE_PORT );
		assert( false );
		return;
	}

	printf( "Waiting for jobs...\n" );
	while ( 1 )
	{
		// Any incoming packets?
		char data[2048];
		CIPAddr ipFrom;
		int len = pSocket->RecvFrom( data, sizeof( data ), &ipFrom );
		if ( len > 3 )
		{
			bf_read buf( data, len );
			if ( buf.ReadByte() == VMPI_PROTOCOL_VERSION )
			{
				if ( buf.ReadByte() == VMPI_LOOKING_FOR_WORKERS )
				{
					// Read the listen port.
					int iListenPort = buf.ReadLong();

					static char ipString[128];
					_snprintf( ipString, sizeof( ipString ), "%d.%d.%d.%d:%d", ipFrom.ip[0], ipFrom.ip[1], ipFrom.ip[2], ipFrom.ip[3], iListenPort );
					
					int argc = 3;
					char *testargv[3];
					testargv[0] = "<supposedly the executable name!>";
					testargv[1] = "-mpi_worker";
					testargv[2] = ipString;
					
					char **argv = testargv;
					if ( MPI_Init( &argc, &argv ) )
					{
						assert( false );
					}
					MPI_Comm_rank( MPI_COMM_WORLD, &myProcId );

					int nProcs;
					MPI_Comm_size( MPI_COMM_WORLD, &nProcs );
					if ( nProcs != 2 )
					{
						assert( false );
					}
					break;
				}
			}
		}

		Sleep( 100 );		
	}

	pSocket->Release();
#else
	// Try to connect, or listen.
	ITCPListenSocket *pListen = CreateTCPListenSocket( g_iPortNum );
	if ( !pListen )
	{
		assert( false );
	}

	printf( "Server listening...\n" );

	CIPAddr addr;
	ITCPSocket *pTCPSocket = TCPSocket_ListenForOneConnection( pListen, &addr, 50000 );
	if ( !pTCPSocket )
	{
		assert( false );
	}
	pListen->Release();

	printf( "Server connected...\n ");
	g_pSocket = pTCPSocket;
#endif
}