ObjFW  Check-in [138a7a1934]

Overview
Comment:OFStream: Add -[unreadFromBuffer:length:].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 138a7a1934efdd1838dbba1c95dd2dce3e53714451b6829754e76f98643bf06c
User & Date: js on 2013-10-10 02:26:40
Other Links: manifest | tags
Context
2013-10-10
13:18
Add OFDeflateStream. check-in: d83d3aa719 user: js tags: trunk
02:26
OFStream: Add -[unreadFromBuffer:length:]. check-in: 138a7a1934 user: js tags: trunk
2013-09-30
16:11
OFHTTPClient: Status in delegate for redirection. check-in: 6bd37697f2 user: js tags: trunk
Changes

Modified src/OFStream.h from [95be3e6746] to [bfaab86a9d].

1048
1049
1050
1051
1052
1053
1054
























1055
1056
1057
1058
1059
1060
1061
#ifdef OF_HAVE_SOCKETS
/*!
 * @brief Cancels all pending asyncronous requests on the stream.
 */
- (void)cancelAsyncRequests;
#endif

























/*!
 * @brief Closes the stream.
 */
- (void)close;

/*!
 * @brief Performs a lowlevel read.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
#ifdef OF_HAVE_SOCKETS
/*!
 * @brief Cancels all pending asyncronous requests on the stream.
 */
- (void)cancelAsyncRequests;
#endif

/*!
 * @brief "Reverses" a read operation, meaning the bytes from the specified
 *	  buffer will be returned on the next read operation.
 *
 * This is useful for reading into a buffer, parsing the data and then giving
 * back the data which does not need to be processed. This can be used to
 * optimize situations in which the length of the data that needs to be
 * processed is not known before all data has been processed - for example in
 * decompression - in which it would otherwise be necessary to read byte by
 * byte to avoid consuming bytes that need to be parsed by something else -
 * for example the data descriptor in a ZIP archive which immediately follows
 * the compressed data.
 *
 * If the stream is a file, this method does not change any data in the file.
 *
 * If the stream is seekable, a seek operation will discard any data that was
 * unread.
 *
 * @param buffer The buffer to unread
 * @param length The length of the buffer to unread
 */
- (void)unreadFromBuffer: (const void*)buffer
		  length: (size_t)length;

/*!
 * @brief Closes the stream.
 */
- (void)close;

/*!
 * @brief Performs a lowlevel read.

Modified src/OFStream.m from [5586c87ef1] to [11398332ce].

38
39
40
41
42
43
44

45
46
47
48
49
50
51
#import "OFSystemInfo.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"

#import "OFSetOptionFailedException.h"

#import "macros.h"
#import "of_asprintf.h"

@implementation OFStream
#ifndef _WIN32







>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#import "OFSystemInfo.h"
#import "OFRunLoop.h"
#import "OFRunLoop+Private.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"
#import "OFOutOfRangeException.h"
#import "OFSetOptionFailedException.h"

#import "macros.h"
#import "of_asprintf.h"

@implementation OFStream
#ifndef _WIN32
1551
1552
1553
1554
1555
1556
1557















1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569

#ifdef OF_HAVE_SOCKETS
- (void)cancelAsyncRequests
{
	[OFRunLoop OF_cancelAsyncRequestsForStream: self];
}
#endif
















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

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







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585

#ifdef OF_HAVE_SOCKETS
- (void)cancelAsyncRequests
{
	[OFRunLoop OF_cancelAsyncRequestsForStream: self];
}
#endif

- (void)unreadFromBuffer: (const void*)buffer
		  length: (size_t)length
{
	if (length > SIZE_MAX - _readBufferLength)
		@throw [OFOutOfRangeException exception];

	_readBuffer = [self resizeMemory: _readBuffer
				    size: _readBufferLength + length];

	memmove(_readBuffer + length, _readBuffer, _readBufferLength);
	memcpy(_readBuffer, buffer, length);

	_readBufferLength += length;
}

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

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