static inline const char *pkgResolvedName( pkgXmlNode *rel, const char *tag, const char *ext ) { /* Local helper function to resolve the mapping from a released * package name, as identified from the XML release element "rel", * to its corresponding source or licence package name, according * to the selection of "source" or "licence" specified by "tag", * with "ext" passed a "src" or "lic" respectively. */ const char *refname; const char *retname = NULL; /* First, we retrieve the released package name... */ if( (refname = pkgArchiveName( rel, release_key, 1 )) != NULL ) { /* ...and if successful, look for an explicit reference to * the source or licence package, embedded within the release * specification itself. */ if( (retname = pkgArchiveName( rel, tag, 0 )) == NULL ) { /* When this fails to identify the required mapping, * then we look for a generic reference, defined for * the containing package. */ pkgXmlNode *enc = rel->GetParent(); /* A generic reference may be placed at any nesting * level, between the enclosing package element and * the release to which it relates; thus, starting * at the first enclosing level... */ rel = NULL; while( enc != NULL ) { /* ...enumerate reference specifications of the * appropriate type, examining all children of * the enclosing element. */ unsigned matched = 0; pkgXmlNode *child = enc->GetChildren(); while( child != NULL ) { /* We have a child, which we have not examined... */ if( child->IsElementOfType( tag ) ) { /* ...and it is of the required "tag" type. */ if( matched++ ) /* * We already had a candidate match, so we * diagnose but otherwise this duplicate... */ dmh_notify( DMH_WARNING, "redundant %s specification ignored\n", tag ); else /* This is the first candidate match found, * so we accept it. */ rel = child; } /* Continue examining child elements, until no more * are present at the current nesting level. */ child = child->GetNext(); } /* When we've completed the examination of all children * at a given nesting level, without finding a matching * specification, and that level is still within the * enclosing package element... */ if( (rel == NULL) && ! enc->IsElementOfType( package_key ) ) /* * ...then we extend the search to the next enclosing * level of nesting... */ enc = enc->GetParent(); else /* ...otherwise, we abandon the search. */ enc = NULL; } /* If we've searched all available nesting levels, * and failed to locate the requisite specification... */ if( rel == NULL ) { /* ...then we assume that the requisite tarname * is identical to the release tarname, with the * appropriate "ext" substitution for the package * class identification... */ pkgSpecs resolved( refname ); resolved.SetComponentClass( ext ); /* * ...so, having made the substitution, * we return the resultant tarname, noting * that this automatically allocates space * on the heap, for the returned string. */ return resolved.GetTarName(); } else /* We did find a mappingspecification, so we * extract a tarname template from it. */ retname = rel->GetPropVal( tarname_key, NULL ); } else if( strcmp( retname, value_none ) == 0 ) /* * The package is virtual, or an explicit mapping * specification indicates that there is no related * source or licence package; return NULL to advise * the caller of this. */ return NULL; /* If we get to here, we found a mapping specification; * it may be a template, so resolve any substitutions which * it must inherit from the released package tarname, again * noting that this allocates heap memory for the result. */ retname = pkgAssociateName( retname, refname ); } /* Finally, how ever we resolved the mapping, we return * the result. */ return retname; }
bool simplesocket::connect (void) { long arg; fd_set myset; struct timeval tv; int valopt; socklen_t lon; int res; if (!resolved()) return false; // Stolen from the web -mdc. // Set non-blocking if( (arg = fcntl(_socketfd, F_GETFL, NULL)) < 0) { fprintf(stderr, "Error fcntl(..., F_GETFL) (%s)\n", strerror(errno)); exit(0); } arg |= O_NONBLOCK; if( fcntl(_socketfd, F_SETFL, arg) < 0) { fprintf(stderr, "Error fcntl(..., F_SETFL) (%s)\n", strerror(errno)); exit(0); } // Trying to connect with timeout res = ::connect(_socketfd, _addresses->ai_addr, _addresses->ai_addrlen); if (res < 0) { if (errno == EINPROGRESS) { // fprintf(stderr, "EINPROGRESS in connect() - selecting\n"); do { tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&myset); FD_SET(_socketfd, &myset); res = select(_socketfd+1, NULL, &myset, NULL, &tv); if (res < 0 && errno != EINTR) { //fprintf(stderr, "Error connecting %d - %s\n", errno, strerror(errno)); res =-1; return (res >= 0); } else if (res > 0) { // Socket selected for write lon = sizeof(int); if (getsockopt(_socketfd, SOL_SOCKET, SO_ERROR, (void*)(&valopt), &lon) < 0) { fprintf(stderr, "Error in getsockopt() %d - %s\n", errno, strerror(errno)); exit (0); } // Check the value returned... if (valopt) { // fprintf(stderr, "Error in delayed connection() %d - %s\n", valopt, strerror(valopt)); res = -1; return (res >= 0); } break; } else { // fprintf(stderr, "Timeout in select() - Cancelling!\n"); res = -1; return (res >= 0); } } while (1); } else { //fprintf(stderr, "Error connecting %d - %s\n", errno, strerror(errno)); res = -1; return (res >= 0); } } // Set to blocking mode again... if( (arg = fcntl(_socketfd, F_GETFL, NULL)) < 0) { fprintf(stderr, "Error fcntl(..., F_GETFL) (%s)\n", strerror(errno)); exit(0); } arg &= (~O_NONBLOCK); if( fcntl(_socketfd, F_SETFL, arg) < 0) { fprintf(stderr, "Error fcntl(..., F_SETFL) (%s)\n", strerror(errno)); exit(0); } /* if (res < 0) { if (_debug) cerr << "NO CONNECTION, errno = " << errno << endl; }*/ return (res >= 0); }
const uint32_t RepoAuthType::arrayId() const { assert(mayHaveArrData()); if (resolved()) return m_data.ptr() ? array()->id() : kInvalidArrayId; return reinterpret_cast<uintptr_t>(m_data.ptr()); }