PERFORCE change 166186 for review
Gabor Pali
pgj at FreeBSD.org
Fri Jul 17 00:22:27 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=166186
Change 166186 by pgj at petymeg-current on 2009/07/17 00:22:11
- Make socket iteration without copying data, just passing constant
pointers, no need for freeing.
- Reset on calling first element of the list.
- Adjust applications.
Affected files ...
.. //depot/projects/soc2009/pgj_libstat/src/contrib/bsnmp/snmp_mibII/mibII_tcp.c#3 edit
.. //depot/projects/soc2009/pgj_libstat/src/contrib/bsnmp/snmp_mibII/mibII_udp.c#3 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#27 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#30 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#7 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#22 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#14 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/unix.c#19 edit
.. //depot/projects/soc2009/pgj_libstat/src/usr.bin/nettop/main.c#8 edit
Differences ...
==== //depot/projects/soc2009/pgj_libstat/src/contrib/bsnmp/snmp_mibII/mibII_tcp.c#3 (text+ko) ====
@@ -70,7 +70,7 @@
struct socket_type_list *stlp;
struct socket_type_iterator *stip;
- struct socket_type *stp;
+ const struct socket_type *stp;
struct addr_type *atp;
int error;
==== //depot/projects/soc2009/pgj_libstat/src/contrib/bsnmp/snmp_mibII/mibII_udp.c#3 (text+ko) ====
@@ -61,7 +61,7 @@
size_t len;
struct socket_type_list *stlp;
struct socket_type_iterator *stip;
- struct socket_type *stp;
+ const struct socket_type *stp;
struct addr_type *atp;
int error;
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#27 (text+ko) ====
@@ -99,8 +99,8 @@
/* Socket iterator: */
int netstat_sti_alloc(struct socket_type_list *list,
struct socket_type_iterator **iterator);
-struct socket_type *netstat_sti_first(struct socket_type_iterator *iterator);
-struct socket_type *netstat_sti_next(struct socket_type_iterator *iterator);
+const struct socket_type *netstat_sti_first(struct socket_type_iterator *);
+const struct socket_type *netstat_sti_next(struct socket_type_iterator *);
void netstat_sti_free(struct socket_type_iterator *iterator);
void netstat_st_free(struct socket_type *stp);
==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#30 (text+ko) ====
@@ -177,7 +177,7 @@
while ((stp = LIST_FIRST(&list->stl_list))) {
LIST_REMOVE(stp, st_list);
- free(stp);
+ netstat_st_free(stp);
}
list->stl_length = 0;
@@ -275,7 +275,6 @@
bzero(itp, sizeof(*itp));
- /* XXX: Should it copy the list? */
itp->sti_list = list;
itp->sti_first = LIST_FIRST(&list->stl_list);
itp->sti_next = LIST_NEXT(itp->sti_first, st_list);
@@ -283,36 +282,24 @@
return (0);
}
-struct socket_type *
+const struct socket_type *
netstat_sti_first(struct socket_type_iterator *iterator)
{
- struct socket_type *stp;
-
- if (iterator->sti_first == NULL)
- return (NULL);
-
- stp = malloc(sizeof(*stp));
- if (stp == NULL)
- return (NULL);
-
- memcpy(stp, iterator->sti_first, sizeof(*stp));
- return (stp);
+ /* "Reset" iteration. */
+ iterator->sti_next = LIST_NEXT(iterator->sti_first, st_list);
+ return (iterator->sti_first);
}
-struct socket_type *
+const struct socket_type *
netstat_sti_next(struct socket_type_iterator *iterator)
{
- struct socket_type *stp;
+ const struct socket_type *stp;
- if (iterator->sti_next == NULL)
- return (NULL);
-
- stp = malloc(sizeof(*stp));
- if (stp == NULL)
- return (NULL);
+ /* "Step" iteration. */
+ stp = iterator->sti_next;
+ if (iterator->sti_next != NULL)
+ iterator->sti_next = LIST_NEXT(iterator->sti_next, st_list);
- memcpy(stp, iterator->sti_next, sizeof(*stp));
- iterator->sti_next = LIST_NEXT(iterator->sti_next, st_list);
return (stp);
}
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/extern.h#7 (text+ko) ====
@@ -72,8 +72,8 @@
int sotoxsocket(struct socket *, struct xsocket *);
void inetpr(void *, int, int);
-void inetppr(struct socket_type *);
-void unixdomainpr(struct socket_type *);
+void inetppr(const struct socket_type *);
+void unixdomainpr(const struct socket_type *);
void tcp_stats(u_long, const char *, int, int);
void udp_stats(u_long, const char *, int, int);
#ifdef SCTP
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/inet.c#22 (text+ko) ====
@@ -112,7 +112,7 @@
kvm_t *kvm;
#ifdef USE_ITERATOR_TYPE
struct socket_type_iterator *stip;
- struct socket_type *stp;
+ const struct socket_type *stp;
#endif
kvm = (kvm_t *)kvmd;
@@ -145,7 +145,6 @@
for (stp = netstat_sti_first(stip); stp != NULL;
stp = netstat_sti_next(stip)) {
inetppr(stp);
- netstat_st_free(stp);
}
netstat_sti_free(stip);
netstat_stl_free(stlp);
@@ -155,7 +154,7 @@
}
void
-inetppr(struct socket_type *stp)
+inetppr(const struct socket_type *stp)
{
static int first = 1;
char buf1[15];
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/main.c#14 (text+ko) ====
@@ -275,7 +275,7 @@
#endif
atalkprotox, NULL };
-static void connpr(struct socket_type *);
+static void connpr(const struct socket_type *);
static void printproto(struct protox *, const char *);
static void usage(void);
static struct protox *name2protox(const char *);
@@ -321,7 +321,7 @@
struct socket_type_list *stlp;
int error, st_flags;
struct socket_type_iterator *stip;
- struct socket_type *stp;
+ const struct socket_type *stp;
af = AF_UNSPEC;
@@ -601,7 +601,6 @@
for (stp = netstat_sti_first(stip); stp != NULL;
stp = netstat_sti_next(stip)) {
connpr(stp);
- netstat_st_free(stp);
}
netstat_sti_free(stip);
netstat_stl_free(stlp);
@@ -610,7 +609,7 @@
}
static void
-connpr(struct socket_type *stp)
+connpr(const struct socket_type *stp)
{
switch (netstat_st_get_family(stp)) {
case PF_INET:
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/unix.c#19 (text+ko) ====
@@ -64,7 +64,7 @@
kvm_t *kvm;
#ifdef USE_ITERATOR_TYPE
struct socket_type_iterator *stip;
- struct socket_type *stp;
+ const struct socket_type *stp;
#endif
kvm = (kvm_t *)kvmd;
@@ -100,10 +100,8 @@
goto out;
}
for (stp = netstat_sti_first(stip); stp != NULL;
- stp = netstat_sti_next(stip)) {
+ stp = netstat_sti_next(stip))
unixdomainpr(stp);
- netstat_st_free(stp);
- }
netstat_sti_free(stip);
out:
netstat_stl_free(stlp);
@@ -115,7 +113,7 @@
}
void
-unixdomainpr(struct socket_type *stp)
+unixdomainpr(const struct socket_type *stp)
{
static int first = 1;
char buf1[15];
==== //depot/projects/soc2009/pgj_libstat/src/usr.bin/nettop/main.c#8 (text+ko) ====
@@ -85,7 +85,7 @@
screen(struct socket_type_list *local, struct socket_type_list *inet)
{
struct socket_type_iterator *stip;
- struct socket_type *stp;
+ const struct socket_type *stp;
struct addr_type *atp, *laddr, *faddr;
int row;
@@ -115,7 +115,6 @@
atp = netstat_st_get_address(stp, 0);
printw(" %s", netstat_at_get_name(atp));
}
- netstat_st_free(stp);
}
netstat_sti_free(stip);
attron(A_BOLD);
@@ -140,7 +139,6 @@
netstat_at_get_name(faddr),
netstat_at_get_portname(faddr),
netstat_st_get_tcpstate(stp));
- netstat_st_free(stp);
}
netstat_sti_free(stip);
}
More information about the p4-projects
mailing list