Changeset 234 in flair-src for trunk/lib/FlairCore/src


Ignore:
Timestamp:
04/10/18 17:05:27 (6 years ago)
Author:
Sanahuja Guillaume
Message:

create file oscket only when necessary

Location:
trunk/lib/FlairCore/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/FrameworkManager_impl.cpp

    r214 r234  
    193193      Printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());
    194194
    195     status = UDT::close(file_sock);
    196     if (status != 0)
    197       Printf("Error udt::close %s", UDT::getlasterror().getErrorMessage());
    198 
    199195    SleepMS(200); // a revoir, sinon UDT::cleanup bloque en RT
    200196    UDT::cleanup();
     
    210206    return;
    211207  }
     208  this->address=address;
     209  this->port=port;
    212210                                                                                                                                                                                       
    213211        UDT::startup(1024*256,1024*256,1024*256);
     
    216214  // socket file_socket, doit être créé en premier, cf station sol
    217215  Printf("Connecting to %s:%i\n", address.c_str(), port);
    218   file_sock = GetSocket(address, port);
    219   com_sock = GetSocket(address, port);
     216  //file_sock = GetSocket(address, port);
     217  com_sock = GetSocket();
    220218
    221219  // receive buffer allocation
     
    226224
    227225  com = new ui_com(this, com_sock);
    228 
    229   // file managment
    230   bool blocking = true;
    231   UDT::setsockopt(file_sock, 0, UDT_SNDSYN, &blocking, sizeof(bool));
    232   UDT::setsockopt(file_sock, 0, UDT_RCVSYN, &blocking, sizeof(bool));
    233 
    234   int timeout = 100; // ms
    235   UDT::setsockopt(com_sock, 0, UDT_RCVTIMEO, &timeout, sizeof(int));
    236226
    237227  Start();
     
    292282  while (!ToBeStopped()) {
    293283    ssize_t bytesRead;
    294 
    295284    bytesRead = com->Receive(rcv_buf, rcv_buf_size);
    296 
     285    com->CheckConnection();
     286//printf("%i\n",bytesRead);
    297287    if (bytesRead == (ssize_t)rcv_buf_size)
    298288      Err("FrameworkManager max receive size, augmenter le buffer size!\n");
    299289
    300290    if (bytesRead > 0) {
    301       // printf("recu %ld, trame %x\n",bytesRead,(uint8_t)rcv_buf[0]);
    302       // rcv_buf[bytesRead-1]=0;//pour affichage
    303       // printf("%s\n",rcv_buf);
     291       //printf("recu %ld, trame %x %lld\n",bytesRead,(uint8_t)rcv_buf[0],GetTime()/(1000000));
     292       //rcv_buf[bytesRead-1]=0;//pour affichage
     293       //printf("%s\n",rcv_buf);
    304294
    305295      switch ((uint8_t)rcv_buf[0]) {
     
    376366}
    377367
    378 void FrameworkManager_impl::SendFile(string path, string name) {
     368void FrameworkManager_impl::SendFile(UDTSOCKET socket,string path, string name) {
    379369  char *buf, *more_buf;
    380370  int size;
     
    411401  Printf("sending %s, size: %i\n", filename.c_str(), size);
    412402  // send file information
    413   UDT::sendmsg(file_sock, buf, sizeof(uint8_t) + sizeof(int) + name.size(), -1,true);
     403  UDT::sendmsg(socket, buf, sizeof(uint8_t) + sizeof(int) + name.size(), -1,true);
    414404
    415405  more_buf = (char *)realloc((void *)buf, size);
     
    424414  pbuf->sgetn(buf, size);
    425415  // send the file
    426   nb_write = UDT::sendmsg(file_sock, buf, size, -1, true);
     416  nb_write = UDT::sendmsg(socket, buf, size, -1, true);
    427417
    428418  if (nb_write < 0) {
     
    436426}
    437427
    438 void FrameworkManager_impl::FinishSending() {
     428void FrameworkManager_impl::FinishSending(UDTSOCKET socket) {
    439429  char rm_cmd[256];
    440430
    441431  // send orignal xml
    442   SendFile(log_path, "setup.xml");
     432  SendFile(socket,log_path, "setup.xml");
    443433  sprintf(rm_cmd, "rm %s/setup.xml", log_path.c_str());
    444434  system(rm_cmd);
     
    447437  for (size_t i = 0; i < xml_changes.size(); i++) {
    448438    // Printf("%s\n",xml_changes.at(i).c_str());
    449     SendFile(log_path, xml_changes.at(i).c_str());
     439    SendFile(socket,log_path, xml_changes.at(i).c_str());
    450440    sprintf(rm_cmd, "rm %s/%s", log_path.c_str(), xml_changes.at(i).c_str());
    451441    system(rm_cmd);
     
    454444
    455445  // end notify
    456   char buf = END;
    457   int nb_write = UDT::sendmsg(file_sock, &buf, 1, -1, true);
     446  char buf = END_SENDING_FILES;
     447  int nb_write = UDT::sendmsg(socket, &buf, 1, -1, true);
    458448
    459449  if (nb_write < 0) {
     
    464454
    465455  //wait end ACK
    466   int nb_read = UDT::recvmsg(file_sock,&buf,1);
     456  int nb_read = UDT::recvmsg(socket,&buf,1);
    467457  if(nb_read<0) {
    468458    Err("UDT::recvmsg error (%s)\n",UDT::getlasterror().getErrorMessage());
     
    472462}
    473463
    474 UDTSOCKET FrameworkManager_impl::GetSocket(string address, uint16_t port) {
     464UDTSOCKET FrameworkManager_impl::GetSocket(void) {
    475465  while (1) {
    476466    UDTSOCKET new_fd;
     
    854844              caller->gcs_watchdog->Join();
    855845          }
     846          //create a socket for files
     847          UDTSOCKET file_sock = caller->GetSocket();
     848          char data=START_SENDING_FILES;
     849          ssize_t nb_write = UDT::sendmsg(file_sock, &data, 1, -1, true);
     850          if (nb_write < 0) {
     851            caller->Err("UDT::sendmsg error (%s)\n", UDT::getlasterror().getErrorMessage());
     852            if (UDT::getlasterror().getErrorCode() == CUDTException::ECONNLOST ||
     853                UDT::getlasterror().getErrorCode() == CUDTException::EINVSOCK) {
     854            }
     855          } else if (nb_write != 1) {
     856            caller->Err("%s, code %i (%ld/%ld)\n", UDT::getlasterror().getErrorMessage(),
     857                UDT::getlasterror().getErrorCode(), nb_write, 1);
     858          }
    856859          for (size_t i = 0; i < logs.size(); i++) {
    857860            if (logs.at(i).dbtFile != NULL) {
     
    859862
    860863              string filename = caller->FileName(logs.at(i).device) + ".dbt";
    861               caller->SendFile(caller->log_path, filename);
     864              caller->SendFile(file_sock,caller->log_path, filename);
    862865
    863866              fstream txt_file;
     
    870873              txt_file.close();
    871874
    872               caller->SendFile(caller->log_path, filename);
     875              caller->SendFile(file_sock,caller->log_path, filename);
    873876            }
    874877          }
    875878          // a revoir celui ci est le xml enregistré et pas forcement l'actuel
    876879          // if(caller->xml_file!="") caller->SendFile(caller->xml_file);
    877           caller->FinishSending();
     880          caller->FinishSending(file_sock);
     881         
     882          int status = UDT::close(file_sock);
     883          if (status != 0)
     884            caller->Err("Error udt::close %s", UDT::getlasterror().getErrorMessage());
    878885
    879886          logs.clear();
  • trunk/lib/FlairCore/src/ui_com.cpp

    r213 r234  
    223223}
    224224
     225void ui_com::CheckConnection(void) {
     226  int32_t val,len;
     227 
     228  int result=UDT::getsockopt(socket_fd,0,UDT_STATE,&val,&len);
     229   if (result < 0) {
     230    Printf("UDT::getsockopt error (%s)\n", UDT::getlasterror().getErrorMessage());
     231   }
     232 // printf("opt: %i %i %i\n",result,val,len);
     233}
     234
    225235void ui_com::Run(void) {
    226236  // check endianness
  • trunk/lib/FlairCore/src/unexported/FrameworkManager_impl.h

    r213 r234  
    8282private:
    8383  flair::core::FrameworkManager *self;
    84   UDTSOCKET file_sock, com_sock;
    85   UDTSOCKET GetSocket(std::string address, uint16_t port);
     84  UDTSOCKET com_sock;
     85  UDTSOCKET GetSocket(void);
    8686  void Run();
    87   void SendFile(std::string path, std::string name);
    88   void FinishSending(void);
     87  void SendFile(UDTSOCKET socket,std::string path, std::string name);
     88  void FinishSending(UDTSOCKET socket);
    8989  std::string FileName(flair::core::IODevice *device);
    9090  void SaveXmlChange(char *buf);
     
    9292  size_t rcv_buf_size;
    9393  char *rcv_buf;
     94  std::string address;
     95  uint16_t port;
    9496#ifdef __XENO__
    9597  int CreatePipe(RT_PIPE *fd, std::string name);
  • trunk/lib/FlairCore/src/unexported/communication.h

    r15 r234  
    66#define COMMUNICATION_H
    77
    8 // messages file socket
    9 #define FILE_INFO_LITTLE_ENDIAN 0x01
    10 #define FILE_INFO_BIG_ENDIAN 0x02
    11 #define END 0x03
    12 
     8// messages data socket
    139#define XML_HEADER 0x3c
    1410#define ZLIB_HEADER 0x78
    1511#define WATCHDOG_HEADER 0x01
     12#define DATAS_LITTLE_ENDIAN 0x02
     13#define DATAS_BIG_ENDIAN 0x03
    1614
    17 #define DATAS_LITTLE_ENDIAN 0xfd
    18 #define DATAS_BIG_ENDIAN 0xfe
     15#define START_SENDING_FILES 0x10
     16#define FILE_INFO_LITTLE_ENDIAN 0x11
     17#define FILE_INFO_BIG_ENDIAN 0x12
     18#define END_SENDING_FILES 0x13
    1919
    2020#endif // COMMUNICATION_H
  • trunk/lib/FlairCore/src/unexported/ui_com.h

    r15 r234  
    4848  void UnBlock(void);
    4949  bool ConnectionLost(void);
    50 
     50  void CheckConnection(void);
    5151private:
    5252  ssize_t send_size;
Note: See TracChangeset for help on using the changeset viewer.