Differences From Artifact [826cbee6d8]:
- File
src/OFStream.m
— part of check-in
[efe7be259d]
at
2013-02-18 21:53:56
on branch trunk
— Rename -[OFStream pendingBytes].
It is now called -[numberOfBytesInReadBuffer].
Additionally, this commit renames OFStream's _cache to _readBuffer. (user: js, size: 30470) [annotate] [blame] [check-ins using]
To Artifact [401460f5bb]:
- File
src/OFStream.m
— part of check-in
[c5ef582958]
at
2013-03-04 17:20:15
on branch trunk
— Replace BOOL with bool.
The only places where BOOL is left are those where they are required by
the ABI. (user: js, size: 30508) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
64 65 66 67 68 69 70 | [self release]; @throw e; } } self = [super init]; | | | | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | [self release]; @throw e; } } self = [super init]; _blocking = true; return self; } - (bool)lowlevelIsAtEndOfStream { [self doesNotRecognizeSelector: _cmd]; abort(); } - (size_t)lowlevelReadIntoBuffer: (void*)buffer length: (size_t)length |
︙ | ︙ | |||
94 95 96 97 98 99 100 | } - copy { return [self retain]; } | | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | } - copy { return [self retain]; } - (bool)isAtEndOfStream { if (_readBufferLength > 0) return false; return [self lowlevelIsAtEndOfStream]; } - (size_t)readIntoBuffer: (void*)buffer length: (size_t)length { |
︙ | ︙ | |||
591 592 593 594 595 596 597 | memcpy(readBuffer, _readBuffer + i + 1, _readBufferLength - i - 1); [self freeMemory: _readBuffer]; _readBuffer = readBuffer; _readBufferLength -= i + 1; | | | | | 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | memcpy(readBuffer, _readBuffer + i + 1, _readBufferLength - i - 1); [self freeMemory: _readBuffer]; _readBuffer = readBuffer; _readBufferLength -= i + 1; _waitingForDelimiter = false; return ret; } } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; buffer = [self allocMemoryWithSize: pageSize]; @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } retLength = _readBufferLength; if (retLength > 0 && _readBuffer[retLength - 1] == '\r') retLength--; ret = [OFString stringWithCString: _readBuffer encoding: encoding length: retLength]; [self freeMemory: _readBuffer]; _readBuffer = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a newline or \0 */ |
︙ | ︙ | |||
686 687 688 689 690 691 692 | memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); [self freeMemory: _readBuffer]; _readBuffer = readBuffer; _readBufferLength = bufferLength - i - 1; | | | 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); [self freeMemory: _readBuffer]; _readBuffer = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; } } /* There was no newline or \0 */ _readBuffer = [self resizeMemory: _readBuffer size: _readBufferLength + |
︙ | ︙ | |||
709 710 711 712 713 714 715 | buffer, bufferLength); _readBufferLength += bufferLength; } @finally { [self freeMemory: buffer]; } | | | 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 | buffer, bufferLength); _readBufferLength += bufferLength; } @finally { [self freeMemory: buffer]; } _waitingForDelimiter = true; return nil; } - (OFString*)readLine { return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } |
︙ | ︙ | |||
810 811 812 813 814 815 816 | memcpy(readBuffer, _readBuffer + i + 1, _readBufferLength - i - 1); [self freeMemory: _readBuffer]; _readBuffer = readBuffer; _readBufferLength -= i + 1; | | | | | 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | memcpy(readBuffer, _readBuffer + i + 1, _readBufferLength - i - 1); [self freeMemory: _readBuffer]; _readBuffer = readBuffer; _readBufferLength -= i + 1; _waitingForDelimiter = false; return ret; } } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; buffer = [self allocMemoryWithSize: pageSize]; @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } ret = [OFString stringWithCString: _readBuffer encoding: encoding length: _readBufferLength]; [self freeMemory: _readBuffer]; _readBuffer = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a delimiter or \0 */ |
︙ | ︙ | |||
889 890 891 892 893 894 895 | memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); [self freeMemory: _readBuffer]; _readBuffer = readBuffer; _readBufferLength = bufferLength - i - 1; | | | 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 | memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); [self freeMemory: _readBuffer]; _readBuffer = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; } } /* Neither the delimiter nor \0 was found */ _readBuffer = [self resizeMemory: _readBuffer size: _readBufferLength + |
︙ | ︙ | |||
912 913 914 915 916 917 918 | buffer, bufferLength); _readBufferLength += bufferLength; } @finally { [self freeMemory: buffer]; } | | | 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 | buffer, bufferLength); _readBufferLength += bufferLength; } @finally { [self freeMemory: buffer]; } _waitingForDelimiter = true; return nil; } - (OFString*)readTillDelimiter: (OFString*)delimiter { return [self readTillDelimiter: delimiter |
︙ | ︙ | |||
943 944 945 946 947 948 949 | - (OFString*)tryReadTillDelimiter: (OFString*)delimiter { return [self tryReadTillDelimiter: delimiter encoding: OF_STRING_ENCODING_UTF_8]; } | | | | 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | - (OFString*)tryReadTillDelimiter: (OFString*)delimiter { return [self tryReadTillDelimiter: delimiter encoding: OF_STRING_ENCODING_UTF_8]; } - (bool)isWriteBufferEnabled { return _writeBufferEnabled; } - (void)setWriteBufferEnabled: (bool)enable { _writeBufferEnabled = enable; } - (void)flushWriteBuffer { if (_writeBuffer == NULL) |
︙ | ︙ | |||
1465 1466 1467 1468 1469 1470 1471 | } - (size_t)numberOfBytesInReadBuffer { return _readBufferLength; } | | | | | | 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 | } - (size_t)numberOfBytesInReadBuffer { return _readBufferLength; } - (bool)isBlocking { return _blocking; } - (void)setBlocking: (bool)enable { #ifndef _WIN32 bool readImplemented = false, writeImplemented = false; @try { int readFlags; readFlags = fcntl([self fileDescriptorForReading], F_GETFL); readImplemented = true; if (readFlags == -1) @throw [OFSetOptionFailedException exceptionWithClass: [self class] stream: self]; if (enable) |
︙ | ︙ | |||
1505 1506 1507 1508 1509 1510 1511 | } @try { int writeFlags; writeFlags = fcntl([self fileDescriptorForWriting], F_GETFL); | | | 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 | } @try { int writeFlags; writeFlags = fcntl([self fileDescriptorForWriting], F_GETFL); writeImplemented = true; if (writeFlags == -1) @throw [OFSetOptionFailedException exceptionWithClass: [self class] stream: self]; if (enable) |
︙ | ︙ | |||
1560 1561 1562 1563 1564 1565 1566 | - (void)close { [self doesNotRecognizeSelector: _cmd]; abort(); } | | | 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 | - (void)close { [self doesNotRecognizeSelector: _cmd]; abort(); } - (bool)OF_isWaitingForDelimiter { return _waitingForDelimiter; } @end |