aboutsummaryrefslogtreecommitdiff
path: root/src/util/network.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-14 07:22:42 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-14 07:22:42 +0000
commit662b5736c37e8cf2b3e6aa5af53cef0d03b743ab (patch)
treec4299637a2db19a3e87957645d5aa58e196da43f /src/util/network.c
parent94aa63cb17777332095a1de0a70382a49e10fecb (diff)
downloadgnunet-662b5736c37e8cf2b3e6aa5af53cef0d03b743ab.tar.gz
gnunet-662b5736c37e8cf2b3e6aa5af53cef0d03b743ab.zip
LRN loves slist: Use stack allocation for slist iterator
Diffstat (limited to 'src/util/network.c')
-rw-r--r--src/util/network.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/src/util/network.c b/src/util/network.c
index fa097dff4..3085d271f 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -1010,7 +1010,7 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
1010 return GNUNET_YES; 1010 return GNUNET_YES;
1011 } 1011 }
1012#else 1012#else
1013 struct GNUNET_CONTAINER_SList_Iterator *it; 1013 struct GNUNET_CONTAINER_SList_Iterator it;
1014 struct GNUNET_DISK_FileHandle *h; 1014 struct GNUNET_DISK_FileHandle *h;
1015 int i; 1015 int i;
1016 int j; 1016 int j;
@@ -1027,25 +1027,25 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
1027 } 1027 }
1028 } 1028 }
1029 it = GNUNET_CONTAINER_slist_begin (fds1->handles); 1029 it = GNUNET_CONTAINER_slist_begin (fds1->handles);
1030 while (GNUNET_CONTAINER_slist_end (it) != GNUNET_YES) 1030 while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES)
1031 { 1031 {
1032#if DEBUG_NETWORK 1032#if DEBUG_NETWORK
1033 struct GNUNET_CONTAINER_SList_Iterator *t; 1033 struct GNUNET_CONTAINER_SList_Iterator t;
1034#endif 1034#endif
1035 h = 1035 h =
1036 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (it, 1036 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&it,
1037 NULL); 1037 NULL);
1038#if DEBUG_NETWORK 1038#if DEBUG_NETWORK
1039 LOG (GNUNET_ERROR_TYPE_DEBUG, 1039 LOG (GNUNET_ERROR_TYPE_DEBUG,
1040 "Checking that FD 0x%x is in another set:\n", h->h); 1040 "Checking that FD 0x%x is in another set:\n", h->h);
1041 for (t = GNUNET_CONTAINER_slist_begin (fds2->handles); 1041 for (t = GNUNET_CONTAINER_slist_begin (fds2->handles);
1042 GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; 1042 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1043 GNUNET_CONTAINER_slist_next (t)) 1043 GNUNET_CONTAINER_slist_next (&t))
1044 { 1044 {
1045 struct GNUNET_DISK_FileHandle *fh; 1045 struct GNUNET_DISK_FileHandle *fh;
1046 1046
1047 fh = 1047 fh =
1048 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, 1048 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1049 NULL); 1049 NULL);
1050 LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h); 1050 LOG (GNUNET_ERROR_TYPE_DEBUG, "0x%x\n", fh->h);
1051 } 1051 }
@@ -1056,12 +1056,10 @@ GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
1056#if DEBUG_NETWORK 1056#if DEBUG_NETWORK
1057 LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n"); 1057 LOG (GNUNET_ERROR_TYPE_DEBUG, "Match!\n");
1058#endif 1058#endif
1059 GNUNET_CONTAINER_slist_iter_destroy (it);
1060 return GNUNET_YES; 1059 return GNUNET_YES;
1061 } 1060 }
1062 GNUNET_CONTAINER_slist_next (it); 1061 GNUNET_CONTAINER_slist_next (&it);
1063 } 1062 }
1064 GNUNET_CONTAINER_slist_iter_destroy (it);
1065#endif 1063#endif
1066 return GNUNET_NO; 1064 return GNUNET_NO;
1067} 1065}
@@ -1161,21 +1159,20 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1161 handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles); 1159 handles += read_handles = GNUNET_CONTAINER_slist_count (rfds->handles);
1162#if DEBUG_NETWORK 1160#if DEBUG_NETWORK
1163 { 1161 {
1164 struct GNUNET_CONTAINER_SList_Iterator *t; 1162 struct GNUNET_CONTAINER_SList_Iterator t;
1165 1163
1166 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); 1164 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1167 GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; 1165 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1168 GNUNET_CONTAINER_slist_next (t)) 1166 GNUNET_CONTAINER_slist_next (&t))
1169 { 1167 {
1170 struct GNUNET_DISK_FileHandle *fh; 1168 struct GNUNET_DISK_FileHandle *fh;
1171 1169
1172 fh = 1170 fh =
1173 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, 1171 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1174 NULL); 1172 NULL);
1175 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n", 1173 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x (0x%x) is SET in rfds\n",
1176 fh->h, fh); 1174 fh->h, fh);
1177 } 1175 }
1178 GNUNET_CONTAINER_slist_iter_destroy (t);
1179 } 1176 }
1180#endif 1177#endif
1181#endif 1178#endif
@@ -1291,16 +1288,16 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1291 /* Read Pipes */ 1288 /* Read Pipes */
1292 if (rfds && read_handles) 1289 if (rfds && read_handles)
1293 { 1290 {
1294 struct GNUNET_CONTAINER_SList_Iterator *i; 1291 struct GNUNET_CONTAINER_SList_Iterator i;
1295 1292
1296 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); 1293 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles);
1297 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; 1294 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
1298 GNUNET_CONTAINER_slist_next (i)) 1295 GNUNET_CONTAINER_slist_next (&i))
1299 { 1296 {
1300 struct GNUNET_DISK_FileHandle *fh; 1297 struct GNUNET_DISK_FileHandle *fh;
1301 1298
1302 fh = 1299 fh =
1303 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, 1300 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
1304 NULL); 1301 NULL);
1305 if (fh->type == GNUNET_PIPE) 1302 if (fh->type == GNUNET_PIPE)
1306 { 1303 {
@@ -1350,7 +1347,6 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1350 GNUNET_DISK_FileHandle)); 1347 GNUNET_DISK_FileHandle));
1351 } 1348 }
1352 } 1349 }
1353 GNUNET_CONTAINER_slist_iter_destroy (i);
1354 } 1350 }
1355 if (wfds && write_handles) 1351 if (wfds && write_handles)
1356 { 1352 {
@@ -1363,17 +1359,17 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1363 } 1359 }
1364 if (efds && ex_handles) 1360 if (efds && ex_handles)
1365 { 1361 {
1366 struct GNUNET_CONTAINER_SList_Iterator *i; 1362 struct GNUNET_CONTAINER_SList_Iterator i;
1367 1363
1368 for (i = GNUNET_CONTAINER_slist_begin (efds->handles); 1364 for (i = GNUNET_CONTAINER_slist_begin (efds->handles);
1369 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; 1365 GNUNET_CONTAINER_slist_end (&i) != GNUNET_YES;
1370 GNUNET_CONTAINER_slist_next (i)) 1366 GNUNET_CONTAINER_slist_next (&i))
1371 { 1367 {
1372 struct GNUNET_DISK_FileHandle *fh; 1368 struct GNUNET_DISK_FileHandle *fh;
1373 DWORD dwBytes; 1369 DWORD dwBytes;
1374 1370
1375 fh = 1371 fh =
1376 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (i, 1372 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&i,
1377 NULL); 1373 NULL);
1378 if (fh->type == GNUNET_PIPE) 1374 if (fh->type == GNUNET_PIPE)
1379 { 1375 {
@@ -1388,7 +1384,6 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1388 } 1384 }
1389 } 1385 }
1390 } 1386 }
1391 GNUNET_CONTAINER_slist_iter_destroy (i);
1392 } 1387 }
1393 if (nfds > 0) 1388 if (nfds > 0)
1394 { 1389 {
@@ -1610,7 +1605,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1610#endif 1605#endif
1611 if (rfds) 1606 if (rfds)
1612 { 1607 {
1613 struct GNUNET_CONTAINER_SList_Iterator *t; 1608 struct GNUNET_CONTAINER_SList_Iterator t;
1614 1609
1615 for (i = 0; i < rfds->sds.fd_count; i++) 1610 for (i = 0; i < rfds->sds.fd_count; i++)
1616 { 1611 {
@@ -1618,20 +1613,19 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1618 nsock++; 1613 nsock++;
1619 } 1614 }
1620 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); 1615 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1621 GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; 1616 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1622 GNUNET_CONTAINER_slist_next (t)) 1617 GNUNET_CONTAINER_slist_next (&t))
1623 { 1618 {
1624 struct GNUNET_DISK_FileHandle *fh; 1619 struct GNUNET_DISK_FileHandle *fh;
1625 1620
1626 fh = 1621 fh =
1627 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, 1622 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1628 NULL); 1623 NULL);
1629 if (fh->type == GNUNET_PIPE) 1624 if (fh->type == GNUNET_PIPE)
1630 { 1625 {
1631 CancelIo (fh->h); 1626 CancelIo (fh->h);
1632 } 1627 }
1633 } 1628 }
1634 GNUNET_CONTAINER_slist_iter_destroy (t);
1635#if DEBUG_NETWORK 1629#if DEBUG_NETWORK
1636 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n"); 1630 LOG (GNUNET_ERROR_TYPE_DEBUG, "Zeroing rfds\n");
1637#endif 1631#endif
@@ -1676,7 +1670,7 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1676#if DEBUG_NETWORK 1670#if DEBUG_NETWORK
1677 if (rfds) 1671 if (rfds)
1678 { 1672 {
1679 struct GNUNET_CONTAINER_SList_Iterator *t; 1673 struct GNUNET_CONTAINER_SList_Iterator t;
1680 1674
1681 for (i = 0; i < bread.fd_count; i++) 1675 for (i = 0; i < bread.fd_count; i++)
1682 { 1676 {
@@ -1687,17 +1681,16 @@ GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
1687 "NOT SET"); 1681 "NOT SET");
1688 } 1682 }
1689 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles); 1683 for (t = GNUNET_CONTAINER_slist_begin (rfds->handles);
1690 GNUNET_CONTAINER_slist_end (t) != GNUNET_YES; 1684 GNUNET_CONTAINER_slist_end (&t) != GNUNET_YES;
1691 GNUNET_CONTAINER_slist_next (t)) 1685 GNUNET_CONTAINER_slist_next (&t))
1692 { 1686 {
1693 struct GNUNET_DISK_FileHandle *fh; 1687 struct GNUNET_DISK_FileHandle *fh;
1694 1688
1695 fh = 1689 fh =
1696 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (t, 1690 (struct GNUNET_DISK_FileHandle *) GNUNET_CONTAINER_slist_get (&t,
1697 NULL); 1691 NULL);
1698 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h); 1692 LOG (GNUNET_ERROR_TYPE_DEBUG, "FD 0x%x is SET in rfds\n", fh->h);
1699 } 1693 }
1700 GNUNET_CONTAINER_slist_iter_destroy (t);
1701 } 1694 }
1702 if (wfds) 1695 if (wfds)
1703 { 1696 {