Exemple #1
0
int rr_flush (rr_dev dev)
{
#ifndef WIN32
  /* Disable non-blocking mode */
  int flags;
  if ((flags = fcntl (dev->fd, F_GETFL, 0)) < 0)
    return flags;

  if (fcntl (dev->fd, F_SETFL, flags & ~O_NONBLOCK) == -1)
    return -1;
#endif

  int result = 0;
  while (rr_dev_buffered (dev) && result >= 0)
    result = rr_dev_handle_writable (dev);

#ifndef WIN32
  /* Restore original mode */
  if (result >= 0)
    result = fcntl (dev->fd, F_SETFL, flags);
  else
    fcntl (dev->fd, F_SETFL, flags);
#endif

  return result;
}
Exemple #2
0
bool Model::handle_dev_fd (Glib::IOCondition cond)
{
  int result;
  if (cond & Glib::IO_IN) {
    result = rr_dev_handle_readable (m_device);
    if (result < 0)
      error ("Error reading from device!", strerror (errno));
  }
  if (cond & Glib::IO_OUT) {
    result = rr_dev_handle_writable (m_device);
    if (result < 0)
      error ("Error writing to device!", strerror (errno));
  }
  if (cond & (Glib::IO_ERR | Glib::IO_HUP))
    serial_try_connect (false);

  return true;
}
bool Printer::handle_dev_fd (Glib::IOCondition cond)
{
  if (device==NULL) return false;
  int result;
  if (cond & Glib::IO_IN) {
    result = rr_dev_handle_readable (device);
    if (result < 0)
      error (_("Error reading from device!"), std::strerror (errno));
  }
  // try to avoid reading and writing at exactly the same time
  else if (cond & Glib::IO_OUT) {
    result = rr_dev_handle_writable (device);
    if (result < 0)
      error (_("Error writing to device!"), std::strerror (errno));
  }
  if (cond & (Glib::IO_ERR | Glib::IO_HUP))
    serial_try_connect (false);

  return true;
}