ExternalStream.st
changeset 20380 fc52f8c44127
parent 20270 d2c92e7e2294
child 20398 8cb53f870d39
child 20411 5094bd64e3f0
equal deleted inserted replaced
20379:135c4fc19014 20380:fc52f8c44127
  5561 %{
  5561 %{
  5562     OBJ fp, pos, lim;
  5562     OBJ fp, pos, lim;
  5563     char c;
  5563     char c;
  5564 
  5564 
  5565     if (__INST(hitEOF) == true) {
  5565     if (__INST(hitEOF) == true) {
  5566 	RETURN (true);
  5566         RETURN (true);
  5567     }
  5567     }
  5568     pos = __INST(position);
  5568     pos = __INST(position);
  5569     lim = __INST(readLimit);
  5569     lim = __INST(readLimit);
  5570     if (lim != nil) {
  5570     if (lim != nil) {
  5571 	off_t _pos, _readLimit;
  5571         off_t _pos, _readLimit;
  5572 
  5572 
  5573 	_pos = __signedLongIntVal(pos);
  5573         _pos = __signedLongIntVal(pos);
  5574 	_pos = _pos - __intVal( @global(PositionableStream:ZeroPosition)) + 1;
  5574         _pos = _pos - __intVal( @global(PositionableStream:ZeroPosition)) + 1;
  5575 	_readLimit = __signedLongIntVal(lim);
  5575         _readLimit = __signedLongIntVal(lim);
  5576 	if (_pos > _readLimit) {
  5576         if (_pos > _readLimit) {
  5577 	    RETURN (true);
  5577             RETURN (true);
  5578 	}
  5578         }
  5579     }
  5579     }
  5580 
  5580 
  5581     __INST(lastErrorNumber) = nil;
  5581     __INST(lastErrorNumber) = nil;
  5582 
  5582 
  5583     if ((__INST(handleType) == nil)
  5583     if ((__INST(handleType) == nil)
  5584      || (__INST(handleType) == @symbol(filePointer))
  5584      || (__INST(handleType) == @symbol(filePointer))
  5585      || (__INST(handleType) == @symbol(socketFilePointer))
  5585      || (__INST(handleType) == @symbol(socketFilePointer))
  5586      || (__INST(handleType) == @symbol(socketHandle))
  5586      || (__INST(handleType) == @symbol(socketHandle))
  5587      || (__INST(handleType) == @symbol(pipeFilePointer))) {
  5587      || (__INST(handleType) == @symbol(pipeFilePointer))) {
  5588 	if ((fp = __INST(handle)) != nil) {
  5588         if ((fp = __INST(handle)) != nil) {
  5589 	    int _buffered = (__INST(buffered) == true);
  5589             int _buffered = (__INST(buffered) == true);
  5590 	    int ret;
  5590             int ret;
  5591 	    FILEPOINTER f = __FILEVal(fp);
  5591             FILEPOINTER f = __FILEVal(fp);
  5592 
  5592 
  5593 	    if (_buffered) {
  5593             if (_buffered) {
  5594 		__READING__(f);
  5594                 __READING__(f);
  5595 	    } else {
  5595             } else {
  5596 		if (__INST(readAhead) != nil) {
  5596                 if (__INST(readAhead) != nil) {
  5597 		    RETURN (false);
  5597                     RETURN (false);
  5598 		}
  5598                 }
  5599 	    }
  5599             }
  5600 
  5600 
  5601 	    /*
  5601             /*
  5602 	     * read ahead ...
  5602              * read ahead ...
  5603 	     */
  5603              */
  5604 	    do {
  5604             do {
  5605 #ifdef __win32__
  5605 #ifdef __win32__
  5606 # if 1
  5606 # if 1
  5607 		__READBYTE__(ret, f, &c, _buffered, __INST(handleType));
  5607                 __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
  5608 
  5608 
  5609 # else
  5609 # else
  5610 		__BEGIN_INTERRUPTABLE__
  5610                 __BEGIN_INTERRUPTABLE__
  5611 		__READBYTE__(ret, f, &c, _buffered, __INST(handleType));
  5611                 __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
  5612 		__END_INTERRUPTABLE__
  5612                 __END_INTERRUPTABLE__
  5613 # endif
  5613 # endif
  5614 #else /* not __win32__ */
  5614 #else /* not __win32__ */
  5615 		__BEGIN_INTERRUPTABLE__
  5615                 __BEGIN_INTERRUPTABLE__
  5616 		__READBYTE__(ret, f, &c, _buffered, __INST(handleType));
  5616                 __READBYTE__(ret, f, &c, _buffered, __INST(handleType));
  5617 		__END_INTERRUPTABLE__
  5617                 __END_INTERRUPTABLE__
  5618 #endif
  5618 #endif
  5619 	    } while ((ret < 0) && (__threadErrno == EINTR));
  5619             } while ((ret < 0) && (__threadErrno == EINTR));
  5620 
  5620 
  5621 	    if (ret > 0) {
  5621             if (ret > 0) {
  5622 		__UNGETC__(c&0xff, f, _buffered);
  5622                 __UNGETC__(c&0xff, f, _buffered);
  5623 		RETURN (false);
  5623                 RETURN (false);
  5624 	    }
  5624             }
  5625 	    if (ret == 0) {
  5625             if (ret == 0) {
  5626 		__INST(hitEOF) = true;
  5626                 __INST(hitEOF) = true;
  5627 		RETURN (true);
  5627                 RETURN (true);
  5628 	    }
  5628             }
  5629 #ifdef ECONNRESET
  5629 #ifdef ECONNRESET
  5630 	    // connection reset by peer is also an EOF
  5630             // connection reset by peer is also an EOF
  5631 	    if (__threadErrno == ECONNRESET) {
  5631             if (__threadErrno == ECONNRESET) {
  5632 		__INST(hitEOF) = true;
  5632                 __INST(hitEOF) = true;
  5633 		RETURN (true);
  5633                 RETURN (true);
  5634 	    }
  5634             }
  5635 #endif
  5635 #endif
  5636 	    /* ret < 0 */
  5636             /* ret < 0 */
  5637 	    __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
  5637             __INST(lastErrorNumber) = __mkSmallInteger(__threadErrno);
  5638 	}
  5638         }
  5639     }
  5639     }
  5640 %}.
  5640 %}.
  5641     lastErrorNumber notNil ifTrue:[^ self readError].
  5641     lastErrorNumber notNil ifTrue:[^ self readError].
  5642     handle isNil ifTrue:[^ self errorNotOpen].
  5642     handle isNil ifTrue:[^ self errorNotOpen].
  5643     mode == #writeonly ifTrue:[^ self errorWriteOnly].
  5643     mode == #writeonly ifTrue:[^ self errorWriteOnly].
  5644     readAhead notNil ifTrue:[^ false].
  5644     readAhead notNil ifTrue:[^ false].
  5645 
  5645 
  5646     "/ migration support
  5646     "/ migration support
  5647     ^ self
  5647     ^ self
  5648 	atEndFile:handle
  5648         atEndFile:handle
  5649 
  5649 
  5650     "Modified: / 30.10.1998 / 20:16:06 / cg"
  5650     "Modified: / 30.10.1998 / 20:16:06 / cg"
  5651 !
  5651 !
  5652 
  5652 
  5653 canReadWithoutBlocking
  5653 canReadWithoutBlocking