ObjFW  Diff

Differences From Artifact [826cbee6d8]:

To Artifact [401460f5bb]:


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 = YES;

	return self;
}

- (BOOL)lowlevelIsAtEndOfStream
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

- (size_t)lowlevelReadIntoBuffer: (void*)buffer
			  length: (size_t)length







|




|







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
101
102
103
104
105
106
107
108
109
110
111
}

- copy
{
	return [self retain];
}

- (BOOL)isAtEndOfStream
{
	if (_readBufferLength > 0)
		return NO;

	return [self lowlevelIsAtEndOfStream];
}

- (size_t)readIntoBuffer: (void*)buffer
		  length: (size_t)length
{







|


|







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
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 = NO;
				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 = NO;
				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 = NO;
			return ret;
		}

		bufferLength = [self lowlevelReadIntoBuffer: buffer
						     length: pageSize];

		/* Look if there's a newline or \0 */







|












|
















|







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
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 = NO;
				return ret;
			}
		}

		/* There was no newline or \0 */
		_readBuffer = [self resizeMemory: _readBuffer
					    size: _readBufferLength +







|







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
716
717
718
719
720
721
722
723
			    buffer, bufferLength);

		_readBufferLength += bufferLength;
	} @finally {
		[self freeMemory: buffer];
	}

	_waitingForDelimiter = YES;
	return nil;
}

- (OFString*)readLine
{
	return [self readLineWithEncoding: OF_STRING_ENCODING_UTF_8];
}







|







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
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 = NO;
				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 = NO;
				return nil;
			}

			ret = [OFString stringWithCString: _readBuffer
						 encoding: encoding
						   length: _readBufferLength];

			[self freeMemory: _readBuffer];
			_readBuffer = NULL;
			_readBufferLength = 0;

			_waitingForDelimiter = NO;
			return ret;
		}

		bufferLength = [self lowlevelReadIntoBuffer: buffer
						     length: pageSize];

		/* Look if there's a delimiter or \0 */







|












|











|







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
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 = NO;
				return ret;
			}
		}

		/* Neither the delimiter nor \0 was found */
		_readBuffer = [self resizeMemory: _readBuffer
					    size: _readBufferLength +







|







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
919
920
921
922
923
924
925
926
			    buffer, bufferLength);

		_readBufferLength += bufferLength;
	} @finally {
		[self freeMemory: buffer];
	}

	_waitingForDelimiter = YES;
	return nil;
}


- (OFString*)readTillDelimiter: (OFString*)delimiter
{
	return [self readTillDelimiter: delimiter







|







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
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)







|




|







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
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 = NO, writeImplemented = NO;

	@try {
		int readFlags;

		readFlags = fcntl([self fileDescriptorForReading], F_GETFL);

		readImplemented = YES;

		if (readFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];

		if (enable)







|




|


|






|







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
1512
1513
1514
1515
1516
1517
1518
1519
	}

	@try {
		int writeFlags;

		writeFlags = fcntl([self fileDescriptorForWriting], F_GETFL);

		writeImplemented = YES;

		if (writeFlags == -1)
			@throw [OFSetOptionFailedException
			    exceptionWithClass: [self class]
					stream: self];

		if (enable)







|







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
1567
1568
1569
1570
1571

- (void)close
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

- (BOOL)OF_isWaitingForDelimiter
{
	return _waitingForDelimiter;
}
@end







|




1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571

- (void)close
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

- (bool)OF_isWaitingForDelimiter
{
	return _waitingForDelimiter;
}
@end