summaryrefslogtreecommitdiff
path: root/src/net/ipc.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-07-19 18:50:18 +0300
committerAndrei Karas <akaras@inbox.ru>2014-07-19 18:50:18 +0300
commit2d5ded6b4f51b6d056ed6f2ae68aa208373c48ac (patch)
tree8ddd0d661e6717bc374f28037ef8e626568e9ca8 /src/net/ipc.cpp
parent104113ad2d968b48ded17f5d23d7c509627a509a (diff)
downloadmv-2d5ded6b4f51b6d056ed6f2ae68aa208373c48ac.tar.gz
mv-2d5ded6b4f51b6d056ed6f2ae68aa208373c48ac.tar.bz2
mv-2d5ded6b4f51b6d056ed6f2ae68aa208373c48ac.tar.xz
mv-2d5ded6b4f51b6d056ed6f2ae68aa208373c48ac.zip
Remove from ipc code try/catch and add missing check.
Diffstat (limited to 'src/net/ipc.cpp')
-rw-r--r--src/net/ipc.cpp76
1 files changed, 34 insertions, 42 deletions
diff --git a/src/net/ipc.cpp b/src/net/ipc.cpp
index b9367caf0..03113902d 100644
--- a/src/net/ipc.cpp
+++ b/src/net/ipc.cpp
@@ -83,54 +83,46 @@ int IPC::acceptLoop(void *ptr)
SDLNet_SocketSet set = SDLNet_AllocSocketSet(1);
SDLNet_TCP_AddSocket(set, ipc1->mSocket);
ipc->mListen = true;
- try
+ while (ipc1->mListen)
{
- while (ipc1->mListen)
+ SDLNet_CheckSockets(set, 250);
+ if (!SDLNet_SocketReady(ipc1->mSocket))
+ continue;
+
+ TCPsocket sock = SDLNet_TCP_Accept(ipc1->mSocket);
+ if (!sock)
+ {
+ logger->log_r("IPC: unable to accept connection");
+ continue;
+ }
+ char data[max_length] = {0};
+ int result = SDLNet_TCP_Recv(sock, data, max_length);
+ if (result <= 0)
{
- SDLNet_CheckSockets(set, 250);
- if (!SDLNet_SocketReady(ipc1->mSocket))
- continue;
-
- TCPsocket sock = SDLNet_TCP_Accept(ipc1->mSocket);
- if (!sock)
- {
- logger->log_r("IPC: unable to accept connection");
- continue;
- }
- char data[max_length] = {0};
- int result = SDLNet_TCP_Recv(sock, data, max_length);
- if (result <= 0)
- {
- logger->log_r("IPC: unable to accept connection");
- SDLNet_TCP_Close(sock);
- continue;
- }
-
- std::string req(data);
- req = trim(req);
+ logger->log_r("IPC: unable to accept connection");
+ SDLNet_TCP_Close(sock);
+ continue;
+ }
+ std::string req(data);
+ req = trim(req);
+
+ if (chatWindow)
chatWindow->chatInput(req);
- ipc1->mNumReqs ++;
- const std::string resp = strprintf("[%d] %s\n",
- ipc1->mNumReqs, req.c_str());
-
- const char *respc = resp.c_str();
- const int len = strlen(respc) + 1;
- result = SDLNet_TCP_Send(sock, respc, len);
- if (result < len)
- {
- logger->log_r("IPC: SDLNet_TCP_Send: %s\n", SDLNet_GetError());
- SDLNet_TCP_Close(sock);
- continue;
- }
+ ipc1->mNumReqs ++;
+ const std::string resp = strprintf("[%d] %s\n",
+ ipc1->mNumReqs, req.c_str());
+
+ const char *respc = resp.c_str();
+ const int len = strlen(respc) + 1;
+ result = SDLNet_TCP_Send(sock, respc, len);
+ if (result < len)
+ {
+ logger->log_r("IPC: SDLNet_TCP_Send: %s\n", SDLNet_GetError());
SDLNet_TCP_Close(sock);
+ continue;
}
- }
- catch (std::exception& e)
- {
- std::cerr << e.what() << std::endl;
- SDLNet_TCP_Close(ipc1->mSocket);
- return 1;
+ SDLNet_TCP_Close(sock);
}
SDLNet_TCP_Close(ipc1->mSocket);
return 0;