ObjFW  Diff

Differences From Artifact [fb448f8379]:

To Artifact [d3c9a265b1]:


22
23
24
25
26
27
28

29





30
31
32
33
34
35
36
#endif

#include <stdarg.h>

#import "OFObject.h"
#import "OFString.h"


@class OFDataArray;






/**
 * \brief A base class for different types of streams.
 *
 * \warning Even though the OFCopying protocol is implemented, it does
 *	    <i>not</i> return an independent copy of the stream but instead
 *	    retains it.  This is so that the stream can be used as a key for a







>

>
>
>
>
>







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#endif

#include <stdarg.h>

#import "OFObject.h"
#import "OFString.h"

@class OFStream;
@class OFDataArray;

#ifdef OF_HAVE_BLOCKS
typedef BOOL (^of_stream_async_read_block_t)(OFStream*, void*, size_t);
typedef BOOL (^of_stream_async_read_line_block_t)(OFStream*, OFString*);
#endif

/**
 * \brief A base class for different types of streams.
 *
 * \warning Even though the OFCopying protocol is implemented, it does
 *	    <i>not</i> return an independent copy of the stream but instead
 *	    retains it.  This is so that the stream can be used as a key for a
77
78
79
80
81
82
83
























84
85
86
87
88
89
90
 * \param buffer The buffer into which the data is read
 * \param length The length of the data that should be read at most.
 *		 The buffer <i>must</i> be at least this big!
 * \return The number of bytes read
 */
- (size_t)readIntoBuffer: (void*)buffer
		  length: (size_t)size;

























/**
 * \brief Reads exactly the specified length bytes from the stream into a
 *	  buffer.
 *
 * Unlike readIntoBuffer:length:, this method does not return when less than the
 * specified length has been read - instead, it waits until it got exactly the







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







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 * \param buffer The buffer into which the data is read
 * \param length The length of the data that should be read at most.
 *		 The buffer <i>must</i> be at least this big!
 * \return The number of bytes read
 */
- (size_t)readIntoBuffer: (void*)buffer
		  length: (size_t)size;

#ifdef OF_HAVE_BLOCKS
/**
 * \brief Asyncronously reads <i>at most</i> size bytes from the stream into a
 *	  buffer.
 *
 * On network streams, this might read less than the specified number of bytes.
 * If you want to read exactly the specified number of bytes, use
 * -[readIntoBuffer:exactLength:].
 *
 * \param buffer The buffer into which the data is read.
 *		 The buffer must not be free'd before the async read completed!
 * \param length The length of the data that should be read at most.
 *		 The buffer <i>must</i> be at least this big!
 * \param block The block to call when the data has been received.
 *		If the block returns YES, it will be called again with the same
 *		buffer and maximum length when more data has been received. If
 *		you want the next block in the queue to handle the data
 *		received next, you need to return NO from the block.
 */
- (void)asyncReadWithBuffer: (void*)buffer
		     length: (size_t)length
		      block: (of_stream_async_read_block_t)block;
#endif

/**
 * \brief Reads exactly the specified length bytes from the stream into a
 *	  buffer.
 *
 * Unlike readIntoBuffer:length:, this method does not return when less than the
 * specified length has been read - instead, it waits until it got exactly the
441
442
443
444
445
446
447

























448
449
450
451
452
453
454
 *	  stream occurs.
 *
 * \param encoding The encoding used by the stream
 * \return The line that was read, autoreleased, or nil if the end of the
 *	   stream has been reached.
 */
- (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding;


























/**
 * \brief Tries to read a line from the stream (see readLine) and returns nil if
 *	  no complete line has been received yet.
 *
 * \return The line that was read, autoreleased, or nil if the line is not
 *	   complete yet







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







471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
 *	  stream occurs.
 *
 * \param encoding The encoding used by the stream
 * \return The line that was read, autoreleased, or nil if the end of the
 *	   stream has been reached.
 */
- (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding;

#ifdef OF_HAVE_BLOCKS
/**
 * \brief Asyncronously reads until a newline, \\0 or end of stream occurs.
 *
 * \param block The block to call when the data has been received.
 *		If the block returns YES, it will be called again when the next
 *		line has been received. If you want the next block in the queue
 *		to handle the next line, you need to return NO from the block.
 */
- (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block;

/**
 * \brief Asyncronously reads with the specified encoding until a newline, \\0
 *	  or end of stream occurs.
 *
 * \param encoding The encoding used by the stream
 * \param block The block to call when the data has been received.
 *		If the block returns YES, it will be called again when the next
 *		line has been received. If you want the next block in the queue
 *		to handle the next line, you need to return NO from the block.
 */
- (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
			    block: (of_stream_async_read_line_block_t)block;
#endif

/**
 * \brief Tries to read a line from the stream (see readLine) and returns nil if
 *	  no complete line has been received yet.
 *
 * \return The line that was read, autoreleased, or nil if the line is not
 *	   complete yet