Skip to content

Commit 330cb5b

Browse files
committed
Added idle_timeout attribute to Context
1 parent 3e71630 commit 330cb5b

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

context.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,36 @@ context_set_timeout(getdns_context *context, PyObject *py_value)
112112
}
113113

114114

115+
int
116+
context_set_idle_timeout(getdns_context *context, PyObject *py_value)
117+
{
118+
getdns_return_t ret;
119+
uint64_t value;
120+
121+
#if PY_MAJOR_VERSION >= 3
122+
if (!PyLong_Check(py_value)) {
123+
#else
124+
if (!PyInt_Check(py_value)) {
125+
#endif
126+
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
127+
return -1;
128+
}
129+
#if PY_MAJOR_VERSION >= 3
130+
if ((long)(value = PyLong_AsLong(py_value)) < 0) {
131+
#else
132+
if ((long)(value = PyInt_AsLong(py_value)) < 0) {
133+
#endif
134+
PyErr_SetString(getdns_error, GETDNS_RETURN_INVALID_PARAMETER_TEXT);
135+
return -1;
136+
}
137+
if ((ret = getdns_context_set_idle_timeout(context, value)) != GETDNS_RETURN_GOOD) {
138+
PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
139+
return -1;
140+
}
141+
return 0;
142+
}
143+
144+
115145
int
116146
context_set_resolution_type(getdns_context *context, PyObject *py_value)
117147
{
@@ -830,6 +860,14 @@ context_getattro(PyObject *self, PyObject *nameobj)
830860
}
831861
return PyLong_FromLong((long)timeout);
832862
}
863+
if (!strncmp(attrname, "idle_timeout", strlen("idle_timeout"))) {
864+
uint64_t timeout;
865+
if ((ret = getdns_context_get_idle_timeout(context, &timeout)) != GETDNS_RETURN_GOOD) {
866+
PyErr_SetString(getdns_error, getdns_get_errorstr_by_id(ret));
867+
return NULL;
868+
}
869+
return PyLong_FromLong((long)timeout);
870+
}
833871
if (!strncmp(attrname, "dns_transport_list", strlen("dns_transport_list"))) {
834872
getdns_transport_list_t *transports;
835873
PyObject *py_transports;
@@ -1055,6 +1093,9 @@ context_setattro(PyObject *self, PyObject *attrname, PyObject *py_value)
10551093
if (!strncmp(name, "timeout", strlen("timeout"))) {
10561094
return(context_set_timeout(context, py_value));
10571095
}
1096+
if (!strncmp(name, "idle_timeout", strlen("idle_timeout"))) {
1097+
return(context_set_idle_timeout(context, py_value));
1098+
}
10581099
if (!strncmp(name, "resolution_type", strlen("resolution_type"))) {
10591100
return(context_set_resolution_type(context, py_value));
10601101
}

getdns.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ PyMemberDef Context_members[] = {
196196
"string set by the implementer" },
197197
{ "version_string", T_STRING|READONLY, offsetof(getdns_ContextObject, version_string), 0,
198198
"string set by the implementer" },
199+
{"idle_timeout", T_INT, offsetof(getdns_ContextObject, idle_timeout), 0, "TCP idle timeout" },
199200
{ NULL }
200201
};
201202

pygetdns.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ typedef struct {
7373
PyObject_HEAD
7474
PyObject *py_context; /* Python capsule containing getdns_context */
7575
uint64_t timeout; /* timeout attribute (milliseconds) */
76+
uint64_t idle_timeout; /* TCP timeout attribute (milliseconds) */
7677
getdns_resolution_t resolution_type; /* stub or recursive? */
7778
#if 0
7879
getdns_transport_t dns_transport; /* udp/tcp/etc */

0 commit comments

Comments
 (0)