Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Typedefs | Enumerations | Functions | Variables

libpq-be.h File Reference

#include "datatype/timestamp.h"
#include "libpq/hba.h"
#include "libpq/pqcomm.h"
Include dependency graph for libpq-be.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Port

Typedefs

typedef enum CAC_state CAC_state
typedef struct Port Port

Enumerations

enum  CAC_state {
  CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY,
  CAC_TOOMANY, CAC_WAITBACKUP
}

Functions

int pq_getkeepalivesidle (Port *port)
int pq_getkeepalivesinterval (Port *port)
int pq_getkeepalivescount (Port *port)
int pq_setkeepalivesidle (int idle, Port *port)
int pq_setkeepalivesinterval (int interval, Port *port)
int pq_setkeepalivescount (int count, Port *port)

Variables

ProtocolVersion FrontendProtocol

Typedef Documentation

typedef enum CAC_state CAC_state
typedef struct Port Port

Enumeration Type Documentation

enum CAC_state
Enumerator:
CAC_OK 
CAC_STARTUP 
CAC_SHUTDOWN 
CAC_RECOVERY 
CAC_TOOMANY 
CAC_WAITBACKUP 

Definition at line 73 of file libpq-be.h.

{
    CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY,
    CAC_WAITBACKUP
} CAC_state;


Function Documentation

int pq_getkeepalivescount ( Port port  ) 

Definition at line 1696 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_count, elog, IS_AF_UNIX, Port::keepalives_count, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivescount(), and show_tcp_keepalives_count().

{
#ifdef TCP_KEEPCNT
    if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
        return 0;

    if (port->keepalives_count != 0)
        return port->keepalives_count;

    if (port->default_keepalives_count == 0)
    {
        ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_count);

        if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
                       (char *) &port->default_keepalives_count,
                       &size) < 0)
        {
            elog(LOG, "getsockopt(TCP_KEEPCNT) failed: %m");
            port->default_keepalives_count = -1;        /* don't know */
        }
    }

    return port->default_keepalives_count;
#else
    return 0;
#endif
}

int pq_getkeepalivesidle ( Port port  ) 

Definition at line 1516 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_idle, elog, IS_AF_UNIX, Port::keepalives_idle, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivesidle(), and show_tcp_keepalives_idle().

{
#if defined(TCP_KEEPIDLE) || defined(TCP_KEEPALIVE) || defined(WIN32)
    if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
        return 0;

    if (port->keepalives_idle != 0)
        return port->keepalives_idle;

    if (port->default_keepalives_idle == 0)
    {
#ifndef WIN32
        ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_idle);

#ifdef TCP_KEEPIDLE
        if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPIDLE,
                       (char *) &port->default_keepalives_idle,
                       &size) < 0)
        {
            elog(LOG, "getsockopt(TCP_KEEPIDLE) failed: %m");
            port->default_keepalives_idle = -1; /* don't know */
        }
#else
        if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPALIVE,
                       (char *) &port->default_keepalives_idle,
                       &size) < 0)
        {
            elog(LOG, "getsockopt(TCP_KEEPALIVE) failed: %m");
            port->default_keepalives_idle = -1; /* don't know */
        }
#endif   /* TCP_KEEPIDLE */
#else                           /* WIN32 */
        /* We can't get the defaults on Windows, so return "don't know" */
        port->default_keepalives_idle = -1;
#endif   /* WIN32 */
    }

    return port->default_keepalives_idle;
#else
    return 0;
#endif
}

int pq_getkeepalivesinterval ( Port port  ) 

Definition at line 1615 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_interval, elog, IS_AF_UNIX, Port::keepalives_interval, Port::laddr, LOG, NULL, and Port::sock.

Referenced by pq_setkeepalivesinterval(), and show_tcp_keepalives_interval().

{
#if defined(TCP_KEEPINTVL) || defined(SIO_KEEPALIVE_VALS)
    if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
        return 0;

    if (port->keepalives_interval != 0)
        return port->keepalives_interval;

    if (port->default_keepalives_interval == 0)
    {
#ifndef WIN32
        ACCEPT_TYPE_ARG3 size = sizeof(port->default_keepalives_interval);

        if (getsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
                       (char *) &port->default_keepalives_interval,
                       &size) < 0)
        {
            elog(LOG, "getsockopt(TCP_KEEPINTVL) failed: %m");
            port->default_keepalives_interval = -1;     /* don't know */
        }
#else
        /* We can't get the defaults on Windows, so return "don't know" */
        port->default_keepalives_interval = -1;
#endif   /* WIN32 */
    }

    return port->default_keepalives_interval;
#else
    return 0;
#endif
}

int pq_setkeepalivescount ( int  count,
Port port 
)

Definition at line 1725 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_count, elog, IS_AF_UNIX, Port::keepalives_count, Port::laddr, LOG, NULL, pq_getkeepalivescount(), and Port::sock.

Referenced by assign_tcp_keepalives_count(), and StreamConnection().

{
    if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
        return STATUS_OK;

#ifdef TCP_KEEPCNT
    if (count == port->keepalives_count)
        return STATUS_OK;

    if (port->default_keepalives_count <= 0)
    {
        if (pq_getkeepalivescount(port) < 0)
        {
            if (count == 0)
                return STATUS_OK;       /* default is set but unknown */
            else
                return STATUS_ERROR;
        }
    }

    if (count == 0)
        count = port->default_keepalives_count;

    if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPCNT,
                   (char *) &count, sizeof(count)) < 0)
    {
        elog(LOG, "setsockopt(TCP_KEEPCNT) failed: %m");
        return STATUS_ERROR;
    }

    port->keepalives_count = count;
#else
    if (count != 0)
    {
        elog(LOG, "setsockopt(TCP_KEEPCNT) not supported");
        return STATUS_ERROR;
    }
#endif

    return STATUS_OK;
}

int pq_setkeepalivesidle ( int  idle,
Port port 
)

Definition at line 1560 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_idle, elog, IS_AF_UNIX, Port::keepalives_idle, Port::keepalives_interval, Port::laddr, LOG, NULL, pq_getkeepalivesidle(), and Port::sock.

Referenced by assign_tcp_keepalives_idle(), and StreamConnection().

{
    if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
        return STATUS_OK;

#if defined(TCP_KEEPIDLE) || defined(TCP_KEEPALIVE) || defined(SIO_KEEPALIVE_VALS)
    if (idle == port->keepalives_idle)
        return STATUS_OK;

#ifndef WIN32
    if (port->default_keepalives_idle <= 0)
    {
        if (pq_getkeepalivesidle(port) < 0)
        {
            if (idle == 0)
                return STATUS_OK;       /* default is set but unknown */
            else
                return STATUS_ERROR;
        }
    }

    if (idle == 0)
        idle = port->default_keepalives_idle;

#ifdef TCP_KEEPIDLE
    if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPIDLE,
                   (char *) &idle, sizeof(idle)) < 0)
    {
        elog(LOG, "setsockopt(TCP_KEEPIDLE) failed: %m");
        return STATUS_ERROR;
    }
#else
    if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPALIVE,
                   (char *) &idle, sizeof(idle)) < 0)
    {
        elog(LOG, "setsockopt(TCP_KEEPALIVE) failed: %m");
        return STATUS_ERROR;
    }
#endif

    port->keepalives_idle = idle;
#else                           /* WIN32 */
    return pq_setkeepaliveswin32(port, idle, port->keepalives_interval);
#endif
#else                           /* TCP_KEEPIDLE || SIO_KEEPALIVE_VALS */
    if (idle != 0)
    {
        elog(LOG, "setting the keepalive idle time is not supported");
        return STATUS_ERROR;
    }
#endif
    return STATUS_OK;
}

int pq_setkeepalivesinterval ( int  interval,
Port port 
)

Definition at line 1649 of file pqcomm.c.

References SockAddr::addr, Port::default_keepalives_interval, elog, IS_AF_UNIX, Port::keepalives_idle, Port::keepalives_interval, Port::laddr, LOG, NULL, pq_getkeepalivesinterval(), and Port::sock.

Referenced by assign_tcp_keepalives_interval(), and StreamConnection().

{
    if (port == NULL || IS_AF_UNIX(port->laddr.addr.ss_family))
        return STATUS_OK;

#if defined(TCP_KEEPINTVL) || defined (SIO_KEEPALIVE_VALS)
    if (interval == port->keepalives_interval)
        return STATUS_OK;

#ifndef WIN32
    if (port->default_keepalives_interval <= 0)
    {
        if (pq_getkeepalivesinterval(port) < 0)
        {
            if (interval == 0)
                return STATUS_OK;       /* default is set but unknown */
            else
                return STATUS_ERROR;
        }
    }

    if (interval == 0)
        interval = port->default_keepalives_interval;

    if (setsockopt(port->sock, IPPROTO_TCP, TCP_KEEPINTVL,
                   (char *) &interval, sizeof(interval)) < 0)
    {
        elog(LOG, "setsockopt(TCP_KEEPINTVL) failed: %m");
        return STATUS_ERROR;
    }

    port->keepalives_interval = interval;
#else                           /* WIN32 */
    return pq_setkeepaliveswin32(port, port->keepalives_idle, interval);
#endif
#else
    if (interval != 0)
    {
        elog(LOG, "setsockopt(TCP_KEEPINTVL) not supported");
        return STATUS_ERROR;
    }
#endif

    return STATUS_OK;
}


Variable Documentation