コード例 #1
0
ファイル: comms.c プロジェクト: atoun/repsnapper
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;
}
コード例 #2
0
ファイル: comms.c プロジェクト: mmeeks/libreprap
int rr_flush(rr_dev device) {
  /* Disable non-blocking mode */
  int flags;
  if((flags = fcntl(device->fd, F_GETFL, 0)) < 0) {
    return flags;
  }
  if(fcntl(device->fd, F_SETFL, flags & ~O_NONBLOCK) == -1) {
    return -1;
  }

  int result = 0;
  while(rr_dev_buffered(device) && result >= 0) {
    result = rr_handle_writable(device);
  }

  if(result >= 0) {
    result = fcntl(device->fd, F_SETFL, flags);
  } else {
    fcntl(device->fd, F_SETFL, flags);
  }

  /* Restore original mode */
  return result;
}