︙ | | | ︙ | |
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
- (void)readIntoBuffer: (void *)buffer
exactLength: (size_t)length
{
size_t readLength = 0;
while (readLength < length) {
if ([self isAtEndOfStream])
@throw [OFTruncatedDataException exception];
readLength += [self readIntoBuffer: (char *)buffer + readLength
length: length - readLength];
}
}
|
|
|
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
- (void)readIntoBuffer: (void *)buffer
exactLength: (size_t)length
{
size_t readLength = 0;
while (readLength < length) {
if (self.atEndOfStream)
@throw [OFTruncatedDataException exception];
readLength += [self readIntoBuffer: (char *)buffer + readLength
length: length - readLength];
}
}
|
︙ | | | ︙ | |
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
|
- (OFData *)readDataUntilEndOfStream
{
OFMutableData *data = [OFMutableData data];
size_t pageSize = [OFSystemInfo pageSize];
char *buffer = [self allocMemoryWithSize: pageSize];
@try {
while (![self isAtEndOfStream]) {
size_t length;
length = [self readIntoBuffer: buffer
length: pageSize];
[data addItems: buffer
count: length];
}
|
|
|
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
|
- (OFData *)readDataUntilEndOfStream
{
OFMutableData *data = [OFMutableData data];
size_t pageSize = [OFSystemInfo pageSize];
char *buffer = [self allocMemoryWithSize: pageSize];
@try {
while (!self.atEndOfStream) {
size_t length;
length = [self readIntoBuffer: buffer
length: pageSize];
[data addItems: buffer
count: length];
}
|
︙ | | | ︙ | |
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
|
}
- (OFString *)readLineWithEncoding: (of_string_encoding_t)encoding
{
OFString *line = nil;
while ((line = [self tryReadLineWithEncoding: encoding]) == nil)
if ([self isAtEndOfStream])
return nil;
return line;
}
#ifdef OF_HAVE_SOCKETS
- (void)asyncReadLine
|
|
|
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
|
}
- (OFString *)readLineWithEncoding: (of_string_encoding_t)encoding
{
OFString *line = nil;
while ((line = [self tryReadLineWithEncoding: encoding]) == nil)
if (self.atEndOfStream)
return nil;
return line;
}
#ifdef OF_HAVE_SOCKETS
- (void)asyncReadLine
|
︙ | | | ︙ | |
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
|
}
- (OFString *)readTillDelimiter: (OFString *)delimiter
encoding: (of_string_encoding_t)encoding
{
OFString *ret = nil;
while ((ret = [self tryReadTillDelimiter: delimiter
encoding: encoding]) == nil)
if ([self isAtEndOfStream])
return nil;
return ret;
}
- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
{
|
<
|
|
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
|
}
- (OFString *)readTillDelimiter: (OFString *)delimiter
encoding: (of_string_encoding_t)encoding
{
OFString *ret = nil;
while ((ret = [self tryReadTillDelimiter: delimiter
encoding: encoding]) == nil)
if (self.atEndOfStream)
return nil;
return ret;
}
- (OFString *)tryReadTillDelimiter: (OFString *)delimiter
{
|
︙ | | | ︙ | |
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
|
void *pool;
size_t length;
if (data == nil)
@throw [OFInvalidArgumentException exception];
pool = objc_autoreleasePoolPush();
length = [data count] * [data itemSize];
[self writeBuffer: [data items]
length: length];
objc_autoreleasePoolPop(pool);
return length;
}
|
|
|
|
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
|
void *pool;
size_t length;
if (data == nil)
@throw [OFInvalidArgumentException exception];
pool = objc_autoreleasePoolPush();
length = data.count * data.itemSize;
[self writeBuffer: data.items
length: length];
objc_autoreleasePoolPop(pool);
return length;
}
|
︙ | | | ︙ | |
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
|
{
char *UTF8String;
int length;
if (format == nil)
@throw [OFInvalidArgumentException exception];
if ((length = of_vasprintf(&UTF8String, [format UTF8String],
arguments)) == -1)
@throw [OFInvalidFormatException exception];
@try {
[self writeBuffer: UTF8String
length: length];
} @finally {
|
|
|
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
|
{
char *UTF8String;
int length;
if (format == nil)
@throw [OFInvalidArgumentException exception];
if ((length = of_vasprintf(&UTF8String, format.UTF8String,
arguments)) == -1)
@throw [OFInvalidFormatException exception];
@try {
[self writeBuffer: UTF8String
length: length];
} @finally {
|
︙ | | | ︙ | |
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
|
{
#if defined(HAVE_FCNTL)
bool readImplemented = false, writeImplemented = false;
@try {
int readFlags;
readFlags =
fcntl([(id)self fileDescriptorForReading], F_GETFL, 0);
readImplemented = true;
if (readFlags == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
if (enable)
readFlags &= ~O_NONBLOCK;
else
readFlags |= O_NONBLOCK;
if (fcntl([(id)self fileDescriptorForReading], F_SETFL,
readFlags) == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
} @catch (OFNotImplementedException *e) {
}
@try {
int writeFlags;
writeFlags =
fcntl([(id)self fileDescriptorForWriting], F_GETFL, 0);
writeImplemented = true;
if (writeFlags == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
if (enable)
writeFlags &= ~O_NONBLOCK;
else
writeFlags |= O_NONBLOCK;
if (fcntl([(id)self fileDescriptorForWriting], F_SETFL,
writeFlags) == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
} @catch (OFNotImplementedException *e) {
}
if (!readImplemented && !writeImplemented)
|
|
|
|
|
|
|
|
|
|
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
|
{
#if defined(HAVE_FCNTL)
bool readImplemented = false, writeImplemented = false;
@try {
int readFlags;
readFlags = fcntl(((id <OFReadyForReadingObserving>)self)
.fileDescriptorForReading, F_GETFL, 0);
readImplemented = true;
if (readFlags == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
if (enable)
readFlags &= ~O_NONBLOCK;
else
readFlags |= O_NONBLOCK;
if (fcntl(((id <OFReadyForReadingObserving>)self)
.fileDescriptorForReading, F_SETFL, readFlags) == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
} @catch (OFNotImplementedException *e) {
}
@try {
int writeFlags;
writeFlags = fcntl(((id <OFReadyForWritingObserving>)self)
.fileDescriptorForWriting, F_GETFL, 0);
writeImplemented = true;
if (writeFlags == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
if (enable)
writeFlags &= ~O_NONBLOCK;
else
writeFlags |= O_NONBLOCK;
if (fcntl(((id <OFReadyForWritingObserving>)self)
.fileDescriptorForWriting, F_SETFL, writeFlags) == -1)
@throw [OFSetOptionFailedException
exceptionWithObject: self
errNo: errno];
} @catch (OFNotImplementedException *e) {
}
if (!readImplemented && !writeImplemented)
|
︙ | | | ︙ | |