Index: trunk/tools/FlairGCS/src/ConnectionLayout.cpp
===================================================================
--- trunk/tools/FlairGCS/src/ConnectionLayout.cpp	(revision 244)
+++ trunk/tools/FlairGCS/src/ConnectionLayout.cpp	(revision 247)
@@ -18,10 +18,6 @@
 }
 
-QString ConnectionLayout::getUDTStats() {
-  return socket->getUDTStats();
-}
-
 void ConnectionLayout::receive(char *buf, int size) {
-  // fprintf(stderr,"trame %x\n",buf[0]);
+   //fprintf(stderr,"trame %x\n",buf[0]);
   // for(int i=0; i<size;i++) fprintf(stderr,"%x ",buf[i]);
   // fprintf(stderr,"\n");
@@ -57,4 +53,8 @@
     // fprintf(stderr,"recu %i period %i\n",size,period);
     drawDatas(&buf[3], size - 3, period);
+    break;
+  }
+  case CLOSING_CONNECTION: {
+    deleteLater();
     break;
   }
Index: trunk/tools/FlairGCS/src/ConnectionLayout.h
===================================================================
--- trunk/tools/FlairGCS/src/ConnectionLayout.h	(revision 244)
+++ trunk/tools/FlairGCS/src/ConnectionLayout.h	(revision 247)
@@ -22,5 +22,4 @@
   void LoadXml(QDomDocument to_parse);
   QString getName();
-  QString getUDTStats();
   static QString getDocRootName(char* buf, int size);
 
Index: trunk/tools/FlairGCS/src/Manager.cpp
===================================================================
--- trunk/tools/FlairGCS/src/Manager.cpp	(revision 244)
+++ trunk/tools/FlairGCS/src/Manager.cpp	(revision 247)
@@ -46,4 +46,5 @@
   // tab bar for multiple connections
   tabBar = new QTabBar();
+  //tabBar->setTabsClosable(true);
   managerLayout->addWidget(tabBar);
   connect(tabBar, SIGNAL(currentChanged(int)), this,
@@ -95,4 +96,9 @@
   }
 
+  
+  icon_ok = QIcon(":green.png");
+  icon_ko = QIcon(":red.png");
+  
+  
   QTimer *timer = new QTimer(this);
   connect(timer, SIGNAL(timeout()), this, SLOT(acceptConnections()));
@@ -101,7 +107,7 @@
 
 Manager::~Manager() {
-  for (int i = 0; i < udtSockets.count(); i++) {
-    udtSockets.at(i)->kill();
-    udtSockets.at(i)->thread()->wait();
+  for (int i = 0; i < connections.count(); i++) {
+    connections.at(i).socket->kill();
+    connections.at(i).socket->thread()->wait();
   }
 
@@ -127,6 +133,5 @@
     UdtSocket *udtSocket = new UdtSocket(socket,name);
     udtSocket->moveToThread(thread);
-    udtSockets.append(udtSocket);
-
+    
     connect(udtSocket, SIGNAL(newFileUI(UDTSOCKET)), this, SLOT(newFileUI(UDTSOCKET)));
     connect(udtSocket, SIGNAL(newConnectionLayout(QString)), this, SLOT(newConnectionLayout(QString)),Qt::BlockingQueuedConnection);
@@ -141,5 +146,4 @@
   
   ConnectionLayout *newLayout = new ConnectionLayout(udtSocket, name);
-  connectionsLayout.append(newLayout);
   connect(udtSocket, SIGNAL(UDTStats(QString)), newLayout, SIGNAL(UDTStats(QString)));//connection in 2 steps to get udtsocket as sender
   connect(newLayout, SIGNAL(UDTStats(QString)), this, SLOT(printUDTStats(QString)));
@@ -147,59 +151,80 @@
   connect(newLayout, SIGNAL(destroyed(QObject *)), this, SLOT(layoutDestroyed(QObject *)));
   connect(udtSocket, SIGNAL(destroyed(QObject *)), this, SLOT(udtSocketDestroyed(QObject *)));
-  connect(udtSocket, SIGNAL(destroyed()), newLayout, SLOT(deleteLater()));
-  
-   // widget
+  
+  // widget
   QWidget *newWidget = new QWidget();
-  connectionsWidget.append(newWidget);
   newWidget->setLayout(newLayout->getQGridLayout());
   managerLayout->insertWidget(1, newWidget);
   newWidget->hide();
   
+  connections_t connection;
+  connection.layout=newLayout;
+  connection.widget=newWidget;
+  connection.socket=udtSocket;
+  connections.append(connection);
+  
   //tab: avoid having only 1 tab (0, 2 or more)
-  if (connectionsLayout.count() == 1) { // first connection
-    connectionsWidget.at(0)->show();
+  if (connections.count() == 1) { // first connection
+    newWidget->show();
     hiddenTabName = name;
   }
-  if (connectionsLayout.count() == 2) {
-    tabBar->addTab(hiddenTabName);
+  if (connections.count() == 2) {
+    tabBar->addTab(icon_ok,hiddenTabName);
     currentTab = 0;
   }
-  if (connectionsLayout.count() > 1) {
-    tabBar->addTab(name);
+  if (connections.count() > 1) {
+    tabBar->addTab(icon_ok,name);
   }
 }
 
 void Manager::udtSocketDestroyed(QObject *obj) {
-  udtSockets.removeOne((UdtSocket *)obj);
+  fprintf(stderr,"sockets -1\n");
+  //mark socket as not valid, it can be a connection lost
+  //in this case we keep the layout for reading, and mark it as problematic
+  fprintf(stderr,"change icon\n");
+  for(int i=0;i<connections.count();i++) {
+    if(connections.at(i).socket==(UdtSocket *)obj) {
+      connections[i].socket=NULL;
+      break;
+    }
+  }
 }
 
 void Manager::layoutDestroyed(QObject *obj) {
-  int index = connectionsLayout.indexOf((ConnectionLayout *)obj);
-
-  delete connectionsWidget.at(index);
-  connectionsWidget.removeAt(index);
-  connectionsLayout.removeOne((ConnectionLayout *)obj);
-  
-  //tab: avoid having only 1 tab (0, 2 or more)
+  fprintf(stderr,"layout -1\n");
+  //remove the connection, it comes from a proper close
+  int index=-1;
+  for(int i=0;i<connections.count();i++) {
+    if(connections.at(i).layout==(ConnectionLayout *)obj) {
+      delete connections.at(i).widget;
+      //connections[i].widget=NULL;
+      //connections[i].layout=NULL;
+      connections.removeAt(i);
+      index=i;
+      break;
+    }
+  }
+  
+  if(index==-1) {
+    fprintf(stderr,"layoutDestroyed: error, layout not found!\n");
+    return;
+  }
+  
+  //tab: avoid having only 1 tab (only 0, 2 or more)
   if (tabBar->count() > 1) {
     tabBar->removeTab(index);
   }
 
-  if (connectionsLayout.count() == 1) {
+  if (connections.count() == 1) {
     hiddenTabName = tabBar->tabText(0);
     tabBar->removeTab(0);
   }
 
-  if (connectionsLayout.count() == 0) {
+  if (connections.count() == 0) {
     status->showMessage("");
   }
-  
-  
 }
 
 void Manager::newFileUI(UDTSOCKET socket) {
-  //remove udtsocket as it will be automatically destroyed
-  udtSockets.removeOne((UdtSocket *)sender());
-  
   QThread *thread = new QThread(this);
   file_ui* fileUi = new file_ui(socket,name);
@@ -216,5 +241,12 @@
 
 void Manager::printUDTStats(QString stats) {
-  int index = connectionsLayout.indexOf((ConnectionLayout *)sender());
+  int index = -1;
+  for(int i=0;i<connections.count();i++) {
+    if(connections.at(i).layout==(ConnectionLayout *)sender()) {
+      index=i;
+      break;
+    }
+  }
+  
   if(index==-1) return;
   
@@ -230,16 +262,19 @@
   if (index >= 0) {
     //if we are coming from layout destroyed
-    if(currentTab<connectionsLayout.count()) connectionsWidget.at(currentTab)->hide();
-    connectionsWidget.at(index)->show();
+    if(currentTab<connections.count()) connections.at(currentTab).widget->hide();
+    connections.at(index).widget->show();
     currentTab = index;
   } else {
     currentTab = 0;
-    connectionsWidget.at(0)->show();
-  }
+    connections.at(0).widget->show();
+  }
+  QString msg="not connected";
   if (tabBar->count() == 0) {
-    status->showMessage(connectionsLayout.at(0)->getUDTStats());
+    if(connections.at(0).socket!=NULL) msg=connections.at(0).socket->getUDTStats();
+    
   } else {
-    status->showMessage(QString("%1: %2").arg(tabBar->tabText(index)).arg(connectionsLayout.at(index)->getUDTStats()));
-  }
+    if(connections.at(index).socket!=NULL) msg=QString("%1: %2").arg(tabBar->tabText(index)).arg(connections.at(index).socket->getUDTStats());
+  }
+  status->showMessage(msg);
 }
 
@@ -249,12 +284,12 @@
 
   if (dir_name != "") {
-    for (int i = 0; i < connectionsLayout.count(); i++) {
+    for (int i = 0; i < connections.count(); i++) {
       QFile *file;
       file = new QFile(dir_name + "/" +
-                       connectionsLayout.at(i)->getName() + ".xml");
+                       connections.at(i).layout->getName() + ".xml");
       if (!file->open(QIODevice::ReadOnly | QIODevice::Text)) {
         QMessageBox::warning(this, "Warning",
                              "Enable to load " +
-                                 connectionsLayout.at(i)->getName() +
+                                 connections.at(i).layout->getName() +
                                  ".xml");
         continue;
@@ -268,9 +303,9 @@
         QMessageBox::critical(
             this, "Error",
-            "unable to read " + connectionsLayout.at(i)->getName() +
+            "unable to read " + connections.at(i).layout->getName() +
                 ".xml" + " (" + errorMsg + " at " + QString::number(errorLine) +
                 "," + QString::number(errorColumn) + ")");
       } else {
-        connectionsLayout.at(i)->LoadXml(doc);
+        connections.at(i).layout->LoadXml(doc);
       }
       delete file;
@@ -282,6 +317,6 @@
   bool isUptodate = true;
 
-  for (int i = 0; i < connectionsLayout.count(); i++) {
-    if (!connectionsLayout.at(i)->IsUptodate()) {
+  for (int i = 0; i < connections.count(); i++) {
+    if (!connections.at(i).layout->IsUptodate()) {
       isUptodate = false;
       break;
@@ -319,10 +354,10 @@
   QDir().mkdir(dir_name);
 
-  for (int i = 0; i < connectionsLayout.count(); i++) {
+  for (int i = 0; i < connections.count(); i++) {
     QDomDocument *xml = new QDomDocument("remote_ui_xml");
 
-    connectionsLayout.at(i)->GetFullXml((QDomElement *)xml);
-
-    QFile fichier(dir_name + "/" + connectionsLayout.at(i)->getName() +
+    connections.at(i).layout->GetFullXml((QDomElement *)xml);
+
+    QFile fichier(dir_name + "/" + connections.at(i).layout->getName() +
                   ".xml");
     QString write_doc = (xml->ownerDocument()).toString();
@@ -344,15 +379,15 @@
 
 void Manager::send(void) {
-  for (int i = 0; i < connectionsLayout.count(); i++) {
+  for (int i = 0; i < connections.count(); i++) {
     QDomDocument doc("remote_ui_xml");
-    connectionsLayout.at(i)->GetUpdateXml((QDomElement *)&doc);
+    connections.at(i).layout->GetUpdateXml((QDomElement *)&doc);
     // fprintf(stderr,"merge\n%s\n",doc.toString().toLocal8Bit().constData());
 
-    connectionsLayout.at(i)->XmlToSend(doc);
+    connections.at(i).layout->XmlToSend(doc);
   }
 }
 
 void Manager::reset() {
-  for (int i = 0; i < connectionsLayout.count(); i++)
-    connectionsLayout.at(i)->ResetAllChilds();
-}
+  for (int i = 0; i < connections.count(); i++)
+    connections.at(i).layout->ResetAllChilds();
+}
Index: trunk/tools/FlairGCS/src/Manager.h
===================================================================
--- trunk/tools/FlairGCS/src/Manager.h	(revision 244)
+++ trunk/tools/FlairGCS/src/Manager.h	(revision 247)
@@ -7,4 +7,5 @@
 
 #include <QWidget>
+#include <QIcon>
 #include <udt.h>
 #include <qdom.h>
@@ -28,7 +29,12 @@
   UDTSOCKET serv;
   QVBoxLayout *managerLayout;
-  QList<ConnectionLayout *> connectionsLayout;
-  QList<QWidget *> connectionsWidget;
-  QList<UdtSocket *> udtSockets;
+  typedef struct {
+    ConnectionLayout *layout;
+    QWidget *widget;
+    UdtSocket *socket;
+  } connections_t;
+  QList<connections_t> connections;
+  //QList<ConnectionLayout *> connectionsLayout;
+  //QList<UdtSocket *> udtSockets;
   QTabBar *tabBar;
   QString name, hiddenTabName;
@@ -41,4 +47,5 @@
   QGridLayout *button_layout;
   QStatusBar *status;
+  QIcon icon_ok,icon_ko;
 
 private slots:
Index: trunk/tools/FlairGCS/src/UdtSocket.cpp
===================================================================
--- trunk/tools/FlairGCS/src/UdtSocket.cpp	(revision 244)
+++ trunk/tools/FlairGCS/src/UdtSocket.cpp	(revision 247)
@@ -53,5 +53,6 @@
   heartbeat_timer->stop();
   udtstats_timer->stop();
-  if(destroySocket) UDT::close(socket);         
+  if(destroySocket) UDT::close(socket);
+fprintf(stderr,"fin udt\n");
 }
 
@@ -151,6 +152,6 @@
     int num = 1;
     UDTSOCKET readfds;
+  
     int rv = UDT::epoll_wait2(eid, &readfds, &num,NULL, NULL,100);
-  
     if (rv == -1) {
       if (UDT::getlasterror().getErrorCode() != 6003)
@@ -158,58 +159,75 @@
     } else if(readfds==socket && num==1 && rv==1) {
        
-      int size=UDT::recvmsg(socket, buf, buf_size);
-      if (size > 0) {
-        total_received+=size;
-        
-        switch ((unsigned char)buf[0]) {
-          case ZLIB_HEADER: {
-            ssize_t out_size;
-            uncompressBuffer(buf, size, uncompressbuf, &out_size);
-            if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) {
-              socketType=gui;
-              QString remoteName=ConnectionLayout::getDocRootName(uncompressbuf, out_size);
-              setName(remoteName);
-              emit newConnectionLayout(remoteName);//connection is Qt::BlockingQueuedConnection
+      int size;
+      do {
+        size=UDT::recvmsg(socket, buf, buf_size);
+      
+        //fprintf(stderr,"recu %i\n",size);
+        if (size > 0) {
+          total_received+=size;
+          
+          switch ((unsigned char)buf[0]) {
+            case ZLIB_HEADER: {
+              ssize_t out_size;
+              uncompressBuffer(buf, size, uncompressbuf, &out_size);
+              if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) {
+                socketType=gui;
+                QString remoteName=ConnectionLayout::getDocRootName(uncompressbuf, out_size);
+                setName(remoteName);
+                emit newConnectionLayout(remoteName);//connection is Qt::BlockingQueuedConnection
+              }
+              emit dataReady(uncompressbuf, out_size);//connection is Qt::BlockingQueuedConnection, as we have only one buffer
+              break;
             }
-            emit dataReady(uncompressbuf, out_size);//connection is Qt::BlockingQueuedConnection, as we have only one buffer
-            break;
+            case START_SENDING_FILES: {
+              if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) {
+                socketType=log;
+              }
+              setName("log files");
+              heartbeat_timer->stop();
+              emit newFileUI(socket);
+              deleteLater();
+              stop=true;
+              destroySocket=false;
+              break;
+            }
+            case XML_HEADER:
+              if(socketType==unknown) {
+                socketType=gui;
+                QString remoteName=ConnectionLayout::getDocRootName(buf, size );
+                setName(remoteName);
+                emit newConnectionLayout(remoteName);
+              }
+            case DATAS_BIG_ENDIAN:
+            case DATAS_LITTLE_ENDIAN:
+              emit dataReady(buf, size );
+              break;
+            case CLOSING_CONNECTION:
+              fprintf(stderr,"%s, connection closed\n",name.toLocal8Bit().constData());
+              emit dataReady(buf, size );
+              stop = true;
+              heartbeat_timer->stop();
+              deleteLater();
+              break;
+            default:
+              fprintf(stderr,"trame non supportée %x\n", buf[0]);
           }
-          case START_SENDING_FILES: {
-            if((unsigned char)uncompressbuf[0]==XML_HEADER && socketType==unknown) {
-              socketType=log;
-            }
-            setName("log files");
-            heartbeat_timer->stop();
-            emit newFileUI(socket);
-            deleteLater();
-            stop=true;
-            destroySocket=false;
-            break;
-          }
-          case XML_HEADER:
-            if(socketType==unknown) {
-              socketType=gui;
-              QString remoteName=ConnectionLayout::getDocRootName(buf, size );
-              setName(remoteName);
-              emit newConnectionLayout(remoteName);
-            }
-          case DATAS_BIG_ENDIAN:
-          case DATAS_LITTLE_ENDIAN:
-            emit dataReady(buf, size );
-            break;
+        } else {
+          //not necessary to check, watchdog (heartbeat_timer) can do it
+          //if(UDT::getlasterror().getErrorCode()!=6002 && !stop) 
+            //fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage());
+          //UDT::close(socket);//si deconnecté
+          //free(buf);
+          //break;
         }
-      } else {
-        if(UDT::getlasterror().getErrorCode()!=6002) 
-          fprintf(stderr,"udt socket: %s %i\n",UDT::getlasterror().getErrorMessage(),size);
-        //UDT::close(socket);//si deconnecté
-        //free(buf);
-        //break;
-      }
+      } while(size>0);
     } else {
-      fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage());
+      //not necessary to check, watchdog (heartbeat_timer) can do it
+      //fprintf(stderr,"udt socket: %s\n",UDT::getlasterror().getErrorMessage());
     }
     UDT::epoll_remove_usock(eid, socket);
     UDT::epoll_release(eid);
   }
+  
   free(uncompressbuf);
   free(buf);
Index: trunk/tools/FlairGCS/src/ressources.qrc
===================================================================
--- trunk/tools/FlairGCS/src/ressources.qrc	(revision 244)
+++ trunk/tools/FlairGCS/src/ressources.qrc	(revision 247)
@@ -5,4 +5,6 @@
   <file>landmark.png</file>
   <file>cross.png</file>
+  <file>green.png</file>
+  <file>red.png</file>
 </qresource>
 </RCC>
