/** * used for debugging and giving info to the user. */ void renderspuMakeVisString( GLbitfield visAttribs, char *s ) { s[0] = 0; if (visAttribs & CR_RGB_BIT) crStrcat(s, "RGB"); if (visAttribs & CR_ALPHA_BIT) crStrcat(s, "A"); if (visAttribs & CR_DOUBLE_BIT) crStrcat(s, ", Doublebuffer"); if (visAttribs & CR_STEREO_BIT) crStrcat(s, ", Stereo"); if (visAttribs & CR_DEPTH_BIT) crStrcat(s, ", Z"); if (visAttribs & CR_STENCIL_BIT) crStrcat(s, ", Stencil"); if (visAttribs & CR_ACCUM_BIT) crStrcat(s, ", Accum"); if (visAttribs & CR_MULTISAMPLE_BIT) crStrcat(s, ", Multisample"); if (visAttribs & CR_OVERLAY_BIT) crStrcat(s, ", Overlay"); if (visAttribs & CR_PBUFFER_BIT) crStrcat(s, ", PBuffer"); }
/* Intersect two strings on a word-by-word basis (separated by spaces). * We typically use this to intersect OpenGL extension strings. * Example: if s1 = "apple banana plum pear" * and s2 = "plum banana orange" * then return "banana plum" (or "plum banana"). */ char *crStrIntersect( const char *s1, const char *s2 ) { int len1, len2; int resultLen; char *result; char **exten1, **exten2; int i, j; if (!s1 || !s2) { /* null strings, no intersection */ return NULL; } len1 = crStrlen(s1); len2 = crStrlen(s2); /* allocate storage for result (a conservative estimate) */ resultLen = ((len1 > len2) ? len1 : len2) + 2; result = (char *) crAlloc(resultLen); if (!result) { return NULL; } result[0] = 0; /* split s1 and s2 at space chars */ exten1 = crStrSplit(s1, " "); exten2 = crStrSplit(s2, " "); for (i = 0; exten1[i]; i++) { for (j = 0; exten2[j]; j++) { if (crStrcmp(exten1[i], exten2[j]) == 0) { /* found an intersection, append to result */ crStrcat(result, exten1[i]); crStrcat(result, " "); break; } } } /* free split strings */ crFreeStrings( exten1 ); crFreeStrings( exten2 ); /*CRASSERT(crStrlen(result) < resultLen);*/ /* all done! */ return result; }
/** * Send a mesage to the mothership and get a response. * \return 1 if OK, 0 if error */ int crMothershipSendString( CRConnection *conn, char *response_buf, const char *str, ... ) { va_list args; static char txt[8092]; va_start(args, str); vsprintf( txt, str, args ); va_end(args); crStrcat( txt, "\n" ); crNetSendExact( conn, txt, crStrlen(txt) ); if (response_buf) { return crMothershipReadResponse( conn, response_buf ); } else { char devnull[1024]; return crMothershipReadResponse( conn, devnull ); } }
/** * Establish a connection with a server. * \param server the server to connect to, in the form * "protocol://servername:port" where the port specifier * is optional and if the protocol is missing it is assumed * to be "tcpip". * \param default_port the port to connect to, if port not specified in the * server URL string. * \param mtu desired maximum transmission unit size (in bytes) * \param broker either 1 or 0 to indicate if connection is brokered through * the mothership */ CRConnection * crNetConnectToServer( const char *server, unsigned short default_port, int mtu, int broker #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) , struct VBOXUHGSMI *pHgsmi #endif ) { char hostname[4096], protocol[4096]; unsigned short port; CRConnection *conn; crDebug( "In crNetConnectToServer( \"%s\", port=%d, mtu=%d, broker=%d )", server, default_port, mtu, broker ); CRASSERT( cr_net.initialized ); if (mtu < CR_MINIMUM_MTU) { crError( "You tried to connect to server \"%s\" with an mtu of %d, " "but the minimum MTU is %d", server, mtu, CR_MINIMUM_MTU ); } /* Tear the URL apart into relevant portions. */ if ( !crParseURL( server, protocol, hostname, &port, default_port ) ) { crError( "Malformed URL: \"%s\"", server ); } /* If the host name is "localhost" replace it with the _real_ name * of the localhost. If we don't do this, there seems to be * confusion in the mothership as to whether or not "localhost" and * "foo.bar.com" are the same machine. */ if (crStrcmp(hostname, "localhost") == 0) { int rv = crGetHostname(hostname, 4096); CRASSERT(rv == 0); (void) rv; } /* XXX why is this here??? I think it could be moved into the * crTeacConnection() function with no problem. I.e. change the * connection's port, teac_rank and tcscomm_rank there. (BrianP) */ if ( !crStrcmp( protocol, "quadrics" ) || !crStrcmp( protocol, "quadrics-tcscomm" ) ) { /* For Quadrics protocols, treat "port" as "rank" */ if ( port > CR_QUADRICS_HIGHEST_RANK ) { crWarning( "Invalid crserver rank, %d, defaulting to %d\n", port, CR_QUADRICS_LOWEST_RANK ); port = CR_QUADRICS_LOWEST_RANK; } } crDebug( "Connecting to %s on port %d, with protocol %s", hostname, port, protocol ); #ifdef SDP_SUPPORT /* This makes me ill, but we need to "fix" the hostname for sdp. MCH */ if (!crStrcmp(protocol, "sdp")) { char* temp; temp = strtok(hostname, "."); crStrcat(temp, crGetSDPHostnameSuffix()); crStrcpy(hostname, temp); crDebug("SDP rename hostname: %s", hostname); } #endif conn = (CRConnection *) crCalloc( sizeof(*conn) ); if (!conn) return NULL; /* init the non-zero fields */ conn->type = CR_NO_CONNECTION; /* we don't know yet */ conn->recv_credits = CR_INITIAL_RECV_CREDITS; conn->hostname = crStrdup( hostname ); conn->port = port; conn->mtu = mtu; conn->buffer_size = mtu; conn->broker = broker; conn->endianness = crDetermineEndianness(); /* XXX why are these here??? Move them into the crTeacConnection() * and crTcscommConnection() functions. */ conn->teac_id = -1; conn->teac_rank = port; conn->tcscomm_id = -1; conn->tcscomm_rank = port; crInitMessageList(&conn->messageList); /* now, just dispatch to the appropriate protocol's initialization functions. */ InitConnection(conn, protocol, mtu #if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST) , pHgsmi #endif ); if (!crNetConnect( conn )) { crDebug("crNetConnectToServer() failed, freeing the connection"); #ifdef CHROMIUM_THREADSAFE crFreeMutex( &conn->messageList.lock ); #endif conn->Disconnect(conn); crFree( conn ); return NULL; } crDebug( "Done connecting to %s (swapping=%d)", server, conn->swap ); return conn; }
static void crSDPAccept( CRConnection *conn, const char *hostname, unsigned short port ) { int err; socklen_t addr_length; struct sockaddr_in servaddr; struct sockaddr addr; struct hostent *host; struct in_addr sin_addr; if (port != last_port) { /* with the new OOB stuff, we can have multiple ports being * accepted on, so we need to redo the server socket every time. */ cr_sdp.server_sock = socket( AF_INET_SDP, SOCK_STREAM, 0 ); if ( cr_sdp.server_sock == -1 ) { err = crSDPErrno( ); crError( "Couldn't create socket: %s", crSDPErrorString( err ) ); } spankSocket( cr_sdp.server_sock ); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = INADDR_ANY; servaddr.sin_port = htons( port ); if ( bind( cr_sdp.server_sock, (struct sockaddr *) &servaddr, sizeof(servaddr) ) ) { err = crSDPErrno( ); crError( "Couldn't bind to socket (port=%d): %s", port, crSDPErrorString( err ) ); } last_port = port; if ( listen( cr_sdp.server_sock, 100 /* max pending connections */ ) ) { err = crSDPErrno( ); crError( "Couldn't listen on socket: %s", crSDPErrorString( err ) ); } } if (conn->broker) { CRConnection *mother; char response[8096]; char my_hostname[256]; char *temp; mother = __copy_of_crMothershipConnect( ); if (!hostname) { if ( crGetHostname( my_hostname, sizeof( my_hostname ) ) ) { crError( "Couldn't determine my own hostname in crSDPAccept!" ); } } else crStrcpy(my_hostname, hostname); /* Hack hostname, YUCK!!! */ temp = strtok(my_hostname, "."); crStrcat(temp, crGetSDPHostnameSuffix()); (void) temp; if (!__copy_of_crMothershipSendString( mother, response, "acceptrequest sdp %s %d %d", temp, conn->port, conn->endianness ) ) { crError( "Mothership didn't like my accept request" ); } __copy_of_crMothershipDisconnect( mother ); sscanf( response, "%u", &(conn->id) ); } addr_length = sizeof( addr ); conn->sdp_socket = accept( cr_sdp.server_sock, (struct sockaddr *) &addr, &addr_length ); if (conn->sdp_socket == -1) { err = crSDPErrno( ); crError( "Couldn't accept client: %s", crSDPErrorString( err ) ); } sin_addr = ((struct sockaddr_in *) &addr)->sin_addr; host = gethostbyaddr( (char *) &sin_addr, sizeof( sin_addr), AF_INET_SDP ); if (host == NULL ) { char *temp = inet_ntoa( sin_addr ); conn->hostname = crStrdup( temp ); } else { char *temp; conn->hostname = crStrdup( host->h_name ); temp = conn->hostname; while (*temp && *temp != '.' ) temp++; *temp = '\0'; } #ifdef RECV_BAIL_OUT err = sizeof(unsigned int); if ( getsockopt( conn->sdp_socket, SOL_SOCKET, SO_RCVBUF, (char *) &conn->krecv_buf_size, &err ) ) { conn->krecv_buf_size = 0; } #endif crDebug( "Accepted connection from \"%s\".", conn->hostname ); }