author | Alberto Bertogli
<albertito@gmail.com> 2007-06-07 05:21:42 UTC |
committer | Alberto Bertogli
<albertito@gmail.com> 2007-06-07 05:21:42 UTC |
parent | ed2e17399f4f6ad944bf506ec7a0f82f0c2d8d2f |
bindings/python/nmdb.py | +7 | -0 |
bindings/python/nmdb_ll.c | +20 | -0 |
diff --git a/bindings/python/nmdb.py b/bindings/python/nmdb.py index 13a1dcd..ea45a3f 100644 --- a/bindings/python/nmdb.py +++ b/bindings/python/nmdb.py @@ -71,6 +71,13 @@ class _nmdbDict (object): raise NetworkError return rv + def add_udp_server(self, addr, port = -1): + "Adds an UDP server to the server pool." + rv = self._db.add_udp_server(addr, port) + if not rv: + raise NetworkError + return rv + def __getitem__(self, key): "d[k] Returns the value associated with the key k." if self.autopickle: diff --git a/bindings/python/nmdb_ll.c b/bindings/python/nmdb_ll.c index b81785c..e37b22a 100644 --- a/bindings/python/nmdb_ll.c +++ b/bindings/python/nmdb_ll.c @@ -70,6 +70,24 @@ static PyObject *db_add_tcp_server(nmdbobject *db, PyObject *args) return PyLong_FromLong(rv); } +/* add udp server */ +static PyObject *db_add_udp_server(nmdbobject *db, PyObject *args) +{ + int port; + char *addr; + int rv; + + if (!PyArg_ParseTuple(args, "si:add_udp_server", &addr, &port)) { + return NULL; + } + + Py_BEGIN_ALLOW_THREADS + rv = nmdb_add_udp_server(db->db, addr, port); + Py_END_ALLOW_THREADS + + return PyLong_FromLong(rv); +} + /* cache set */ static PyObject *db_cache_set(nmdbobject *db, PyObject *args) { @@ -303,6 +321,8 @@ static PyMethodDef nmdb_methods[] = { METH_VARARGS, NULL }, { "add_tcp_server", (PyCFunction) db_add_tcp_server, METH_VARARGS, NULL }, + { "add_udp_server", (PyCFunction) db_add_udp_server, + METH_VARARGS, NULL }, { "cache_set", (PyCFunction) db_cache_set, METH_VARARGS, NULL }, { "cache_get", (PyCFunction) db_cache_get, METH_VARARGS, NULL }, { "cache_delete", (PyCFunction) db_cache_delete, METH_VARARGS, NULL },