project_files/frontlib/ipc/mapconn.c
changeset 7576 65d29988fd3d
parent 7316 f7b49b2c5d84
child 10017 de822cd3df3a
--- a/project_files/frontlib/ipc/mapconn.c	Sat Aug 18 21:05:30 2012 +0200
+++ b/project_files/frontlib/ipc/mapconn.c	Sun Aug 19 15:05:23 2012 +0200
@@ -30,6 +30,7 @@
 typedef enum {
 	AWAIT_CONNECTION,
 	AWAIT_REPLY,
+	AWAIT_CLOSE,
 	FINISHED
 } mapconn_state;
 
@@ -160,15 +161,24 @@
 
 	if(conn->progress == AWAIT_REPLY) {
 		if(flib_ipcbase_recv_map(conn->ipcBase, conn->mapBuffer) >= 0) {
-			conn->progress = FINISHED;
-			conn->onSuccessCb(conn->onSuccessCtx, conn->mapBuffer, conn->mapBuffer[IPCBASE_MAPMSG_BYTES-1]);
-			return;
+			conn->progress = AWAIT_CLOSE;
 		} else if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
 			conn->progress = FINISHED;
 			conn->onFailureCb(conn->onSuccessCtx, "Engine connection closed unexpectedly.");
 			return;
 		}
 	}
+
+	if(conn->progress == AWAIT_CLOSE) {
+		// Just do throwaway reads so we find out when the engine disconnects
+		uint8_t buf[256];
+		flib_ipcbase_recv_message(conn->ipcBase, buf);
+		if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
+			conn->progress = FINISHED;
+			conn->onSuccessCb(conn->onSuccessCtx, conn->mapBuffer, conn->mapBuffer[IPCBASE_MAPMSG_BYTES-1]);
+			return;
+		}
+	}
 }
 
 void flib_mapconn_tick(flib_mapconn *conn) {