ObjFW  Diff

Differences From Artifact [ba57cd6e80]:

To Artifact [a9818d561e]:


67
68
69
70
71
72
73
74
75

76
77
78
79
80


81
82
83

84
85
86
87
88


89
90
91
92
93
94
95
67
68
69
70
71
72
73


74


75


76
77
78
79

80


81


82
83
84
85
86
87
88
89
90







-
-
+
-
-

-
-
+
+


-
+
-
-

-
-
+
+







typedef bool (^of_stream_async_read_line_block_t)(OF_KINDOF(OFStream *) stream,
    OFString *_Nullable line, id _Nullable exception);

/*!
 * @brief A block which is called when data was written asynchronously to a
 *	  stream.
 *
 * @param stream The stream to which data was written
 * @param buffer A pointer to the buffer which was written to the stream. This
 * @param data The data which was written to the stream
 *		 can be changed to point to a different buffer to be used on the
 *		 next write.
 * @param bytesWritten The number of bytes which have been written. This
 *		       matches the length specified on the asynchronous write
 *		       if no exception was encountered.
 *		       matches the length of the specified data on the
 *		       asynchronous write if no exception was encountered.
 * @param exception An exception which occurred while writing or `nil` on
 *		    success
 * @return The length to repeat the write with or 0 if it should not repeat.
 * @return The data to repeat the write with or nil if it should not repeat
 *	   The buffer may be changed, so that every time a new buffer and length
 *	   can be specified
 */
typedef size_t (^of_stream_async_write_block_t)(OF_KINDOF(OFStream *) stream,
    const void *_Nonnull *_Nonnull buffer, size_t bytesWritten,
typedef OFData *_Nullable (^of_stream_async_write_block_t)(
    OF_KINDOF(OFStream *) stream, OFData *_Nonnull data, size_t bytesWritten,
    id _Nullable exception);
#endif

/*!
 * @protocol OFStreamDelegate OFStream.h ObjFW/OFStream.h
 *
 * A delegate for OFStream.
126
127
128
129
130
131
132
133
134


135
136


137
138

139
140
141
142
143
144
145




146
147
148
149
150
151
152
121
122
123
124
125
126
127


128
129


130
131
132

133


134




135
136
137
138
139
140
141
142
143
144
145







-
-
+
+
-
-
+
+

-
+
-
-

-
-
-
-
+
+
+
+







     exception: (nullable id)exception;

/*!
 * @brief This method is called when data was written asynchronously to a
 *	  stream.
 *
 * @param stream The stream to which data was written
 * @param buffer A pointer to the buffer which was written to the stream. This
 *		 can be changed to point to a different buffer to be used on the
 * @param data The data which was written to the stream
 * @param bytesWritten The number of bytes which have been written. This
 *		 next write.
 * @param length The length of the buffer that has been written
 *		       matches the length of the specified data on the
 *		       asynchronous write if no exception was encountered.
 * @param exception An exception that occurred while writing, or nil on success
 * @return The length to repeat the write with or 0 if it should not repeat.
 * @return The data to repeat the write with or nil if it should not repeat
 *	   The buffer may be changed, so that every time a new buffer and
 *	   length can be specified
 */
- (size_t)stream: (OF_KINDOF(OFStream *))stream
  didWriteBuffer: (const void *_Nonnull *_Nonnull)buffer
	  length: (size_t)length
       exception: (nullable id)exception;
- (nullable OFData *)stream: (OF_KINDOF(OFStream *))stream
	       didWriteData: (OFData *)data
	       bytesWritten: (size_t)bytesWritten
		  exception: (nullable id)exception;
@end

/*!
 * @class OFStream OFStream.h ObjFW/OFStream.h
 *
 * @brief A base class for different types of streams.
 *
956
957
958
959
960
961
962
963

964
965
966
967
968

969
970
971
972

973
974
975
976

977
978
979
980
981

982
983
984
985
986

987
988

989
990
991
992

993
994
995
996
997
998
999




1000
1001
1002


1003
1004
1005
1006

1007
1008

1009
1010
1011

1012
1013
1014
1015
1016

1017
1018
1019
1020
1021
1022


1023
1024
1025
1026

1027
1028
1029


1030
1031
1032
1033
1034
1035
1036
949
950
951
952
953
954
955

956
957
958
959
960

961


962

963

964
965

966
967
968
969
970

971


972
973

974


975
976
977
978

979



980



981
982
983
984
985


986
987


988

989


990
991
992

993
994
995
996
997

998


999
1000


1001
1002


1003

1004



1005
1006
1007
1008
1009
1010
1011
1012
1013







-
+




-
+
-
-

-
+
-


-
+




-
+
-
-


-
+
-
-
+



-
+
-
-
-

-
-
-
+
+
+
+

-
-
+
+
-
-

-
+
-
-
+


-
+




-
+
-
-


-
-
+
+
-
-

-
+
-
-
-
+
+







 *	   length in non-blocking mode.
 */
- (size_t)writeBuffer: (const void *)buffer
	       length: (size_t)length;

#ifdef OF_HAVE_SOCKETS
/*!
 * @brief Asynchronously writes a buffer into the stream.
 * @brief Asynchronously writes data into the stream.
 *
 * @note The stream must conform to @ref OFReadyForWritingObserving in order
 *	 for this to work!
 *
 * @param buffer The buffer from which the data is written into the stream. The
 * @param data The data which is written into the stream
 *		 buffer needs to be valid until the write request is completed!
 * @param length The length of the data that should be written
 */
- (void)asyncWriteBuffer: (const void *)buffer
- (void)asyncWriteData: (OFData *)data;
		  length: (size_t)length;

/*!
 * @brief Asynchronously writes a buffer into the stream.
 * @brief Asynchronously writes data into the stream.
 *
 * @note The stream must conform to @ref OFReadyForWritingObserving in order
 *	 for this to work!
 *
 * @param buffer The buffer from which the data is written into the stream. The
 * @param data The data which is written into the stream
 *		 buffer needs to be valid until the write request is completed!
 * @param length The length of the data that should be written
 * @param runLoopMode The run loop mode in which to perform the async write
 */
- (void)asyncWriteBuffer: (const void *)buffer
- (void)asyncWriteData: (OFData *)data
		  length: (size_t)length
	     runLoopMode: (of_run_loop_mode_t)runLoopMode;
	   runLoopMode: (of_run_loop_mode_t)runLoopMode;

# ifdef OF_HAVE_BLOCKS
/*!
 * @brief Asynchronously writes a buffer into the stream.
 * @brief Asynchronously writes data into the stream.
 *
 * @note The stream must conform to @ref OFReadyForWritingObserving in order
 *	 for this to work!
 *
 * @param buffer The buffer from which the data is written into the stream. The
 *		 buffer needs to be valid until the write request is completed!
 * @param length The length of the data that should be written
 * @note The stream must conform to @ref OFReadyForWritingObserving in order
 *	 for this to work!
 *
 * @param data The data which is written into the stream
 * @param block The block to call when the data has been written. It should
 *		return the length for the next write with the same callback or
 *		0 if it should not repeat. The buffer may be changed, so that
 *		return the data for the next write with the same callback or
 *		nil if it should not repeat.
 *		every time a new buffer and length can be specified while the
 *		callback stays the same.
 */
- (void)asyncWriteBuffer: (const void *)buffer
- (void)asyncWriteData: (OFData *)data
		  length: (size_t)length
		   block: (of_stream_async_write_block_t)block;
		 block: (of_stream_async_write_block_t)block;

/*!
 * @brief Asynchronously writes a buffer into the stream.
 * @brief Asynchronously writes data into the stream.
 *
 * @note The stream must conform to @ref OFReadyForWritingObserving in order
 *	 for this to work!
 *
 * @param buffer The buffer from which the data is written into the stream. The
 * @param data The data which is written into the stream
 *		 buffer needs to be valid until the write request is completed!
 * @param length The length of the data that should be written
 * @param runLoopMode The run loop mode in which to perform the async write
 * @param block The block to call when the data has been written. It should
 *		return the length for the next write with the same callback or
 *		0 if it should not repeat. The buffer may be changed, so that
 *		return the data for the next write with the same callback or
 *		nil if it should not repeat.
 *		every time a new buffer and length can be specified while the
 *		callback stays the same.
 */
- (void)asyncWriteBuffer: (const void *)buffer
- (void)asyncWriteData: (OFData *)data
		  length: (size_t)length
	     runLoopMode: (of_run_loop_mode_t)runLoopMode
		   block: (of_stream_async_write_block_t)block;
	   runLoopMode: (of_run_loop_mode_t)runLoopMode
		 block: (of_stream_async_write_block_t)block;
# endif
#endif

/*!
 * @brief Writes a uint8_t into the stream.
 *
 * @param int8 A uint8_t