int wd_hb_send(int sock, WdHbPacket * pkt, int len, const char * host) { int rtn; struct sockaddr_in addr; struct hostent *hp; WdHbPacket buf; if (!host || !strlen(host)) { pool_error("wd_hb_send: host name is empty"); return -1; } hp = gethostbyname(host); if ((hp == NULL) || (hp->h_addrtype != AF_INET)) { pool_error("wd_hb_send: gethostbyname() failed: %s host: %s", hstrerror(h_errno), host); return -1; } memmove((char *) &(addr.sin_addr), (char *) hp->h_addr, hp->h_length); addr.sin_family = AF_INET; addr.sin_port = htons(pool_config->wd_heartbeat_port); hton_wd_hb_packet(&buf, pkt); if ((rtn = sendto(sock, &buf, sizeof(WdHbPacket), 0, (struct sockaddr *)&addr, sizeof(addr))) != len) { pool_error("wd_hb_send: failed to sent packet to %s", host); return WD_NG; } pool_debug("wd_hb_send: send %d byte packet", rtn); return WD_OK; }
/* send heartbeat signal */ void wd_hb_send(int sock, WdHbPacket * pkt, int len, const char * host, const int port) { int rtn; struct sockaddr_in addr; struct hostent *hp; WdHbPacket buf; if (!host || !strlen(host)) ereport(ERROR, (errmsg("failed to send watchdog heartbeat. host name is empty"))); hp = gethostbyname(host); if ((hp == NULL) || (hp->h_addrtype != AF_INET)) ereport(ERROR, (errmsg("failed to send watchdog heartbeat, gethostbyname() failed"), errdetail("gethostbyname on \"%s\" failed with reason: \"%s\"",host, hstrerror(h_errno)))); memmove((char *) &(addr.sin_addr), (char *) hp->h_addr, hp->h_length); addr.sin_family = AF_INET; addr.sin_port = htons(port); hton_wd_hb_packet(&buf, pkt); if ((rtn = sendto(sock, &buf, sizeof(WdHbPacket), 0, (struct sockaddr *)&addr, sizeof(addr))) != len) { ereport(ERROR, (errmsg("failed to send watchdog heartbeat, sendto failed"), errdetail("sending packet to \"%s\" failed with reason: \"%s\"",host, strerror(errno)))); } ereport(DEBUG2, (errmsg("watchdog heartbeat: send %d byte packet", rtn))); }