- if (iTimeoutMs == 0)
- {
- tv = NULL;
- }
- else
- {
- timeout.tv_sec = ((long int)target - (long int)now) / (long int)1000.;
- timeout.tv_usec = ((long int)target - (long int)now) % (long int)1000.;
- tv = &timeout;
- }
-
- FD_ZERO(&port);
- FD_SET(m_fd, &port);
- int32_t returnv = select(m_fd + 1, &port, NULL, NULL, tv);
-
- if (returnv == -1)
- {
- m_error = strerror(errno);
- return -1;
- }
- else if (returnv == 0)
- {
- break; //nothing to read
- }
-
- returnv = read(m_fd, data + bytesread, len - bytesread);
- if (returnv == -1)
- {
- m_error = strerror(errno);
- return -1;
- }
-
- bytesread += returnv;
-
- if (iTimeoutMs > 0)
- now = GetTimeMs();