summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2019-02-24 07:25:54 -0800
committerGiampaolo Rodola <g.rodola@gmail.com>2019-02-24 07:25:54 -0800
commita96bbdf2e84c737f2b80f5a9af9ac0ca46b93526 (patch)
tree4184ab779853a1e2a630eeea71789a5984d8348c
parent8c4d4c21d08a573a25cbbe3d6c3e2ec20008e215 (diff)
downloadpsutil-a96bbdf2e84c737f2b80f5a9af9ac0ca46b93526.tar.gz
win connections refactoring
-rw-r--r--psutil/_psutil_windows.c50
1 files changed, 14 insertions, 36 deletions
diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c
index 82be938b..bcdc3e0b 100644
--- a/psutil/_psutil_windows.c
+++ b/psutil/_psutil_windows.c
@@ -1474,7 +1474,16 @@ static DWORD __GetExtendedUdpTable(_GetExtendedUdpTable call,
*data = NULL;
}
}
- return error;
+
+ if (error == ERROR_NOT_ENOUGH_MEMORY) {
+ PyErr_NoMemory();
+ return 1;
+ }
+ if (error != NO_ERROR) {
+ PyErr_SetFromWindowsErr(error);
+ return 1;
+ }
+ return 0;
}
@@ -1556,16 +1565,8 @@ psutil_net_connections(PyObject *self, PyObject *args) {
error = __GetExtendedTcpTable(psutil_GetExtendedTcpTable,
AF_INET, &table, &tableSize);
- if (error == ERROR_NOT_ENOUGH_MEMORY) {
- PyErr_NoMemory();
+ if (error != 0)
goto error;
- }
-
- if (error != NO_ERROR) {
- PyErr_SetFromWindowsErr(error);
- goto error;
- }
-
tcp4Table = table;
for (i = 0; i < tcp4Table->dwNumEntries; i++) {
if (pid != -1) {
@@ -1649,15 +1650,8 @@ psutil_net_connections(PyObject *self, PyObject *args) {
error = __GetExtendedTcpTable(psutil_GetExtendedTcpTable,
AF_INET6, &table, &tableSize);
- if (error == ERROR_NOT_ENOUGH_MEMORY) {
- PyErr_NoMemory();
- goto error;
- }
- if (error != NO_ERROR) {
- PyErr_SetFromWindowsErr(error);
+ if (error != 0)
goto error;
- }
-
tcp6Table = table;
for (i = 0; i < tcp6Table->dwNumEntries; i++)
{
@@ -1742,15 +1736,8 @@ psutil_net_connections(PyObject *self, PyObject *args) {
tableSize = 0;
error = __GetExtendedUdpTable(psutil_GetExtendedUdpTable,
AF_INET, &table, &tableSize);
- if (error == ERROR_NOT_ENOUGH_MEMORY) {
- PyErr_NoMemory();
- goto error;
- }
- if (error != NO_ERROR) {
- PyErr_SetFromWindowsErr(error);
+ if (error != 0)
goto error;
- }
-
udp4Table = table;
for (i = 0; i < udp4Table->dwNumEntries; i++)
{
@@ -1812,18 +1799,9 @@ psutil_net_connections(PyObject *self, PyObject *args) {
tableSize = 0;
error = __GetExtendedUdpTable(psutil_GetExtendedUdpTable,
AF_INET6, &table, &tableSize);
- if (error == ERROR_NOT_ENOUGH_MEMORY) {
- PyErr_NoMemory();
- goto error;
- }
-
- if (error != NO_ERROR) {
- PyErr_SetFromWindowsErr(error);
+ if (error != 0)
goto error;
- }
-
udp6Table = table;
-
for (i = 0; i < udp6Table->dwNumEntries; i++) {
if (pid != -1) {
if (udp6Table->table[i].dwOwningPid != pid) {