IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK;
pch = NULL;
- while ((nSuccessLess < timeout) && (pch == NULL)) {
+ while ((nSuccessLess < timeout) &&
+ (pch == NULL) &&
+ (*fd != -1)) {
if (IsNonBlock)
{
tv.tv_sec = 1;
fdflags = fcntl(*fd, F_GETFL);
IsNonBlock = (fdflags & O_NONBLOCK) == O_NONBLOCK;
nSuccessLess = 0;
- while (nRead < nBytes) {
+ while ((nRead < nBytes) &&
+ (*fd != -1))
+ {
if (IsNonBlock)
{
tv.tv_sec = 1;
SelRes = 1;
nBytes -= nRead;
nRead = 0;
- while (nRead < nBytes) {
+ while ((nRead < nBytes) &&
+ (*fd != -1)) {
if (IsNonBlock)
{
tv.tv_sec = 1;