ObjFW  Diff

Differences From Artifact [95bd8d7b45]:

To Artifact [63931bf44e]:


765
766
767
768
769
770
771
772

773
774
775
776

777
778
779
780
781
782
783
784
785
786
787
788
789
790

791
792
793
794



795
796
797
798
799

800
801

802
803
804
805
806
807
808
809

810
811
812
813
814
815
816
817
818
819
820
821
822

823
824
825
826
827
828
829
765
766
767
768
769
770
771

772

773


774
775
776
777
778
779
780
781
782
783
784
785
786
787

788




789
790
791
792
793
794
795

796
797

798
799
800
801



802

803
804
805
806
807
808








809
810
811
812
813
814
815
816







-
+
-

-
-
+













-
+
-
-
-
-
+
+
+




-
+

-
+



-
-
-

-
+





-
-
-
-
-
-
-
-
+







		[self close];

	[_handler release];

	[super dealloc];
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
- (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length
		       length: (size_t)length
{
	size_t requestedLength = length;
	size_t ret;
	/* TODO: Use non-blocking writes */

	if (_socket == nil)
		@throw [OFNotOpenException exceptionWithObject: self];

	/*
	 * We must not send a chunk of size 0, as that would end the body. We
	 * always ignore writing 0 bytes to still allow writing 0 bytes after
	 * the end of stream.
	 */
	if (length == 0)
		return 0;

	if (_atEndOfStream)
		@throw [OFWriteFailedException
		@throw [OFWriteFailedException exceptionWithObject: self
		    exceptionWithObject: self
			requestedLength: requestedLength
			   bytesWritten: 0
				  errNo: 0];
						   requestedLength: length
						      bytesWritten: 0
							     errNo: ENOTCONN];

	if (_chunked)
		[_socket writeFormat: @"%zX\r\n", length];
	else if (length > _toWrite)
		length = (size_t)_toWrite;
		@throw [OFOutOfRangeException exception];

	ret = [_socket writeBuffer: buffer length: length];
	[_socket writeBuffer: buffer length: length];
	if (_chunked)
		[_socket writeString: @"\r\n"];

	if (ret > length)
		@throw [OFOutOfRangeException exception];

	if (!_chunked) {
		_toWrite -= ret;
		_toWrite -= length;

		if (_toWrite == 0)
			_atEndOfStream = true;
	}

	if (requestedLength > length)
		@throw [OFWriteFailedException
		    exceptionWithObject: self
			requestedLength: requestedLength
			   bytesWritten: ret
				  errNo: 0];

	return ret;
	return length;
}

- (bool)lowlevelIsAtEndOfStream
{
	return _atEndOfStream;
}