diff --git a/debian/patches/sipwise/db_postgres-timeout b/debian/patches/sipwise/db_postgres-timeout index 8eb0de8f5..5147eb35c 100644 --- a/debian/patches/sipwise/db_postgres-timeout +++ b/debian/patches/sipwise/db_postgres-timeout @@ -66,29 +66,32 @@ } --- a/modules/db_postgres/pg_mod.c +++ b/modules/db_postgres/pg_mod.c -@@ -61,6 +61,7 @@ +@@ -61,6 +61,8 @@ * 0 disables reconnecting */ int pg_lockset = 4; +int pg_timeout = 0; /* default = no timeout */ ++int pg_keepalive = 0; /* * Postgres module interface -@@ -92,6 +93,7 @@ +@@ -92,6 +94,8 @@ static param_export_t params[] = { {"retries", PARAM_INT, &pg_retries }, {"lockset", PARAM_INT, &pg_lockset }, + {"timeout", PARAM_INT, &pg_timeout }, ++ {"tcp_keepalive", PARAM_INT, &pg_keepalive }, {0, 0, 0} }; --- a/modules/db_postgres/pg_mod.h +++ b/modules/db_postgres/pg_mod.h -@@ -41,6 +41,7 @@ +@@ -41,6 +41,8 @@ */ extern int pg_retries; +extern int pg_timeout; ++extern int pg_keepalive; /** @} */ @@ -153,6 +156,18 @@ goto error; } +@@ -285,6 +304,11 @@ + PQprotocolVersion(pcon->con), 0 ); + #endif + ++#ifdef TCP_KEEPIDLE ++ if (pg_keepalive) ++ setsockopt(PQsocket(pcon->con), IPPROTO_TCP, TCP_KEEPIDLE, &pg_keepalive); ++#endif ++ + ret = timestamp_format(pcon->con); + if (ret == 1 || ret == -1) { + /* Assume INT8 representation if detection fails */ --- a/modules/db_postgres/km_pg_con.c +++ b/modules/db_postgres/km_pg_con.c @@ -26,6 +26,7 @@ @@ -209,3 +224,15 @@ if( (ptr->con == 0) || (PQstatus(ptr->con) != CONNECTION_OK) ) { +@@ -88,6 +110,11 @@ + ptr->timestamp = time(0); + ptr->id = id; + ++#ifdef TCP_KEEPIDLE ++ if (pg_keepalive) ++ setsockopt(PQsocket(ptr->con), IPPROTO_TCP, TCP_KEEPIDLE, &pg_keepalive); ++#endif ++ + return ptr; + + err: