|
1 | 1 | /* nanonext - C level - Sockets and Protocols ------------------------------- */ |
2 | 2 |
|
| 3 | +#include <time.h> |
3 | 4 | #include <nng/nng.h> |
4 | 5 | #include <nng/protocol/bus0/bus.h> |
5 | 6 | #include <nng/protocol/pair0/pair.h> |
@@ -100,25 +101,38 @@ static void rnng_thread(void *arg) { |
100 | 101 | unsigned char *buf = NULL; |
101 | 102 | size_t sz; |
102 | 103 | int xc; |
| 104 | + time_t now; |
| 105 | + struct tm *tms; |
103 | 106 | nng_socket *sock = (nng_socket *) arg; |
104 | 107 |
|
105 | 108 | while (1) { |
106 | 109 | xc = nng_recv(*sock, &buf, &sz, 1u); |
| 110 | + time(&now); |
107 | 111 | if (xc) { |
108 | | - REprintf("messenger session ended\n"); |
| 112 | + tms = localtime(&now); |
| 113 | + REprintf("| messenger session: ended: %d-%02d-%02d %02d:%02d:%02d\n", |
| 114 | + tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday, |
| 115 | + tms->tm_hour, tms->tm_min, tms->tm_sec); |
109 | 116 | break; |
110 | 117 | } |
111 | 118 | if (!strcmp((const char *) buf, ":q")) { |
112 | 119 | nng_free(buf, sz); |
113 | 120 | break; |
114 | 121 | } |
115 | 122 | if (!strcmp((const char *) buf, "")) { |
| 123 | + tms = localtime(&now); |
| 124 | + REprintf("| peer status: changed: %d-%02d-%02d %02d:%02d:%02d\n", |
| 125 | + tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday, |
| 126 | + tms->tm_hour, tms->tm_min, tms->tm_sec); |
116 | 127 | nng_free(buf, sz); |
117 | | - Rprintf("[ peer status ] changed\n"); |
118 | 128 | continue; |
119 | 129 | } |
120 | 130 |
|
121 | | - Rprintf("> %s\n", buf); |
| 131 | + tms = localtime(&now); |
| 132 | + Rprintf("%s < %d-%02d-%02d %02d:%02d:%02d\n", |
| 133 | + buf, |
| 134 | + tms->tm_year + 1900, tms->tm_mon + 1, tms->tm_mday, |
| 135 | + tms->tm_hour, tms->tm_min, tms->tm_sec); |
122 | 136 | nng_free(buf, sz); |
123 | 137 | } |
124 | 138 |
|
|
0 commit comments