ObjFW  Diff

Differences From Artifact [3923d7b75a]:

To Artifact [815f2dd728]:


46
47
48
49
50
51
52

53
54
55
56
57
58
59
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFSetOptionFailedException.h"
#import "OFTruncatedDataException.h"


#import "of_asprintf.h"

#define MIN_READ_SIZE 512

@implementation OFStream
@synthesize of_waitingForDelimiter = _waitingForDelimiter;







>







46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfMemoryException.h"
#import "OFOutOfRangeException.h"
#import "OFSetOptionFailedException.h"
#import "OFTruncatedDataException.h"
#import "OFWriteFailedException.h"

#import "of_asprintf.h"

#define MIN_READ_SIZE 512

@implementation OFStream
@synthesize of_waitingForDelimiter = _waitingForDelimiter;
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
			  length: (size_t)length
{
	OF_UNRECOGNIZED_SELECTOR
}

- (void)lowlevelWriteBuffer: (const void *)buffer
		     length: (size_t)length
{
	OF_UNRECOGNIZED_SELECTOR
}

- copy
{
	return [self retain];







|
|







93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

- (size_t)lowlevelReadIntoBuffer: (void *)buffer
			  length: (size_t)length
{
	OF_UNRECOGNIZED_SELECTOR
}

- (size_t)lowlevelWriteBuffer: (const void *)buffer
		       length: (size_t)length
{
	OF_UNRECOGNIZED_SELECTOR
}

- copy
{
	return [self retain];
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054









1055
1056
1057
1058
1059
1060

1061





























1062
1063
1064
1065
1066
1067
1068
			   length: _writeBufferLength];

	[self freeMemory: _writeBuffer];
	_writeBuffer = NULL;
	_writeBufferLength = 0;
}

- (void)writeBuffer: (const void *)buffer
	     length: (size_t)length
{
	if (!_writeBuffered)
		[self lowlevelWriteBuffer: buffer
				   length: length];









	else {
		_writeBuffer = [self resizeMemory: _writeBuffer
					     size: _writeBufferLength + length];
		memcpy(_writeBuffer + _writeBufferLength, buffer, length);
		_writeBufferLength += length;
	}

}






























- (void)writeInt8: (uint8_t)int8
{
	[self writeBuffer: (char *)&int8
		   length: 1];
}








|
|

|
|
|
>
>
>
>
>
>
>
>
>
|




|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
			   length: _writeBufferLength];

	[self freeMemory: _writeBuffer];
	_writeBuffer = NULL;
	_writeBufferLength = 0;
}

- (size_t)writeBuffer: (const void *)buffer
	       length: (size_t)length
{
	if (!_writeBuffered) {
		size_t bytesWritten = [self lowlevelWriteBuffer: buffer
							 length: length];

		if (_blocking && bytesWritten < length)
			@throw [OFWriteFailedException
			    exceptionWithObject: self
				requestedLength: length
				   bytesWritten: bytesWritten
					  errNo: 0];

		return bytesWritten;
	} else {
		_writeBuffer = [self resizeMemory: _writeBuffer
					     size: _writeBufferLength + length];
		memcpy(_writeBuffer + _writeBufferLength, buffer, length);
		_writeBufferLength += length;

		return length;
	}
}

#ifdef OF_HAVE_SOCKETS
- (void)asyncWriteBuffer: (const void *)buffer
		  length: (size_t)length
		  target: (id)target
		selector: (SEL)selector
		 context: (id)context
{
	[OFRunLoop of_addAsyncWriteForStream: self
				      buffer: buffer
				      length: length
				      target: target
				    selector: selector
				     context: context];
}

# ifdef OF_HAVE_BLOCKS
- (void)asyncWriteBuffer: (const void *)buffer
		  length: (size_t)length
		   block: (of_stream_async_write_block_t)block
{
	[OFRunLoop of_addAsyncWriteForStream: self
				      buffer: buffer
				      length: length
				       block: block];
}
# endif
#endif

- (void)writeInt8: (uint8_t)int8
{
	[self writeBuffer: (char *)&int8
		   length: 1];
}