@@ -1676,7 +1676,7 @@ pq_setkeepaliveswin32(Port *port, int idle, int interval)
1676
1676
int
1677
1677
pq_getkeepalivesidle (Port * port )
1678
1678
{
1679
- #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE ) || defined(WIN32 )
1679
+ #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE_THRESHOLD ) || defined( TCP_KEEPALIVE ) || defined(WIN32 )
1680
1680
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1681
1681
return 0 ;
1682
1682
@@ -1688,23 +1688,34 @@ pq_getkeepalivesidle(Port *port)
1688
1688
#ifndef WIN32
1689
1689
ACCEPT_TYPE_ARG3 size = sizeof (port -> default_keepalives_idle );
1690
1690
1691
- #ifdef TCP_KEEPIDLE
1691
+ #if defined(TCP_KEEPIDLE )
1692
+ /* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
1692
1693
if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPIDLE ,
1693
1694
(char * ) & port -> default_keepalives_idle ,
1694
1695
& size ) < 0 )
1695
1696
{
1696
1697
elog (LOG , "getsockopt(TCP_KEEPIDLE) failed: %m" );
1697
1698
port -> default_keepalives_idle = -1 ; /* don't know */
1698
1699
}
1699
- #else
1700
+ #elif defined(TCP_KEEPALIVE_THRESHOLD )
1701
+ /* TCP_KEEPALIVE_THRESHOLD is the name of this option on Solaris */
1702
+ if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE_THRESHOLD ,
1703
+ (char * ) & port -> default_keepalives_idle ,
1704
+ & size ) < 0 )
1705
+ {
1706
+ elog (LOG , "getsockopt(TCP_KEEPALIVE_THRESHOLD) failed: %m" );
1707
+ port -> default_keepalives_idle = -1 ; /* don't know */
1708
+ }
1709
+ #else /* must have TCP_KEEPALIVE */
1710
+ /* TCP_KEEPALIVE is the name of this option on macOS */
1700
1711
if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE ,
1701
1712
(char * ) & port -> default_keepalives_idle ,
1702
1713
& size ) < 0 )
1703
1714
{
1704
1715
elog (LOG , "getsockopt(TCP_KEEPALIVE) failed: %m" );
1705
1716
port -> default_keepalives_idle = -1 ; /* don't know */
1706
1717
}
1707
- #endif /* TCP_KEEPIDLE */
1718
+ #endif /* KEEPIDLE/KEEPALIVE_THRESHOLD/KEEPALIVE */
1708
1719
#else /* WIN32 */
1709
1720
/* We can't get the defaults on Windows, so return "don't know" */
1710
1721
port -> default_keepalives_idle = -1 ;
@@ -1723,7 +1734,8 @@ pq_setkeepalivesidle(int idle, Port *port)
1723
1734
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1724
1735
return STATUS_OK ;
1725
1736
1726
- #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE ) || defined(SIO_KEEPALIVE_VALS )
1737
+ /* check SIO_KEEPALIVE_VALS here, not just WIN32, as some toolchains lack it */
1738
+ #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE_THRESHOLD ) || defined(TCP_KEEPALIVE ) || defined(SIO_KEEPALIVE_VALS )
1727
1739
if (idle == port -> keepalives_idle )
1728
1740
return STATUS_OK ;
1729
1741
@@ -1742,14 +1754,24 @@ pq_setkeepalivesidle(int idle, Port *port)
1742
1754
if (idle == 0 )
1743
1755
idle = port -> default_keepalives_idle ;
1744
1756
1745
- #ifdef TCP_KEEPIDLE
1757
+ #if defined(TCP_KEEPIDLE )
1758
+ /* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
1746
1759
if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPIDLE ,
1747
1760
(char * ) & idle , sizeof (idle )) < 0 )
1748
1761
{
1749
1762
elog (LOG , "setsockopt(TCP_KEEPIDLE) failed: %m" );
1750
1763
return STATUS_ERROR ;
1751
1764
}
1752
- #else
1765
+ #elif defined(TCP_KEEPALIVE_THRESHOLD )
1766
+ /* TCP_KEEPALIVE_THRESHOLD is the name of this option on Solaris */
1767
+ if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE_THRESHOLD ,
1768
+ (char * ) & idle , sizeof (idle )) < 0 )
1769
+ {
1770
+ elog (LOG , "setsockopt(TCP_KEEPALIVE_THRESHOLD) failed: %m" );
1771
+ return STATUS_ERROR ;
1772
+ }
1773
+ #else /* must have TCP_KEEPALIVE */
1774
+ /* TCP_KEEPALIVE is the name of this option on macOS */
1753
1775
if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE ,
1754
1776
(char * ) & idle , sizeof (idle )) < 0 )
1755
1777
{
@@ -1762,7 +1784,7 @@ pq_setkeepalivesidle(int idle, Port *port)
1762
1784
#else /* WIN32 */
1763
1785
return pq_setkeepaliveswin32 (port , idle , port -> keepalives_interval );
1764
1786
#endif
1765
- #else /* TCP_KEEPIDLE || SIO_KEEPALIVE_VALS */
1787
+ #else /* no way to set it */
1766
1788
if (idle != 0 )
1767
1789
{
1768
1790
elog (LOG , "setting the keepalive idle time is not supported" );
@@ -1812,7 +1834,7 @@ pq_setkeepalivesinterval(int interval, Port *port)
1812
1834
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1813
1835
return STATUS_OK ;
1814
1836
1815
- #if defined(TCP_KEEPINTVL ) || defined (SIO_KEEPALIVE_VALS )
1837
+ #if defined(TCP_KEEPINTVL ) || defined(SIO_KEEPALIVE_VALS )
1816
1838
if (interval == port -> keepalives_interval )
1817
1839
return STATUS_OK ;
1818
1840
0 commit comments