summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorAsk Solem <ask@celeryproject.org>2014-04-14 19:05:16 +0100
committerAsk Solem <ask@celeryproject.org>2014-04-14 19:05:16 +0100
commit11175a09f4d8a92d07e52781a354685a9e10aaea (patch)
treedb2313709c7899a3ae18f6ad1891bc1f6b752970 /Modules
parent14141117b6e9036145b9c13816d58252613959c0 (diff)
downloadlibrabbitmq-11175a09f4d8a92d07e52781a354685a9e10aaea.tar.gz
Connection.fileno() now raises AttributeError if fd not set and close sets fd to 0. Closes #39
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_librabbitmq/connection.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Modules/_librabbitmq/connection.c b/Modules/_librabbitmq/connection.c
index 5fd289f..eed493d 100644
--- a/Modules/_librabbitmq/connection.c
+++ b/Modules/_librabbitmq/connection.c
@@ -926,7 +926,13 @@ PyRabbitMQ_ConnectionType_init(PyRabbitMQ_Connection *self,
static PyObject*
PyRabbitMQ_Connection_fileno(PyRabbitMQ_Connection *self)
{
- return PyInt_FromLong((long)self->sockfd);
+ if (self->sockfd > 0) {
+ return PyInt_FromLong((long)self->sockfd);
+ }
+ else {
+ PyErr_SetString(PyExc_ValueError, "Socket not connected");
+ return 0;
+ }
}
@@ -995,6 +1001,7 @@ PyRabbitMQ_Connection_close(PyRabbitMQ_Connection *self)
reply = amqp_connection_close(self->conn, AMQP_REPLY_SUCCESS);
amqp_destroy_connection(self->conn);
close(self->sockfd);
+ self->sockfd = 0;
Py_END_ALLOW_THREADS
}