@@ -1653,7 +1653,7 @@ pq_setkeepaliveswin32(Port *port, int idle, int interval)
1653
1653
int
1654
1654
pq_getkeepalivesidle (Port * port )
1655
1655
{
1656
- #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE ) || defined(WIN32 )
1656
+ #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE_THRESHOLD ) || defined( TCP_KEEPALIVE ) || defined(WIN32 )
1657
1657
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1658
1658
return 0 ;
1659
1659
@@ -1665,23 +1665,34 @@ pq_getkeepalivesidle(Port *port)
1665
1665
#ifndef WIN32
1666
1666
ACCEPT_TYPE_ARG3 size = sizeof (port -> default_keepalives_idle );
1667
1667
1668
- #ifdef TCP_KEEPIDLE
1668
+ #if defined(TCP_KEEPIDLE )
1669
+ /* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
1669
1670
if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPIDLE ,
1670
1671
(char * ) & port -> default_keepalives_idle ,
1671
1672
& size ) < 0 )
1672
1673
{
1673
1674
elog (LOG , "getsockopt(TCP_KEEPIDLE) failed: %m" );
1674
1675
port -> default_keepalives_idle = -1 ; /* don't know */
1675
1676
}
1676
- #else
1677
+ #elif defined(TCP_KEEPALIVE_THRESHOLD )
1678
+ /* TCP_KEEPALIVE_THRESHOLD is the name of this option on Solaris */
1679
+ if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE_THRESHOLD ,
1680
+ (char * ) & port -> default_keepalives_idle ,
1681
+ & size ) < 0 )
1682
+ {
1683
+ elog (LOG , "getsockopt(TCP_KEEPALIVE_THRESHOLD) failed: %m" );
1684
+ port -> default_keepalives_idle = -1 ; /* don't know */
1685
+ }
1686
+ #else /* must have TCP_KEEPALIVE */
1687
+ /* TCP_KEEPALIVE is the name of this option on macOS */
1677
1688
if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE ,
1678
1689
(char * ) & port -> default_keepalives_idle ,
1679
1690
& size ) < 0 )
1680
1691
{
1681
1692
elog (LOG , "getsockopt(TCP_KEEPALIVE) failed: %m" );
1682
1693
port -> default_keepalives_idle = -1 ; /* don't know */
1683
1694
}
1684
- #endif /* TCP_KEEPIDLE */
1695
+ #endif /* KEEPIDLE/KEEPALIVE_THRESHOLD/KEEPALIVE */
1685
1696
#else /* WIN32 */
1686
1697
/* We can't get the defaults on Windows, so return "don't know" */
1687
1698
port -> default_keepalives_idle = -1 ;
@@ -1700,7 +1711,8 @@ pq_setkeepalivesidle(int idle, Port *port)
1700
1711
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1701
1712
return STATUS_OK ;
1702
1713
1703
- #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE ) || defined(SIO_KEEPALIVE_VALS )
1714
+ /* check SIO_KEEPALIVE_VALS here, not just WIN32, as some toolchains lack it */
1715
+ #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE_THRESHOLD ) || defined(TCP_KEEPALIVE ) || defined(SIO_KEEPALIVE_VALS )
1704
1716
if (idle == port -> keepalives_idle )
1705
1717
return STATUS_OK ;
1706
1718
@@ -1719,14 +1731,24 @@ pq_setkeepalivesidle(int idle, Port *port)
1719
1731
if (idle == 0 )
1720
1732
idle = port -> default_keepalives_idle ;
1721
1733
1722
- #ifdef TCP_KEEPIDLE
1734
+ #if defined(TCP_KEEPIDLE )
1735
+ /* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
1723
1736
if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPIDLE ,
1724
1737
(char * ) & idle , sizeof (idle )) < 0 )
1725
1738
{
1726
1739
elog (LOG , "setsockopt(TCP_KEEPIDLE) failed: %m" );
1727
1740
return STATUS_ERROR ;
1728
1741
}
1729
- #else
1742
+ #elif defined(TCP_KEEPALIVE_THRESHOLD )
1743
+ /* TCP_KEEPALIVE_THRESHOLD is the name of this option on Solaris */
1744
+ if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE_THRESHOLD ,
1745
+ (char * ) & idle , sizeof (idle )) < 0 )
1746
+ {
1747
+ elog (LOG , "setsockopt(TCP_KEEPALIVE_THRESHOLD) failed: %m" );
1748
+ return STATUS_ERROR ;
1749
+ }
1750
+ #else /* must have TCP_KEEPALIVE */
1751
+ /* TCP_KEEPALIVE is the name of this option on macOS */
1730
1752
if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE ,
1731
1753
(char * ) & idle , sizeof (idle )) < 0 )
1732
1754
{
@@ -1739,7 +1761,7 @@ pq_setkeepalivesidle(int idle, Port *port)
1739
1761
#else /* WIN32 */
1740
1762
return pq_setkeepaliveswin32 (port , idle , port -> keepalives_interval );
1741
1763
#endif
1742
- #else /* TCP_KEEPIDLE || SIO_KEEPALIVE_VALS */
1764
+ #else /* no way to set it */
1743
1765
if (idle != 0 )
1744
1766
{
1745
1767
elog (LOG , "setting the keepalive idle time is not supported" );
@@ -1789,7 +1811,7 @@ pq_setkeepalivesinterval(int interval, Port *port)
1789
1811
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1790
1812
return STATUS_OK ;
1791
1813
1792
- #if defined(TCP_KEEPINTVL ) || defined (SIO_KEEPALIVE_VALS )
1814
+ #if defined(TCP_KEEPINTVL ) || defined(SIO_KEEPALIVE_VALS )
1793
1815
if (interval == port -> keepalives_interval )
1794
1816
return STATUS_OK ;
1795
1817
0 commit comments