Beispiel #1
0
/**
 * This routine is used with etr_open to find an ET system's tcp host & port.
 * Tries only twice to send broad/multicast packets. Waits 0.1 second for the
 * first response and 1.1 second for the second.
 *
 * @param etname    ET system file name
 * @param ethost    returns name of ET system's host
 * @param port      returns ET system's TCP port
 * @param inetaddr  returns host address as network-byte-ordered, 32-bit unsigned int
 * @param config    configuration passed to et_open
 * @param allETinfo returns a pointer to single structure with all of the ET system's
 *                  response information;
 *                  may be null if all relevant info given in ethost, port, and inetaddr args
 * 
 * @return ET_OK            if successful
 * @return ET_ERROR         failure in select statement
 * @return ET_ERROR_BADARG  NULL arg for ethost, port, or inetaddr
 * @return ET_ERROR_NOMEM   cannot allocate memory
 * @return ET_ERROR_NETWORK error find IP addresses or resolving host name;
 *                          error converting dotted-decimal IP addr to binary;
 *                          error create socket; failure reading socket
 * @return ET_ERROR_SOCKET  error setting socket option
 * @return ET_ERROR_TOOMANY if multiple ET systems responded when policy is to return an error when
 *                          more than one responds.
 * @return ET_ERROR_TIMEOUT if no responses received in allotted time
 */
int et_findserver(const char *etname, char *ethost, int *port,
                  uint32_t *inetaddr, et_open_config *config, et_response **allETinfo)
{
    struct timeval waittime;
    /* wait 0.1 seconds before calling select the first time */
    waittime.tv_sec  = 0;
    waittime.tv_usec = 100000;
  
    return et_findserver2(etname, ethost, port, inetaddr, allETinfo, config, 2, &waittime);
}
Beispiel #2
0
/**
 * This routine is used to quickly see if an ET system
 * is alive by trying to get a response from its UDP
 * broad/multicast thread. This is used only when the
 * ET system is local.
 *
 * @param etname name of ET system to test
 * @return 1 if a response was received, else 0
 */
int et_responds(const char *etname)
{
    int   port;
    char  ethost[ET_MAXHOSTNAMELEN];
    uint32_t inetaddr;
    et_openconfig  openconfig; /* opaque structure */
    et_open_config *config;    /* real structure   */
  
    /* by default we'll broadcast to uname subnet */
    et_open_config_init(&openconfig);
    config = (et_open_config *) openconfig;
  
    /* make sure we contact a LOCAL et system of this name! */
    strcpy(config->host, ET_HOST_LOCAL);
  
    /* send only 1 broadcast with a default maximum .01 sec wait */
    if (et_findserver2(etname, ethost, &port, &inetaddr, NULL, config, 1, NULL) == ET_OK) {
        /* got a response */
        return 1;
    }
  
    /* no response */
    return 0;
}
Beispiel #3
0
/**
 * This routine determines whether we are looking for the ET system locally,
 * locally on some non-pthread-mutex-sharing operating system, or remotely.
 *
 * @param filename    name of ET system file.
 * @param openconfig  ET system open configuration.
 *
 * @returns @ref ET_REMOTE         if looking for a remote ET system.
 * @returns @ref ET_LOCAL          if looking for a local ET system.
 * @returns @ref ET_LOCAL_NOSHARE  if looking for a local ET system without pthread mutex sharing.
 */
int et_findlocality(const char *filename, et_openconfig openconfig) {

    char ethost[ET_IPADDRSTRLEN];
    et_open_config *config = (et_open_config *) openconfig;

    /* if local client opens ET system as remote (thru server) ...
     * This option is for those applications (such as system
     * monitoring) that only want to communication through
     * an ET system's server and not map its shared mem.
     */
    if (config->mode == ET_HOST_AS_REMOTE) {
        return ET_REMOTE;
    }
    /* else if ET system host name is unknown and remote ... */
    else if (strcmp(config->host, ET_HOST_REMOTE) == 0) {
        return ET_REMOTE;
    }
    /* else if ET system is on local host */
    else if ((strcmp(config->host, ET_HOST_LOCAL) == 0) ||
             (strcmp(config->host, "localhost")   == 0))  {
        /* if local operating system can share pthread mutexes ... */
        if (et_sharedmutex() == ET_MUTEX_SHARE) {
            return ET_LOCAL;
        }
        else {
            return ET_LOCAL_NOSHARE;
        }
    }
    /* else if ET system host name is unknown and maybe anywhere ... */
    else if (strcmp(config->host, ET_HOST_ANYWHERE) == 0) {
        int err, port, isLocal;
        uint32_t inetaddr;
        struct timeval waittime;

        waittime.tv_sec  = 0;
        waittime.tv_usec = 10000; /* 0.1 sec */

        /* send only 1 broad/multicast with a 0.1 sec wait */
        err = et_findserver2(filename, ethost, &port, &inetaddr, NULL, config, 1, &waittime, ET_DEBUG_NONE);
        if ((err == ET_ERROR) || (err == ET_ERROR_TIMEOUT)) {
            et_logmsg("ERROR", "et_findlocality, cannot find ET system\n");
            return err;
        }
        else if (err == ET_ERROR_TOOMANY) {
            /* many systems responded */
            et_logmsg("ERROR", "et_findlocality, multiple ET systems responded\n");
            return err;
        }

        etNetNodeIsLocal(ethost, &isLocal);
        if (isLocal) {
            if (et_sharedmutex() == ET_MUTEX_SHARE) {
                return ET_LOCAL;
            }
            else {
                return ET_LOCAL_NOSHARE;
            }
        }

        return ET_REMOTE;
    }
    /* else ET system host name is given ... */
    else {
        int isLocal;
        etNetNodeIsLocal(config->host, &isLocal);
        if (isLocal) {
            if (et_sharedmutex() == ET_MUTEX_SHARE) {
                return ET_LOCAL;
            }
            else {
                return ET_LOCAL_NOSHARE;
            }
        }

        return ET_REMOTE;
    }

    return ET_REMOTE;
}