예제 #1
0
static void swapsyncConnect(void)
{
    char hostname[4096], protocol[4096];
    unsigned short port;

    crNetInit(NULL, NULL);

    if (!crParseURL( render_spu.swap_master_url, protocol, hostname,
                    &port, 9876))
        crError( "Bad URL: %s", render_spu.swap_master_url );

    if (render_spu.is_swap_master)
    {
        int a;

        render_spu.swap_conns = (CRConnection **)crAlloc(
                        render_spu.num_swap_clients*sizeof(CRConnection *));
        for (a=0; a<render_spu.num_swap_clients; a++)
        {
            render_spu.swap_conns[a] = crNetAcceptClient( protocol, hostname, port,
                                                        render_spu.swap_mtu, 1);
        }
    }
    else
    {
        render_spu.swap_conns = (CRConnection **)crAlloc(sizeof(CRConnection *));

        render_spu.swap_conns[0] = crNetConnectToServer(render_spu.swap_master_url,
                                    port, render_spu.swap_mtu, 1);
        if (!render_spu.swap_conns[0])
            crError("Failed connection");
    }
}
예제 #2
0
/**
 * Connect to a server, as specified by the 'name' and 'buffer_size' fields
 * of the CRNetServer parameter.
 * When done, the CrNetServer's conn field will be initialized.
 */
void crNetServerConnect( CRNetServer *ns
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
                , struct VBOXUHGSMI *pHgsmi
#endif
)
{
    ns->conn = crNetConnectToServer( ns->name, DEFAULT_SERVER_PORT,
                                     ns->buffer_size, 0
#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
                , pHgsmi
#endif
            );
}
예제 #3
0
파일: client.c 프로젝트: alown/chromium
CRConnection *crMothershipConnect( void )
{
	const char *mother_server;

	crNetInit( NULL, NULL );

	mother_server = crGetenv( "CRMOTHERSHIP" );
	if (!mother_server)
	{
		crWarning( "Couldn't find the CRMOTHERSHIP environment variable, defaulting to localhost" );
		mother_server = "localhost";
	}

	return crNetConnectToServer( mother_server, DEFAULT_MOTHERSHIP_PORT, 8096, 0 );
}
예제 #4
0
파일: net.c 프로젝트: boompig/chromium
CRConnection *__copy_of_crMothershipConnect( void )
{
	CRConnection *conn;
	const char *mother_server = NULL;

	crNetInit( NULL, NULL );

	mother_server = crGetenv( "CRMOTHERSHIP" );
	if (!mother_server)
	{
		crWarning( "Couldn't find the CRMOTHERSHIP environment variable, defaulting to localhost" );
		mother_server = "localhost";
	}

	conn = crNetConnectToServer( mother_server, DEFAULT_MOTHERSHIP_PORT, 8096, 0 );

	if (!conn)
		crError("Failed to connect to mothership\n");

	return conn;
}
예제 #5
0
파일: main.c 프로젝트: boompig/chromium
static void 
crutInitProxy(char *mothership)
{
    char response[8096];
    char **newserver;
    char* server;
    int mtu;
    
    crutInitAPI(&crut_api, mothership);

    crMothershipIdentifyCRUTProxy( crut_api.mothershipConn, response );

    crMothershipGetCRUTServer( crut_api.mothershipConn, response );
    newserver = crStrSplit(response, " ");
    server = newserver[1];

    mtu = crMothershipGetMTU(crut_api.mothershipConn);
 
    /* set up the connection to recv on */
    crut_proxy.recv_conn = crNetConnectToServer( server, DEFAULT_CRUT_PORT, mtu, 1 );
    crutConnectToClients( &crut_api );

}
예제 #6
0
파일: net.c 프로젝트: L3oV1nc3/VMGL
/**
 * Connect to a server, as specified by the 'name' and 'buffer_size' fields
 * of the CRNetServer parameter.
 * When done, the CrNetServer's conn field will be initialized.
 */
void crNetServerConnect( CRNetServer *ns )
{
	ns->conn = crNetConnectToServer( ns->name, DEFAULT_SERVER_PORT,ns->buffer_size );
}
예제 #7
0
파일: npclient.c 프로젝트: boompig/chromium
int
main(int argc, char *argv[])
{
	const int port = 10000;
	CRConnection *conn[MAX_SERVERS];
	const char *servers[MAX_SERVERS];
	int numServers = 0;
	int bufferSize = 10000;
	int numBuffers = 10;
	int autoMode = 0;
	int size;
	int i, j;

	if (argc < 2) {
		PrintHelp();
		return 0;
	}

	for (i = 1; i < argc; i++) {
		if (!crStrcmp(argv[i], "-a")) {
			autoMode = 1;
		}
		else if (!crStrcmp(argv[i], "-b") && (i + 1 < argc)) {
			bufferSize = crStrToInt(argv[i + 1]);
			i++;
		}
		else if (!crStrcmp(argv[i], "-h")) {
			PrintHelp();
			return 0;
		}
		else if (!crStrcmp(argv[i], "-m") && (i + 1 < argc)) {
			MTU = crStrToInt(argv[i + 1]);
			i++;
		}
		else if (!crStrcmp(argv[i], "-n") && (i + 1 < argc)) {
			numBuffers = crStrToInt(argv[i + 1]);
			i++;
		}
		else if ((argv[i][0] != '-') && (numServers < MAX_SERVERS)) {
			servers[numServers] = argv[i];
			numServers++;
		}
	}

	if (numServers == 0) {
		printf("npclient error: need to specify at least one server\n");
		return 1;
	}

	if (autoMode)
		printf("npclient:  MTU=%d  (automatic buffer sizing)\n", MTU);
	else
		printf("npclient:  MTU=%d  bufferSize=%d  numBuffers=%d\n",
					 MTU, bufferSize, numBuffers);

	MyTimer = crTimerNewTimer();
	crNetInit( ReceiveFunc, CloseFunc );

	printf("npclient:  Connecting to servers\n");
	for (i = 0; i < numServers; i++) {
		conn[i] = crNetConnectToServer(servers[i], (unsigned short) port, MTU, 0);
		if (conn[i]) {
			printf("npclient:  Connection to %s OK.\n", servers[i]);
		}
		else {
			printf("npclient:  Connection to %s failed!\n", servers[i]);
			exit(1);
		}
	}

	printf("npclient:  Testing...\n");

	if (autoMode) {
		bufferSize = 10000;
		for (size = 0; size < 5; size++) {
			double t0, t1, dt, rate;
			double bytes;
			int buffers;

			bytes = 0.0;
			buffers = 0;
			crStartTimer(MyTimer);
			t0 = crTimerTime(MyTimer);

			do {
				for (j = 0; j < numServers; j++) {
					SendOpcodes(conn[j], bufferSize, 0);
				}
				bytes += (double) bufferSize;
				buffers++;
				t1 = crTimerTime(MyTimer);
			} while (t1 - t0 < 5.0);

			crStopTimer(MyTimer);

			dt = t1 - t0;
			rate = (double) bytes / dt / 1000000.0;
			printf("npclient:  %8.3f MB/s (%d bytes / buffer, %d buffers, %d servers)\n",
						 rate, bufferSize, buffers, numServers);
			if (rate < 0.0) {
				char *t = 0;
				*t = 0;
				CRASSERT(rate >= 0.0);
			}
			bufferSize *= 10;
		}
	}
	else {
		double t0, t1, dt, rate;
		double bytes;

		crStartTimer(MyTimer);
		t0 = crTimerTime(MyTimer);
		bytes = 0.0;
		for (i = 0; i < numBuffers; i++) {
			for (j = 0; j < numServers; j++) {
				SendOpcodes(conn[j], bufferSize, 0);
			}
			bytes += (double) bufferSize;
		}
		t1 = crTimerTime(MyTimer);

		dt = t1 - t0;
		rate = (double) bytes / dt / 1000000.0;
		printf("npclient:  %8.3f MB/s (%d bytes / buffer, %d buffers, %d servers)\n",
					 rate, bufferSize, numBuffers, numServers);
	}


	/* Send exit message to servers */
	for (j = 0; j < numServers; j++) {
		SendOpcodes(conn[j], 100, 1);
	}

	for (j = 0; j < numServers; j++) {
		crNetDisconnect(conn[j]);
	}

	printf("npclient:  done!\n");

	return 0;
}
예제 #8
0
/**
 * This is the main routine responsible for replicating our GL state
 * for a new VNC viewer.  Called when we detect that a new VNC viewer
 * has been started.
 * \param ipaddress  the IP address where the new viewer is running.
 */
void
replicatespuReplicate(int ipaddress) 
{
	GET_THREAD(thread);
	struct in_addr addr;
	char *hosturl;
	char *ipstring;
	int i, r_slot;
	int serverPort;

	crDebug("Replicate SPU: Enter replicatespuReplicate(ipaddress=0x%x)", ipaddress);

	replicatespuFlushAll( (void *)thread );

#ifdef CHROMIUM_THREADSAFE_notyet
	crLockMutex(&_ReplicateMutex);
#endif

	/*
	 * Find empty slot.
	 * Slot 0 is the dummy slot (a non-existant server on devnull connection)
	 */
	for (r_slot = 1; r_slot < CR_MAX_REPLICANTS; r_slot++) {
		if (!IS_CONNECTED(replicate_spu.rserver[r_slot].conn))
			break;
	}
	if (r_slot == CR_MAX_REPLICANTS) {
		crWarning("Replicate SPU: no more replicant slots available");
		return;
	}

	/**
	 ** OK, now rserver[r_slot] is free for use.
	 **/

	/*
	 * At this time, we can only support one VNC viewer per host.
	 * Check for that here.
	 */
	for (i = 1; i < CR_MAX_REPLICANTS; i++) {
		if (replicate_spu.ipnumbers[i] == ipaddress) {
			CRConnection *conn = replicate_spu.rserver[i].conn;
			/* If the connection appears to be active, it may actually be a dangling
			 * connection.  Try flushing it now.  If flushing fails, the connection
			 * type will definitely be CR_NO_CONNECTION (which we test below).
			 */
			if (conn) {
				if (conn->type != CR_NO_CONNECTION) {
					FlushConnection(i);
				}
				if (conn->type != CR_NO_CONNECTION) {
					crWarning("Replicate SPU: Can't connect to multiple VNC viewers on one host.");
#if 0
					/* The above test isn't 100% reliable and can prevent successful
					 * restart of a viewer on a host.  For now, just print warning and
					 * continue.
					 */
					return;
#endif
				}
			}
		}
	}

	replicate_spu.ipnumbers[r_slot] = ipaddress;

	serverPort = replicate_spu.chromium_start_port + r_slot;

	if (replicate_spu.vncAvailable) {
		/* Send a ChromiumStart message to the VNC Server.  The VNC Server will
		 * in turn send a ChromiumStart message to all the attached VNC viewers.
		 * The VNC Viewer/Chromium module will tell its crserver that there's
		 * a new OpenGL client.
		 * We pass the mothership port and crserver port in this message.
		 */
		char protocol[100], hostname[1000];
		const char *mothershipURL;
		unsigned short mothershipPort;
		mothershipURL = crGetenv("CRMOTHERSHIP");
		crDebug("Replicate SPU: CRMOTHERSHIP env var = %s", mothershipURL);
		if (mothershipURL)
			crParseURL(mothershipURL, protocol, hostname, &mothershipPort,
								 DEFAULT_MOTHERSHIP_PORT);
		else
			mothershipPort = DEFAULT_MOTHERSHIP_PORT;
		crDebug("Replicate SPU: Sending ChromiumStart msg to VNC server, port=%d",
						serverPort);

		if (!XVncChromiumStart(replicate_spu.glx_display, ipaddress,
													 serverPort, mothershipPort)) {
			 crWarning("Replicate SPU: XVncChromiumStart() call failed");
		}
	}

	addr.s_addr = ipaddress;
	ipstring = inet_ntoa(addr);
	hosturl = crAlloc(crStrlen(ipstring) + 9);
	sprintf(hosturl, "tcpip://%s", ipstring);

	crDebug("Replicate SPU attaching to %s on port %d", hosturl, serverPort);

	/* connect to the remote VNC server */
	replicate_spu.rserver[r_slot].name = crStrdup( replicate_spu.name );
	replicate_spu.rserver[r_slot].buffer_size = replicate_spu.buffer_size;
	replicate_spu.rserver[r_slot].conn
		= crNetConnectToServer( hosturl, serverPort,
														replicate_spu.rserver[r_slot].buffer_size, 1);

	if (!replicate_spu.rserver[r_slot].conn) {
		crWarning("Replicate SPU: failed to connect to %s", hosturl);
		return;
	}

	CRASSERT(replicate_spu.rserver[r_slot].conn);

	/*
	 * Setup the the packer flush function.  While replicating state to
	 * a particular server we definitely don't want to do any broadcast
	 * flushing!
	 */
	crPackFlushFunc( thread->packer, replicatespuFlushOnePacker );
	crPackSendHugeFunc( thread->packer, replicatespuHugeOnePacker );

	NewServerIndex = r_slot;

	/*
	 * Create server-side windows and contexts by walking tables of app windows
	 * and contexts.  Note that windows can be created in random order,
	 * but contexts must be created in the order they were originally
	 * created, or shared contexts will break.
	 */
	crHashtableWalk(replicate_spu.windowTable, replicatespuReplicateWindow, thread);
	crListApply(replicate_spu.contextList, replicatespuReplicateContext, thread);

	/* MakeCurrent, the current context */
	if (thread->currentContext) {
		int serverWindow = thread->currentContext->currentWindow->id[r_slot];
		int serverContext = thread->currentContext->rserverCtx[r_slot];
		if (replicate_spu.swap)
			crPackMakeCurrentSWAP(serverWindow, 0, serverContext);
	 	else
			crPackMakeCurrent(serverWindow, 0, serverContext);

		crStateMakeCurrent( thread->currentContext->State );
	}

	/*
	 * Set window sizes
	 */
	crHashtableWalk(replicate_spu.windowTable, replicatespuResizeWindows, thread);
	replicatespuFlushOne(thread, NewServerIndex);

	/*
	 * restore normal, broadcasting packer flush function now.
	 */
	crPackFlushFunc( thread->packer, replicatespuFlush );
	crPackSendHugeFunc( thread->packer, replicatespuHuge );

	NewServerIndex = -1;

	crDebug("Replicate SPU: leaving replicatespuReplicate");

#ifdef CHROMIUM_THREADSAFE_notyet
	crUnlockMutex(&_ReplicateMutex);
#endif
}