Ejemplo n.º 1
0
TSimpleFileTransport::
TSimpleFileTransport(const std::string& path, bool read, bool write)
    : TFDTransport(-1, TFDTransport::CLOSE_ON_DESTROY) {
  int flags = 0;
  if (read && write) {
    flags = O_RDWR;
  } else if (read) {
    flags = O_RDONLY;
  } else if (write) {
    flags = O_WRONLY;
  } else {
    throw TTransportException("Neither READ nor WRITE specified");
  }
  if (write) {
    flags |= O_CREAT | O_APPEND;
  }
  int fd = ::open(path.c_str(),
                  flags,
                  S_IRUSR | S_IWUSR| S_IRGRP | S_IROTH);
  if (fd < 0) {
    throw TTransportException("failed to open file for writing: " + path);
  }
  setFD(fd);
  open();
}
TSimpleFileTransport::TSimpleFileTransport(const std::string& path, bool read, bool write, bool append)
    : TFDTransport(-1, TFDTransport::CLOSE_ON_DESTROY) {
  int flags = 0;
  if (read && write) {
    flags = O_RDWR;
  } else if (read) {
    flags = O_RDONLY;
  } else if (write) {
    flags = O_WRONLY;
  } else {
    throw TTransportException("Neither READ nor WRITE specified");
  }

  flags |= O_BINARY; // unix에는 없지만 windows에서는 넣어주어야 모든 곳에서 사용가능 (O_BINARY아닐 때 \r\n을 붙이는 문제가 발생함.) - joygram(2016/02/01)
  if (write) {
	  flags |= O_CREAT;
	  if (append) {
		  flags |= O_APPEND;
	  } else if (false == read) {
		  flags |= O_TRUNC; // 읽는 것도 아니고 덧대는 것이 아닌 경우 기존 내용 제거 joygram(2016/02/01) 
	  }
  }
#ifndef _WIN32
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
#else
  int mode = _S_IREAD | _S_IWRITE;
#endif
  int fd = ::THRIFT_OPEN(path.c_str(), flags, mode);
  if (fd < 0) {
    throw TTransportException("failed to open file for writing: " + path);
  }
  setFD(fd);
  open();
}
TSimpleFileTransport::
TSimpleFileTransport(const std::string& path, bool read, bool write)
    : TFDTransport(-1, TFDTransport::CLOSE_ON_DESTROY) {
  int flags = 0;
  if (read && write) {
    flags = O_RDWR;
  } else if (read) {
    flags = O_RDONLY;
  } else if (write) {
    flags = O_WRONLY;
  } else {
    LOG(ERROR, __func__ << ": Neither READ nor WRITE specified");
    assert(false);
  }
  if (write) {
    flags |= O_CREAT | O_APPEND;
  }
#ifndef _WIN32
  mode_t mode = S_IRUSR | S_IWUSR| S_IRGRP | S_IROTH;
#else
  int mode = _S_IREAD | _S_IWRITE;
#endif
  int fd = ::open(path.c_str(),
                  flags,
                  mode);
  if (fd < 0) {
    LOG(ERROR, __func__ << ": Failed to open file for writing: " << path);
    assert(false);
  }
  setFD(fd);
  open();
}
Ejemplo n.º 4
0
void    Client::selectLoop()
{
  fd_set  fd_read;
  fd_set  fd_write;
  struct timeval tv;

  tv.tv_sec = 0;
  tv.tv_usec = 10000;
  while (42)
    {
      setFD(&fd_read, &fd_write);
      if ((select(_fd + 1, &fd_read, &fd_write, NULL, &tv)) == -1)
	perror("Error during execution : Exiting programm\n");
      findFDRead(&fd_read);
      findFDWrite(&fd_write);
    }
}
Ejemplo n.º 5
0
void    Client::update()
{
  int   i;
  struct timeval tv;

  tv.tv_sec = 0;
  tv.tv_usec = 10000;
  _end = true;
  for (i = 0; i < 1000000; i++)
  {
    setFD(&fd_read, &fd_write);
    if ((select(_fd + 1, &fd_read, &fd_write, NULL, &tv)) == -1)
    perror("Error during execution : Exiting programm\n");
    findFDRead(&fd_read);
    findFDWrite(&fd_write);
    _buffOut = "";
    if (_end == true)
      break;
  }
  if (i == 1000000)
    std::cout << "Warning: condition end is not reach on data income from server !" << std::endl;
  arangeCommands();
}
Ejemplo n.º 6
0
/** @ingroup SystemInfo
 * @brief Allows the caller to determine the value of various NSP2000 and API
 * system and configuration values.
 *
 * The configuration parameter desired is determined by the value specified in
 * Parameter. Note that the hash units are currently being treated the same
 * as the EA units since the NSP2000 does not have a separate hash core.
 *
 *  @param parameter   RO:  A constant naming the configuration value to 
 *                          return.
 *  @param value_p     WO:  A pointer to where to return the value(s) of the
 *                          requested system parameter. The format (type) of
 *                          what is returned depends on the value of
 *                          Parameter.
 *
 * @return
 *    returnResult - returns N8_STATUS_OK if successful or Error value.
 * @par Errors
 *      N8_INVALID_ENUM -     The value of Parameter is not one of the 
 *                            defined valid configuration enumerations. 
 *      N8_INVALID_OBJECT     The output parameter is NULL.
 * @par Assumptions
 *    None<br>
 *****************************************************************************/
N8_Status_t N8_GetSystemParameter(N8_Parameter_t parameter, void *value_p)
{
   N8_Status_t ret = N8_STATUS_OK;

   DBG(("N8_GetSystemParameter\n"));
   do
   {
       ret = N8_preamble();
       CHECK_RETURN(ret);

       /* verify value object */
       CHECK_OBJECT(value_p, ret);

       switch (parameter)
       {
           case N8_EACOUNT:
              ret = setCount(value_p, N8_EA);
              break;
           case N8_EATYPE:
              ret = setType(value_p, N8_EA);
              break;
           case N8_PKCOUNT:
              ret = setCount(value_p, N8_PKP);
              break;
           case N8_PKTYPE:
              ret = setType(value_p, N8_PKP);
              break;
           case N8_HPCOUNT:
              ret = setCount(value_p, N8_EA);
              break;
           case N8_HPTYPE:
              ret = setType(value_p, N8_EA);
              break;
           case N8_HARDWAREVERSION:
              ret = setHWversion(value_p);
              break;
           case N8_HARDWAREREVISION:
              ret = setHWrevision(value_p);
              break;
           case N8_SOFTWAREVERSION:
              ret = setSWversion(value_p);
              break;
           case N8_CONTEXTMEMSIZE:
              ret = setContextSize(value_p);
              break;
           case N8_SKSMEMSIZE:
              ret = setSKSsize(value_p);
              break;
           case N8_NUMBEROFCHIPS:
              ret = setNumberOfChips(value_p);
              break;
           case N8_SWVERSIONTEXT:
              ret = setSWversionText(value_p);
              break;
           case N8_INITIALIZE_INFO:
              ret = setInitInfo(value_p);
              break;
           case N8_FILEDESCRIPTOR:
              ret = setFD(value_p);
              break;
           default:
              /* invalid parameter */
              DBG(("Invalid parameter\n"));
              DBG(("N8_GetSystemParameter - return Error\n"));
              ret = N8_INVALID_ENUM;
              break;
       } /* switch */
   }while (FALSE);
   DBG(("N8_GetSystemParameter - OK\n"));
   return ret;
} /* N8_GetSystemParameter */
Ejemplo n.º 7
0
EvNIOReader::EvNIOReader(FD fd):fd(-1){
    readevio.set<EvNIOReader, &EvNIOReader::readCallback>(this);
    setFD(fd);
}