@@ -1593,7 +1593,7 @@ pq_setkeepaliveswin32(Port *port, int idle, int interval)
1593
1593
int
1594
1594
pq_getkeepalivesidle (Port * port )
1595
1595
{
1596
- #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE ) || defined(WIN32 )
1596
+ #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE_THRESHOLD ) || defined( TCP_KEEPALIVE ) || defined(WIN32 )
1597
1597
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1598
1598
return 0 ;
1599
1599
@@ -1605,23 +1605,34 @@ pq_getkeepalivesidle(Port *port)
1605
1605
#ifndef WIN32
1606
1606
ACCEPT_TYPE_ARG3 size = sizeof (port -> default_keepalives_idle );
1607
1607
1608
- #ifdef TCP_KEEPIDLE
1608
+ #if defined(TCP_KEEPIDLE )
1609
+ /* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
1609
1610
if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPIDLE ,
1610
1611
(char * ) & port -> default_keepalives_idle ,
1611
1612
& size ) < 0 )
1612
1613
{
1613
1614
elog (LOG , "getsockopt(TCP_KEEPIDLE) failed: %m" );
1614
1615
port -> default_keepalives_idle = -1 ; /* don't know */
1615
1616
}
1616
- #else
1617
+ #elif defined(TCP_KEEPALIVE_THRESHOLD )
1618
+ /* TCP_KEEPALIVE_THRESHOLD is the name of this option on Solaris */
1619
+ if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE_THRESHOLD ,
1620
+ (char * ) & port -> default_keepalives_idle ,
1621
+ & size ) < 0 )
1622
+ {
1623
+ elog (LOG , "getsockopt(TCP_KEEPALIVE_THRESHOLD) failed: %m" );
1624
+ port -> default_keepalives_idle = -1 ; /* don't know */
1625
+ }
1626
+ #else /* must have TCP_KEEPALIVE */
1627
+ /* TCP_KEEPALIVE is the name of this option on macOS */
1617
1628
if (getsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE ,
1618
1629
(char * ) & port -> default_keepalives_idle ,
1619
1630
& size ) < 0 )
1620
1631
{
1621
1632
elog (LOG , "getsockopt(TCP_KEEPALIVE) failed: %m" );
1622
1633
port -> default_keepalives_idle = -1 ; /* don't know */
1623
1634
}
1624
- #endif /* TCP_KEEPIDLE */
1635
+ #endif /* KEEPIDLE/KEEPALIVE_THRESHOLD/KEEPALIVE */
1625
1636
#else /* WIN32 */
1626
1637
/* We can't get the defaults on Windows, so return "don't know" */
1627
1638
port -> default_keepalives_idle = -1 ;
@@ -1640,7 +1651,8 @@ pq_setkeepalivesidle(int idle, Port *port)
1640
1651
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1641
1652
return STATUS_OK ;
1642
1653
1643
- #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE ) || defined(SIO_KEEPALIVE_VALS )
1654
+ /* check SIO_KEEPALIVE_VALS here, not just WIN32, as some toolchains lack it */
1655
+ #if defined(TCP_KEEPIDLE ) || defined(TCP_KEEPALIVE_THRESHOLD ) || defined(TCP_KEEPALIVE ) || defined(SIO_KEEPALIVE_VALS )
1644
1656
if (idle == port -> keepalives_idle )
1645
1657
return STATUS_OK ;
1646
1658
@@ -1659,14 +1671,24 @@ pq_setkeepalivesidle(int idle, Port *port)
1659
1671
if (idle == 0 )
1660
1672
idle = port -> default_keepalives_idle ;
1661
1673
1662
- #ifdef TCP_KEEPIDLE
1674
+ #if defined(TCP_KEEPIDLE )
1675
+ /* TCP_KEEPIDLE is the name of this option on Linux and *BSD */
1663
1676
if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPIDLE ,
1664
1677
(char * ) & idle , sizeof (idle )) < 0 )
1665
1678
{
1666
1679
elog (LOG , "setsockopt(TCP_KEEPIDLE) failed: %m" );
1667
1680
return STATUS_ERROR ;
1668
1681
}
1669
- #else
1682
+ #elif defined(TCP_KEEPALIVE_THRESHOLD )
1683
+ /* TCP_KEEPALIVE_THRESHOLD is the name of this option on Solaris */
1684
+ if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE_THRESHOLD ,
1685
+ (char * ) & idle , sizeof (idle )) < 0 )
1686
+ {
1687
+ elog (LOG , "setsockopt(TCP_KEEPALIVE_THRESHOLD) failed: %m" );
1688
+ return STATUS_ERROR ;
1689
+ }
1690
+ #else /* must have TCP_KEEPALIVE */
1691
+ /* TCP_KEEPALIVE is the name of this option on macOS */
1670
1692
if (setsockopt (port -> sock , IPPROTO_TCP , TCP_KEEPALIVE ,
1671
1693
(char * ) & idle , sizeof (idle )) < 0 )
1672
1694
{
@@ -1679,7 +1701,7 @@ pq_setkeepalivesidle(int idle, Port *port)
1679
1701
#else /* WIN32 */
1680
1702
return pq_setkeepaliveswin32 (port , idle , port -> keepalives_interval );
1681
1703
#endif
1682
- #else /* TCP_KEEPIDLE || SIO_KEEPALIVE_VALS */
1704
+ #else /* no way to set it */
1683
1705
if (idle != 0 )
1684
1706
{
1685
1707
elog (LOG , "setting the keepalive idle time is not supported" );
@@ -1729,7 +1751,7 @@ pq_setkeepalivesinterval(int interval, Port *port)
1729
1751
if (port == NULL || IS_AF_UNIX (port -> laddr .addr .ss_family ))
1730
1752
return STATUS_OK ;
1731
1753
1732
- #if defined(TCP_KEEPINTVL ) || defined (SIO_KEEPALIVE_VALS )
1754
+ #if defined(TCP_KEEPINTVL ) || defined(SIO_KEEPALIVE_VALS )
1733
1755
if (interval == port -> keepalives_interval )
1734
1756
return STATUS_OK ;
1735
1757
0 commit comments