Procházet zdrojové kódy

fix mapping for disconnect, properly break out of netmain, todo: stop main user input after disconnect

Missingmew před 5 roky
rodič
revize
d51363af21
2 změnil soubory, kde provedl 7 přidání a 3 odebrání
  1. 1 1
      cli/src/cmdman.cpp
  2. 6 2
      cli/src/ioman.cpp

+ 1 - 1
cli/src/cmdman.cpp

@@ -33,7 +33,7 @@ CmdMan::CmdMan(FileMan &fm) : fileman(fileman) {
 	
 	/* initialize handle command map */
 	handlemap["status"] = &CmdMan::handleStatus;
-	handlemap["disconnect"] = &CmdMan::handleClose;
+	handlemap["close"] = &CmdMan::handleClose;
 	handlemap["put"] = &CmdMan::handlePut;
 	handlemap["get"] = &CmdMan::handleGet;
 	handlemap["list"] = &CmdMan::handleList;

+ 6 - 2
cli/src/ioman.cpp

@@ -151,13 +151,15 @@ void IoMan::networkMain() {
 		
 		// read from network
 		readsize = boost::asio::read_until(*tcpsock, recvbuf, '\n', errcode);
-		printDebugMessage(string(__PRETTY_FUNCTION__) + string(" asio::read() ok"));
+		printDebugMessage(string(__PRETTY_FUNCTION__) + string(" asio::read() ok ") + std::to_string(readsize));
+		// printDebugMessage(string("have ") + std::to_string(toprocess.size()) + string(" commands"));
 		if (errcode && errcode != boost::asio::error::eof) {
 			printErrorMessage("IoMan::networkMain() couldnt read json data\n" + errcode.message());
 			continue;
 		}
-		
+		if(!readsize) break;
 		recvjson = (char *)(boost::asio::buffer_cast<const char *>(recvbuf.data()));
+		recvjson[readsize] = 0;
 		while(strchr(recvjson, '\n')) {
 			// parse
 			jsonsize = strchr(recvjson, '\n') - recvjson + 1;
@@ -427,6 +429,8 @@ void IoMan::run() {
 	
 	while(runmain) {
 		free(line);
+		std::this_thread::yield();
+		std::this_thread::sleep_for(std::chrono::milliseconds(10));
 		
 		line = readline(getCmdPrompt().c_str());