Commit e266a4a0 authored by captainwong's avatar captainwong

fix warnings

parent 4de8781f
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <string> #include <string>
...@@ -232,7 +233,7 @@ void eventcb(struct bufferevent* bev, short events, void* user_data) ...@@ -232,7 +233,7 @@ void eventcb(struct bufferevent* bev, short events, void* user_data)
printf("All disconnected\n"); printf("All disconnected\n");
double encodeSpeed = totalEncodeTime * 1.0 / totalMsgWritten; double encodeSpeed = totalEncodeTime * 1.0 / totalMsgWritten;
double decodeSpeed = totalDecodeTime * 1.0 / totalMsgRead; double decodeSpeed = totalDecodeTime * 1.0 / totalMsgRead;
printf("Read %.2f MiB %lld packets, Write %.2f MiB %lld packets\n" printf("Read %.2f MiB %" PRId64 " packets, Write %.2f MiB %" PRId64 " packets\n"
"Average msg size is %.2f bytes\n" "Average msg size is %.2f bytes\n"
"Throughput is %.2f MiB/s %.2f packets/s\n" "Throughput is %.2f MiB/s %.2f packets/s\n"
"Encode average time %.2f us, %.2f packets/s\n" "Encode average time %.2f us, %.2f packets/s\n"
......
...@@ -24,21 +24,21 @@ int main() ...@@ -24,21 +24,21 @@ int main()
// 解析完整数据包 // 解析完整数据包
{ {
char raw[] = "\nC5C30053\"HENG-BO\"0000R000000L000000#90219125916578[#000000|1737 00 000]_09:11:19,08-05-2019\r"; char raw[] = "\nC5C30053\"HENG-BO\"0000R000000L000000#90219125916578[#000000|1737 00 000]_09:11:19,08-05-2019\r";
int res = parse(raw, strlen(raw), &cb_commited); int res = parse(raw, (int)strlen(raw), &cb_commited);
assert(res == 0); assert(res == 0);
} }
// 解析长度不足的数据包 // 解析长度不足的数据包
{ {
char raw_not_enough[] = "\nC5C30053\"HENG-BO\"0000R000000L000000"; char raw_not_enough[] = "\nC5C30053\"HENG-BO\"0000R000000L000000";
int res = parse(raw_not_enough, strlen(raw_not_enough), &cb_commited); int res = parse(raw_not_enough, (int)strlen(raw_not_enough), &cb_commited);
assert(res == 1); assert(res == 1);
} }
// 解析到错误数据包 // 解析到错误数据包
{ {
char raw_error[] = "abcdeadfasdfasdfasd"; char raw_error[] = "abcdeadfasdfasdfasd";
int res = parse(raw_error, strlen(raw_error), &cb_commited); int res = parse(raw_error, (int)strlen(raw_error), &cb_commited);
assert(res == 2); assert(res == 2);
} }
......
...@@ -125,7 +125,7 @@ int main(int argc, char** argv) ...@@ -125,7 +125,7 @@ int main(int argc, char** argv)
FD_ZERO(&rfd); FD_ZERO(&rfd);
FD_SET(serverSock, &rfd); FD_SET(serverSock, &rfd);
timeval timeout = { 1, 0 }; timeval timeout = { 1, 0 };
int nfds = select(serverSock + 1, &rfd, (fd_set*)0, (fd_set*)0, &timeout); int nfds = select((int)(serverSock + 1), &rfd, (fd_set*)0, (fd_set*)0, &timeout);
printf("do_accept, select ret=%d\n", nfds); printf("do_accept, select ret=%d\n", nfds);
if (nfds > 0) { if (nfds > 0) {
FD_CLR(serverSock, &rfd); FD_CLR(serverSock, &rfd);
...@@ -134,7 +134,7 @@ int main(int argc, char** argv) ...@@ -134,7 +134,7 @@ int main(int argc, char** argv)
if (ret != 0) { if (ret != 0) {
exit(0); exit(0);
} }
printf("Got connection from %s:%d, fd=%d\n", inet_ntoa(sForeignAddrIn.sin_addr), sForeignAddrIn.sin_port, clientSock); printf("Got connection from %s:%d, fd=%d\n", inet_ntoa(sForeignAddrIn.sin_addr), sForeignAddrIn.sin_port, (int)clientSock);
} }
}; };
...@@ -160,7 +160,7 @@ int main(int argc, char** argv) ...@@ -160,7 +160,7 @@ int main(int argc, char** argv)
char ack[1024]; char ack[1024];
auto len = ap.make_ack(ack, sizeof(ack), ap.seq_.value_, ap.acct_.acct(), ap.ademcoData_.ademco_id_); auto len = ap.make_ack(ack, sizeof(ack), ap.seq_.value_, ap.acct_.acct(), ap.ademcoData_.ademco_id_);
printf("S:%s\n", ap.toString().data()); printf("S:%s\n", ap.toString().data());
send(clientSock, ack, len, 0); send(clientSock, ack, (int)len, 0);
break; break;
} }
...@@ -178,7 +178,7 @@ int main(int argc, char** argv) ...@@ -178,7 +178,7 @@ int main(int argc, char** argv)
auto len = ap.make_ack(ack, sizeof(ack), ap.seq_.value_, ap.acct_.acct(), ap.ademcoData_.ademco_id_); auto len = ap.make_ack(ack, sizeof(ack), ap.seq_.value_, ap.acct_.acct(), ap.ademcoData_.ademco_id_);
printf("S:%s\n", ap.toString().data()); printf("S:%s\n", ap.toString().data());
// send to machine via network // send to machine via network
send(clientSock, ack, len, 0); send(clientSock, ack, (int)len, 0);
} }
break; break;
...@@ -211,7 +211,7 @@ int main(int argc, char** argv) ...@@ -211,7 +211,7 @@ int main(int argc, char** argv)
fd_set fd_read; fd_set fd_read;
FD_ZERO(&fd_read); FD_ZERO(&fd_read);
FD_SET(clientSock, &fd_read); FD_SET(clientSock, &fd_read);
int nfds = select(clientSock + 1, &fd_read, (fd_set*)0, (fd_set*)0, &tv); int nfds = select(int(clientSock + 1), &fd_read, (fd_set*)0, (fd_set*)0, &tv);
if (nfds <= 0) { if (nfds <= 0) {
return; return;
} }
...@@ -221,7 +221,7 @@ int main(int argc, char** argv) ...@@ -221,7 +221,7 @@ int main(int argc, char** argv)
char* temp = clientBuffer.buff + clientBuffer.wpos; char* temp = clientBuffer.buff + clientBuffer.wpos;
size_t dwLenToRead = BUFF_SIZE - clientBuffer.wpos; size_t dwLenToRead = BUFF_SIZE - clientBuffer.wpos;
int bytes_transfered = recv(clientSock, temp, dwLenToRead, 0); int bytes_transfered = recv(clientSock, temp, (int)dwLenToRead, 0);
if (-1 == bytes_transfered) { if (-1 == bytes_transfered) {
if (EAGAIN == errno) { if (EAGAIN == errno) {
...@@ -230,14 +230,14 @@ int main(int argc, char** argv) ...@@ -230,14 +230,14 @@ int main(int argc, char** argv)
} }
if (bytes_transfered <= 0) { if (bytes_transfered <= 0) {
printf("Client %d offline\n", clientSock); printf("Client %d offline\n", (int)clientSock);
close(clientSock); clientSock = INVALID_SOCKET; close(clientSock); clientSock = INVALID_SOCKET;
clientBuffer.clear(); clientBuffer.clear();
} else { } else {
clientBuffer.wpos += bytes_transfered; clientBuffer.wpos += bytes_transfered;
auto result = do_handle(); auto result = do_handle();
while (1) { while (1) {
unsigned int bytes_not_commited = clientBuffer.wpos - clientBuffer.rpos; size_t bytes_not_commited = clientBuffer.wpos - clientBuffer.rpos;
if (bytes_not_commited == 0) { if (bytes_not_commited == 0) {
if (clientBuffer.wpos == BUFF_SIZE) { if (clientBuffer.wpos == BUFF_SIZE) {
clientBuffer.clear(); clientBuffer.clear();
...@@ -276,11 +276,11 @@ int main(int argc, char** argv) ...@@ -276,11 +276,11 @@ int main(int argc, char** argv)
auto xdata = makeXData(pwd, 6); auto xdata = makeXData(pwd, 6);
auto len = ap.make_hb(buf, sizeof(buf), 1, clientAcct, clientAdemcoId, 0, e, 0, xdata); auto len = ap.make_hb(buf, sizeof(buf), 1, clientAcct, clientAdemcoId, 0, e, 0, xdata);
printf("S:%s\n", ap.toString().data()); printf("S:%s\n", ap.toString().data());
send(clientSock, buf, len, 0); send(clientSock, buf, (int)len, 0);
} else { } else {
auto len = ap.make_hb(buf, sizeof(buf), 1, clientAcct, clientAdemcoId, 0, e, 0); auto len = ap.make_hb(buf, sizeof(buf), 1, clientAcct, clientAdemcoId, 0, e, 0);
printf("S:%s\n", ap.toString().data()); printf("S:%s\n", ap.toString().data());
send(clientSock, buf, len, 0); send(clientSock, buf, (int)len, 0);
} }
} }
...@@ -298,10 +298,11 @@ int main(int argc, char** argv) ...@@ -298,10 +298,11 @@ int main(int argc, char** argv)
std::lock_guard<std::mutex> lg(mutex); std::lock_guard<std::mutex> lg(mutex);
evntsWaiting4Send.push_back(EVENT_ARM); evntsWaiting4Send.push_back(EVENT_ARM);
} else if (cmd == 'd' || cmd == 'D') { } else if (cmd == 'd' || cmd == 'D') {
int ret = 0;
do { do {
printf("Input 6 digit password:"); printf("Input 6 digit password:");
scanf("%s", pwd); ret = scanf("%s", pwd);
} while (strlen(pwd) != 6); } while (ret != 1 || strlen(pwd) != 6);
std::lock_guard<std::mutex> lg(mutex); std::lock_guard<std::mutex> lg(mutex);
evntsWaiting4Send.push_back(EVENT_DISARM); evntsWaiting4Send.push_back(EVENT_DISARM);
} else if (cmd == 'e' || cmd == 'E') { } else if (cmd == 'e' || cmd == 'E') {
......
...@@ -472,10 +472,12 @@ int main(int argc, char** argv) ...@@ -472,10 +472,12 @@ int main(int argc, char** argv)
break; break;
case 'D': case 'D':
{
int ret = 0;
do { do {
printf("Input 6 digit password:"); printf("Input 6 digit password:");
scanf("%s", userInput.pwd); ret = scanf("%s", userInput.pwd);
} while (strlen(userInput.pwd) != 6); } while (ret != 1 || strlen(userInput.pwd) != 6);
{ {
std::lock_guard<std::mutex> lg(mutex); std::lock_guard<std::mutex> lg(mutex);
events.push_back(EVENT_DISARM); events.push_back(EVENT_DISARM);
...@@ -483,6 +485,7 @@ int main(int argc, char** argv) ...@@ -483,6 +485,7 @@ int main(int argc, char** argv)
} }
fire_command(); fire_command();
break; break;
}
case 'E': case 'E':
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment