Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 27e4018

Browse filesBrowse files
benjaminpmethane
authored andcommitted
Resurrect Connection.fileno() (PyMySQL#300)
This permits low-level access to the underlying network connection. For example, this can be used to tweak the TCP timeout (TCP_USER_TIMEOUT).
1 parent 3bdcb26 commit 27e4018
Copy full SHA for 27e4018

File tree

Expand file treeCollapse file tree

2 files changed

+23
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-0
lines changed

‎MySQLdb/_mysql.c

Copy file name to clipboardExpand all lines: MySQLdb/_mysql.c
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,20 @@ _mysql_ConnectionObject_field_count(
16391639
return PyInt_FromLong((long)mysql_field_count(&(self->connection)));
16401640
}
16411641

1642+
static char _mysql_ConnectionObject_fileno__doc__[] =
1643+
"Return file descriptor of the underlying libmysqlclient connection.\n\
1644+
This provides raw access to the underlying network connection.\n\
1645+
";
1646+
1647+
static PyObject *
1648+
_mysql_ConnectionObject_fileno(
1649+
_mysql_ConnectionObject *self,
1650+
PyObject *noargs)
1651+
{
1652+
check_connection(self);
1653+
return PyInt_FromLong(self->connection.net.fd);
1654+
}
1655+
16421656
static char _mysql_ResultObject_num_fields__doc__[] =
16431657
"Returns the number of fields (column) in the result." ;
16441658

@@ -2133,6 +2147,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
21332147
METH_NOARGS,
21342148
_mysql_ConnectionObject_field_count__doc__
21352149
},
2150+
{
2151+
"fileno",
2152+
(PyCFunction)_mysql_ConnectionObject_fileno,
2153+
METH_NOARGS,
2154+
_mysql_ConnectionObject_fileno__doc__
2155+
},
21362156
{
21372157
"get_host_info",
21382158
(PyCFunction)_mysql_ConnectionObject_get_host_info,

‎tests/test_MySQLdb_nonstandard.py

Copy file name to clipboardExpand all lines: tests/test_MySQLdb_nonstandard.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,6 @@ def test_client_flag(self):
103103
conn.client_flag = 0
104104

105105
conn.close()
106+
107+
def test_fileno(self):
108+
self.assertGreaterEqual(self.conn.fileno(), 0)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.