/usr/share/doc/apcupsd/examples/megaclient.c is in apcupsd-doc 3.14.10-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | /*
* Client test program for apcnet
*
* This program beats the living daylights out of your
* server by sending it one million requests.
*
* Optionally, it can send one million requests, connecting
* and disconnecting each time.
*
*
* Build it with: cc megaclient.c ../lib/libapc.a -o megaclient
*
* Execute: ./megaclient [host[:port]]
*
* For additional examples of code, see cgi/upsfetch.c
*/
/*
* If RECONNECT is defined, megaclient will disconnect
* and reconnect for every request (iteration), which is the normal
* way that apcupsd is currently accessed.
*
* If RECONNECT is not defined, a single connection
* is made with multiple requests.
*/
#define RECONNECT 1
#define ITERATIONS 80000
#include "apc.h"
#ifdef HAVE_NISLIB
/* Default values, can be changed on command line */
#define SERV_TCP_PORT 3551
#define SERV_HOST_ADDR "127.0.0.1"
#define MAXLINE 5000
void error_abort(const char *msg)
{
fprintf(stderr, msg);
exit(1);
}
int main(int argc, char *argv[])
{
int sockfd, port;
char host[200];
char msg[200], *p, *cmd;
int i, n, line;
time_t now, done;
char recvline[MAXLINE+1];
strcpy(host, SERV_HOST_ADDR);
port = SERV_TCP_PORT;
if (argc > 1) {
strcpy(host, argv[1]); /* get host from command line */
p = strchr(host, ':');
if (p) {
*p++ = 0;
port = atoi(p);
}
}
if (argc > 2) {
cmd = argv[2];
} else {
cmd = NULL;
}
#ifdef RECONNECT
now = time(NULL);
for (i=0; i<ITERATIONS; i++) {
if ((sockfd = net_open(host, NULL, port)) < 0) {
sprintf(msg, "client: tcp_open for host %s on %d failed\n", host, port);
error_abort(msg);
}
if (net_send(sockfd, "status", 6) != 6)
error_abort("handle_client: write error on socket");
line = 0;
while ((n = net_recv(sockfd, recvline, sizeof(recvline))) > 0) {
recvline[n] = 0;
line++;
/* fputs(recvline, stdout); */
}
if (n < 0) {
char msg[200];
sprintf(msg, "handle_client: net_recv error: %s\n", strerror(-n));
error_abort(msg);
}
if ( (i % 100) == 0) {
printf("%d lines=%d\n", i, line);
}
net_close(sockfd);
}
#else
/* Open once only */
if ((sockfd = net_open(host, NULL, port)) < 0) {
sprintf(msg, "client: tcp_open for host %s on %d failed\n", host, port);
error_abort(msg);
}
now = time(NULL);
for (i=0; i<ITERATIONS; i++) {
if (net_send(sockfd, "status", 6) != 6)
error_abort("handle_client: write error on socket");
line = 0;
while ((n = net_recv(sockfd, recvline, sizeof(recvline))) > 0) {
recvline[n] = 0;
line++;
/* fputs(recvline, stdout); */
}
if (n < 0) {
char msg[200];
sprintf(msg, "handle_client: net_recv error: %s\n", strerror(-n));
error_abort(msg);
}
if ( (i % 100) == 0) {
printf("%d lines=%d\n", i, line);
}
}
net_close(sockfd);
#endif
done = time(NULL);
printf("Total time = %ld secs.\n", done - now);
exit(0);
}
#else /* HAVE_NISLIB */
int main(int argc, char *argv[]) {
printf("Sorry, NIS code is not compiled in apcupsd.\n");
return 1;
}
#endif /* HAVE_NISLIB */
|