MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / createSentinelAddr

Function createSentinelAddr

src/sentinel.cpp:601–619  ·  view source on GitHub ↗

Create a sentinelAddr object and return it on success. * On error NULL is returned and errno is set to: * ENOENT: Can't resolve the hostname. * EINVAL: Invalid port number. */

Source from the content-addressed store, hash-verified

599 * EINVAL: Invalid port number.
600 */
601sentinelAddr *createSentinelAddr(char *hostname, int port) {
602 char ip[NET_IP_STR_LEN];
603 sentinelAddr *sa;
604
605 if (port < 0 || port > 65535) {
606 errno = EINVAL;
607 return NULL;
608 }
609 if (anetResolve(NULL,hostname,ip,sizeof(ip),
610 sentinel.resolve_hostnames ? ANET_NONE : ANET_IP_ONLY) == ANET_ERR) {
611 errno = ENOENT;
612 return NULL;
613 }
614 sa = (sentinelAddr*)zmalloc(sizeof(*sa), MALLOC_LOCAL);
615 sa->hostname = sdsnew(hostname);
616 sa->ip = sdsnew(ip);
617 sa->port = port;
618 return sa;
619}
620
621/* Return a duplicate of the source address. */
622sentinelAddr *dupSentinelAddr(sentinelAddr *src) {

Calls 3

anetResolveFunction · 0.85
zmallocFunction · 0.85
sdsnewFunction · 0.85

Tested by

no test coverage detected