Index: gw/smppbox.c
===================================================================
--- gw/smppbox.c	(revision 43)
+++ gw/smppbox.c	(working copy)
@@ -399,16 +399,20 @@
     Msg *msg;
 
     pack = NULL;
-    switch (read_from_bearerbox_real(conn, &msg, INFINITE_TIME)) {
-    case -1:
-	// connection to bearerbox lost
-	break;
-    case  0:
-	// all is well
-	break;
-    case  1:
-	// timeout
-	break;
+    while (boxconn->alive) {
+	switch (read_from_bearerbox_real(conn, &msg, 1.0)) {
+	case -1:
+	    /* connection to bearerbox lost */
+	    return NULL;
+	    break;
+	case  0:
+	    /* all is well */
+	    return msg;
+	    break;
+	case  1:
+	    /* timeout */
+	    break;
+	}
     }
 
     return msg;
@@ -1608,7 +1612,7 @@
     if (boxc->smpp_connection)
 	    conn_destroy(boxc->smpp_connection);
     if (boxc->bearerbox_connection)
-	    close_connection_to_bearerbox_real(boxc->bearerbox_connection);
+	    conn_destroy(boxc->bearerbox_connection);
     if (boxc->boxc_id)
 	    octstr_destroy(boxc->boxc_id);
     if (boxc->alt_charset)
@@ -1732,7 +1736,7 @@
 
 	msg = read_from_box(box->bearerbox_connection, box);
         if (msg == NULL) {
-	    if (conn_eof(box->bearerbox_connection)) {
+	    if ((!box->alive) || conn_eof(box->bearerbox_connection)) {
             	/* tell smppbox to die */
 	    	/* the client closes the connection, after that die in receiver */
 	    	box->alive = 0;
@@ -1914,7 +1918,6 @@
 	    boxc_destroy(newconn);
 	    return;
     }
-    /* identify_to_bearerbox(newconn); */
 
     gwlist_append(all_boxes, newconn);
 
