#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include "anet.h"
#include "sds.h"
static int cliReadReply(int fd);
static void usage();
+/*------------------------------------------------------------------------------
+ * Utility functions
+ *--------------------------------------------------------------------------- */
+
+static long long mstime(void) {
+ struct timeval tv;
+ long long mst;
+
+ gettimeofday(&tv, NULL);
+ mst = ((long)tv.tv_sec)*1000;
+ mst += tv.tv_usec/1000;
+ return mst;
+}
+
+static void printStringRepr(char *s, int len) {
+ printf("\"");
+ while(len--) {
+ switch(*s) {
+ case '\\':
+ case '"':
+ printf("\\%c",*s);
+ break;
+ case '\n': printf("\\n"); break;
+ case '\r': printf("\\r"); break;
+ case '\t': printf("\\t"); break;
+ case '\a': printf("\\a"); break;
+ case '\b': printf("\\b"); break;
+ default:
+ if (isprint(*s))
+ printf("%c",*s);
+ else
+ printf("\\x%02x",(unsigned char)*s);
+ break;
+ }
+ s++;
+ }
+ printf("\"");
+}
+
+/*------------------------------------------------------------------------------
+ * Networking / parsing
+ *--------------------------------------------------------------------------- */
+
/* Connect to the client. If force is not zero the connection is performed
* even if there is already a connected socket. */
static int cliConnect(int force) {
return 0;
}
-static void printStringRepr(char *s, int len) {
- printf("\"");
- while(len--) {
- switch(*s) {
- case '\\':
- case '"':
- printf("\\%c",*s);
- break;
- case '\n': printf("\\n"); break;
- case '\r': printf("\\r"); break;
- case '\t': printf("\\t"); break;
- case '\a': printf("\\a"); break;
- case '\b': printf("\\b"); break;
- default:
- if (isprint(*s))
- printf("%c",*s);
- else
- printf("\\x%02x",(unsigned char)*s);
- break;
- }
- s++;
- }
- printf("\"");
-}
-
static int cliReadBulkReply(int fd) {
sds replylen = cliReadLine(fd);
char *reply, crlf[2];
return 0;
}
+/*------------------------------------------------------------------------------
+ * User interface
+ *--------------------------------------------------------------------------- */
+
static int parseOptions(int argc, char **argv) {
int i;
exit(0);
} else {
int err;
+ long long start_time = mstime(), elapsed;
if ((err = cliSendCommand(argc, argv, 1)) != 0) {
if (err == ECONNRESET) {
cliSendCommand(argc,argv,1);
}
}
+ elapsed = mstime()-start_time;
+ if (elapsed > 500) printf("%.2f seconds\n",
+ (double)elapsed/1000);
}
}
/* Free the argument vector */