Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright 2000, International Business Machines Corporation and others. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * This software has been released under the terms of the IBM Public | |
6 | * License. For details, see the LICENSE file in the top-level source | |
7 | * directory or online at http://www.openafs.org/dl/license10.html | |
8 | * | |
9 | * Portions Copyright (c) 2003 Apple Computer, Inc. | |
10 | */ | |
11 | ||
12 | /* | |
13 | * This file contains sample code for the rxstats interface | |
14 | */ | |
15 | ||
16 | #include <afsconfig.h> | |
17 | #include <afs/param.h> | |
18 | ||
19 | #include <roken.h> | |
20 | ||
21 | #ifdef AFS_NT40_ENV | |
22 | #include <pthread.h> | |
23 | #endif | |
24 | ||
25 | #include <rx/rx.h> | |
26 | #include <rx/rxstat.h> | |
27 | ||
28 | #include <afs/afs_Admin.h> | |
29 | #include <afs/afs_clientAdmin.h> | |
30 | #include <afs/afs_utilAdmin.h> | |
31 | ||
32 | void | |
33 | Usage(void) | |
34 | { | |
35 | fprintf(stderr, "Usage: rxstat_clear_peer <cell> <host> <port>\n"); | |
36 | exit(1); | |
37 | } | |
38 | ||
39 | void | |
40 | ParseArgs(int argc, char *argv[], char **cellName, char **srvrName, | |
41 | long *srvrPort) | |
42 | { | |
43 | char **argp = argv; | |
44 | ||
45 | if (!*(++argp)) | |
46 | Usage(); | |
47 | *cellName = *(argp++); | |
48 | if (!*(argp)) | |
49 | Usage(); | |
50 | *srvrName = *(argp++); | |
51 | if (!*(argp)) | |
52 | Usage(); | |
53 | *srvrPort = strtol(*(argp++), NULL, 0); | |
54 | if (*srvrPort <= 0 || *srvrPort >= 65536) | |
55 | Usage(); | |
56 | if (*(argp)) | |
57 | Usage(); | |
58 | } | |
59 | ||
60 | int | |
61 | main(int argc, char *argv[]) | |
62 | { | |
63 | int rc; | |
64 | afs_status_t st = 0; | |
65 | struct rx_connection *conn; | |
66 | char *srvrName; | |
67 | long srvrPort; | |
68 | char *cellName; | |
69 | void *tokenHandle; | |
70 | void *cellHandle; | |
71 | ||
72 | ParseArgs(argc, argv, &cellName, &srvrName, &srvrPort); | |
73 | ||
74 | rc = afsclient_Init(&st); | |
75 | if (!rc) { | |
76 | fprintf(stderr, "afsclient_Init, status %d\n", st); | |
77 | exit(1); | |
78 | } | |
79 | ||
80 | rc = afsclient_TokenGetExisting(cellName, &tokenHandle, &st); | |
81 | if (!rc) { | |
82 | fprintf(stderr, "afsclient_TokenGetExisting, status %d\n", st); | |
83 | exit(1); | |
84 | } | |
85 | ||
86 | rc = afsclient_CellOpen(cellName, tokenHandle, &cellHandle, &st); | |
87 | if (!rc) { | |
88 | fprintf(stderr, "afsclient_CellOpen, status %d\n", st); | |
89 | exit(1); | |
90 | } | |
91 | ||
92 | rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn, | |
93 | &st); | |
94 | if (!rc) { | |
95 | fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st); | |
96 | exit(1); | |
97 | } | |
98 | ||
99 | rc = util_RPCStatsClear(conn, RXSTATS_ClearPeerRPCStats, | |
100 | AFS_RX_STATS_CLEAR_ALL, &st); | |
101 | if (!rc) { | |
102 | fprintf(stderr, "util_RPCStatsClear, status %d\n", st); | |
103 | exit(1); | |
104 | } | |
105 | ||
106 | rc = afsclient_RPCStatClose(conn, &st); | |
107 | if (!rc) { | |
108 | fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st); | |
109 | exit(1); | |
110 | } | |
111 | ||
112 | rc = afsclient_CellClose(cellHandle, &st); | |
113 | if (!rc) { | |
114 | fprintf(stderr, "afsclient_CellClose, status %d\n", st); | |
115 | exit(1); | |
116 | } | |
117 | ||
118 | rc = afsclient_TokenClose(tokenHandle, &st); | |
119 | if (!rc) { | |
120 | fprintf(stderr, "afsclient_TokenClose, status %d\n", st); | |
121 | exit(1); | |
122 | } | |
123 | ||
124 | exit(0); | |
125 | } |