Differences From Artifact [c63329fd4a]:
- File
src/OFStream.m
— part of check-in
[b02c4b05bb]
at
2020-04-25 17:05:13
on branch trunk
— Add OFDatagramSocket as base class for OFUDPSocket
This makes it easier to reuse code for other datagram sockets, namely
IPX. (user: js, size: 40740) [annotate] [blame] [check-ins using]
To Artifact [dd10e2b21b]:
- File src/OFStream.m — part of check-in [bc67e98833] at 2020-05-06 00:32:10 on branch trunk — Improve names of several properties (user: js, size: 40667) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | #import "OFWriteFailedException.h" #import "of_asprintf.h" #define MIN_READ_SIZE 512 @implementation OFStream @synthesize of_waitingForDelimiter = _waitingForDelimiter, delegate = _delegate; #if defined(SIGPIPE) && defined(SIG_IGN) + (void)initialize { if (self == [OFStream class]) signal(SIGPIPE, SIG_IGN); } #endif - (instancetype)init { self = [super init]; @try { if (self.class == [OFStream class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } | > | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | #import "OFWriteFailedException.h" #import "of_asprintf.h" #define MIN_READ_SIZE 512 @implementation OFStream @synthesize buffersWrites = _buffersWrites; @synthesize of_waitingForDelimiter = _waitingForDelimiter, delegate = _delegate; #if defined(SIGPIPE) && defined(SIG_IGN) + (void)initialize { if (self == [OFStream class]) signal(SIGPIPE, SIG_IGN); } #endif - (instancetype)init { self = [super init]; @try { if (self.class == [OFStream class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } _canBlock = true; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
1124 1125 1126 1127 1128 1129 1130 | - (OFString *)tryReadTillDelimiter: (OFString *)delimiter { return [self tryReadTillDelimiter: delimiter encoding: OF_STRING_ENCODING_UTF_8]; } | < < < < < < < < < < | | | 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 | - (OFString *)tryReadTillDelimiter: (OFString *)delimiter { return [self tryReadTillDelimiter: delimiter encoding: OF_STRING_ENCODING_UTF_8]; } - (void)flushWriteBuffer { if (_writeBuffer == NULL) return; [self lowlevelWriteBuffer: _writeBuffer length: _writeBufferLength]; [self freeMemory: _writeBuffer]; _writeBuffer = NULL; _writeBufferLength = 0; } - (size_t)writeBuffer: (const void *)buffer length: (size_t)length { if (!_buffersWrites) { size_t bytesWritten = [self lowlevelWriteBuffer: buffer length: length]; if (_canBlock && bytesWritten < length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; return bytesWritten; |
︙ | ︙ | |||
1796 1797 1798 1799 1800 1801 1802 | } - (bool)hasDataInReadBuffer { return (_readBufferLength > 0); } | | | | | | 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 | } - (bool)hasDataInReadBuffer { return (_readBufferLength > 0); } - (bool)canBlock { return _canBlock; } - (void)setCanBlock: (bool)canBlock { #if defined(HAVE_FCNTL) && !defined(OF_AMIGAOS) 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 (canBlock) readFlags &= ~O_NONBLOCK; else readFlags |= O_NONBLOCK; if (fcntl(((id <OFReadyForReadingObserving>)self) .fileDescriptorForReading, F_SETFL, readFlags) == -1) @throw [OFSetOptionFailedException |
︙ | ︙ | |||
1845 1846 1847 1848 1849 1850 1851 | writeImplemented = true; if (writeFlags == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; | | | | 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 1867 | writeImplemented = true; if (writeFlags == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; if (canBlock) 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) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; _canBlock = canBlock; #else OF_UNRECOGNIZED_SELECTOR #endif } - (int)fileDescriptorForReading { |
︙ | ︙ | |||
1912 1913 1914 1915 1916 1917 1918 | [self freeMemory: _readBufferMemory]; _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; [self freeMemory: _writeBuffer]; _writeBuffer = NULL; _writeBufferLength = 0; | | | 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 | [self freeMemory: _readBufferMemory]; _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; [self freeMemory: _writeBuffer]; _writeBuffer = NULL; _writeBufferLength = 0; _buffersWrites = false; _waitingForDelimiter = false; } @end |