| 1549 | ----------------------------------------------------------*/ |
| 1550 | |
| 1551 | int win32_serial_read(int fd, void *vb, int size) |
| 1552 | { |
| 1553 | long start, now; |
| 1554 | unsigned long nBytes = 0, total = 0; |
| 1555 | /* unsigned long waiting = 0; */ |
| 1556 | int err; |
| 1557 | struct termios_list *index; |
| 1558 | // char message[80]; |
| 1559 | COMSTAT stat; |
| 1560 | clock_t c; |
| 1561 | unsigned char *dest = vb; |
| 1562 | |
| 1563 | start = GetTickCount(); |
| 1564 | ENTER("serial_read"); |
| 1565 | |
| 1566 | if (fd <= 0) |
| 1567 | { |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
| 1571 | index = win32_serial_find_port(fd); |
| 1572 | |
| 1573 | if (!index) |
| 1574 | { |
| 1575 | LEAVE("serial_read"); |
| 1576 | return -1; |
| 1577 | } |
| 1578 | |
| 1579 | /* FIXME: CREAD: without this, data cannot be read |
| 1580 | FIXME: PARMRK: mark framing & parity errors |
| 1581 | FIXME: IGNCR: ignore \r |
| 1582 | FIXME: ICRNL: convert \r to \n |
| 1583 | FIXME: INLCR: convert \n to \r |
| 1584 | */ |
| 1585 | |
| 1586 | if (index->open_flags & O_NONBLOCK) |
| 1587 | { |
| 1588 | /* pull mucho-cpu here? */ |
| 1589 | do |
| 1590 | { |
| 1591 | #ifdef DEBUG_VERBOSE |
| 1592 | report("vmin=0\n"); |
| 1593 | #endif /* DEBUG_VERBOSE */ |
| 1594 | ClearErrors(index, &stat); |
| 1595 | |
| 1596 | if (stat.cbInQue < index->ttyset->c_cc[VMIN]) |
| 1597 | { |
| 1598 | /* |
| 1599 | hl_usleep(50); |
| 1600 | */ |
| 1601 | hl_usleep(100); /* don't hog the CPU while waiting */ |
| 1602 | |
| 1603 | /* we should use -1 instead of 0 for disabled timeout */ |
| 1604 | now = GetTickCount(); |
| 1605 | |
| 1606 | if (index->ttyset->c_cc[VTIME] && |
| 1607 | now - start >= (index->ttyset->c_cc[VTIME] * 100)) |
| 1608 | { |
no test coverage detected