libs/stream_message/src/service.cxx
// ===========================================================================
// Register this service on the given listening socket.
// -- code borrowed from paraset/src/serverspy/serverspy.cpp --
//
Register this service on the given listening socket.
Register this service on the given listening socket .
bool ServiceName::doRegister(int socket) const
{
    if (!initialize()) {
	return false;
    }
#ifdef DEBUG19953
    fprintf(stderr, "doRegister contacting name server.\n");
    fflush(stderr);
#endif
    int test_sock = ConnectToNameServer();
    if (test_sock < 0) {
	if (start_name_server() != 0) {
	    for (int count = 0; count < 3000; count++) {
		test_sock = ConnectToNameServer();
		if (test_sock >= 0) {
		    break;
		}
	    }
	}
    }
    if (test_sock >= 0) {
	closesocket (test_sock);
    } else {
	fprintf(stderr, "Unable to contact or start nameserver.  Please run nameserv by hand.\n");
	fflush(stderr);
	return false;
    }
    struct sockaddr_in sock_info;
    socklen_t len = sizeof(sock_info);
    int res = -1;
    int getsockres = getsockname(socket, (struct sockaddr *)&sock_info, &len);
    if(getsockres == 0) {
#ifdef DEBUG19953
	fprintf(stderr, "doRegister calling NameServerRegisterService for %s.\n", name);
	fflush(stderr);
#endif
	res = NameServerRegisterService(name, ntohs(sock_info.sin_port));
    }
    if (res == 1) {
    } else {
	fprintf(stderr, "Unable to register %s service: getsockname code %d, register code %d.\n", name, getsockres, res);
	fflush(stderr);
	return false;
    }
    return true;
}
bool ServiceName :: doRegister ( int socket ) const { if ( ! initialize ( ) ) { return false ; } #ifdef DEBUG19953 fprintf ( stderr , " \n " ) ; fflush ( stderr ) ; #endif int test_sock = ConnectToNameServer ( ) ; if ( test_sock < 0 ) { if ( start_name_server ( ) != 0 ) { for ( int count = 0 ; count < 3000 ; count ++ ) { test_sock = ConnectToNameServer ( ) ; if ( test_sock >= 0 ) { break ; } } } } if ( test_sock >= 0 ) { closesocket ( test_sock ) ; } else { fprintf ( stderr , " \n " ) ; fflush ( stderr ) ; return false ; } struct sockaddr_in sock_info ; socklen_t len = sizeof ( sock_info ) ; int res = -1 ; int getsockres = getsockname ( socket , ( struct sockaddr * ) & sock_info , & len ) ; if ( getsockres == 0 ) { #ifdef DEBUG19953 fprintf ( stderr , " \n " , name ) ; fflush ( stderr ) ; #endif res = NameServerRegisterService ( name , ntohs ( sock_info . sin_port ) ) ; } if ( res == 1 ) { } else { fprintf ( stderr , " \n " , name , getsockres , res ) ; fflush ( stderr ) ; return false ; } return true ; }
Register this service on the given listening socket.
Register this service on the given listening socket .
// First, make sure that nameserv is up and accepting connections // Couldn't connect, so try to start nameserv // Wait for nameserv to start accepting connections // Next, register service // fprintf(stderr, "Successfully registered %s service.\n", name); fflush(stderr);