patch-libpisock_unixserial_c 790 B

1234567891011121314151617181920212223242526272829
  1. $OpenBSD: patch-libpisock_unixserial_c,v 1.5 2015/09/21 08:46:50 ajacoutot Exp $
  2. --- libpisock/unixserial.c.orig Thu Oct 12 16:21:23 2006
  3. +++ libpisock/unixserial.c Thu Jan 17 09:00:40 2008
  4. @@ -161,13 +161,23 @@ s_open(pi_socket_t *ps, struct pi_sockaddr *addr, size
  5. struct pi_serial_data *data =
  6. (struct pi_serial_data *)ps->device->data;
  7. +#define maxretries 100
  8. + int retries;
  9. #ifndef SGTTY
  10. struct termios tcn;
  11. #else
  12. struct sgttyb tcn;
  13. #endif
  14. - if ((fd = open(tty, O_RDWR | O_NONBLOCK)) < 0) {
  15. +
  16. + for (retries = 0 ; retries <= maxretries ; retries++ ) {
  17. + if ((fd = open(tty, O_RDWR | O_NONBLOCK)) != -1) {
  18. + break;
  19. + }
  20. + usleep(50000);
  21. + }
  22. +
  23. + if (fd == -1) {
  24. ps->last_error = PI_ERR_GENERIC_SYSTEM;
  25. return PI_ERR_GENERIC_SYSTEM; /* errno already set */
  26. }