ObjFW  Diff

Differences From Artifact [f1fb6806e0]:

To Artifact [b904df7bb8]:


184
185
186
187
188
189
190

191
192

193
194
195
196
197
198

199
200
201

202
203
204
205
206
207

208
209

210
211
212
213
214
215

216
217
218

219
220
221
222
223
224

225
226

227
228
229
230
231
232

233
234
235

236
237
238
239
240
241
242
243
244
245
246

247
248

249
250
251
252
253
254

255
256
257

258
259
260
261
262
263
264
- (void)setDelegate: (id <OFStreamObserverDelegate>)delegate_
{
	delegate = delegate_;
}

- (void)addStreamForReading: (OFStream*)stream
{

	[mutex lock];
	@try {

		int qi = QUEUE_ADD | QUEUE_READ;
		int fd = [stream fileDescriptorForReading];

		[queue addObject: stream];
		[queueInfo addItem: &qi];
		[queueFDs addItem: &fd];

	} @finally {
		[mutex unlock];
	}


	[self cancel];
}

- (void)addStreamForWriting: (OFStream*)stream
{

	[mutex lock];
	@try {

		int qi = QUEUE_ADD | QUEUE_WRITE;
		int fd = [stream fileDescriptorForWriting];

		[queue addObject: stream];
		[queueInfo addItem: &qi];
		[queueFDs addItem: &fd];

	} @finally {
		[mutex unlock];
	}


	[self cancel];
}

- (void)removeStreamForReading: (OFStream*)stream
{

	[mutex lock];
	@try {

		int qi = QUEUE_REMOVE | QUEUE_READ;
		int fd = [stream fileDescriptorForReading];

		[queue addObject: stream];
		[queueInfo addItem: &qi];
		[queueFDs addItem: &fd];

	} @finally {
		[mutex unlock];
	}


#ifndef _WIN32
	OF_ENSURE(write(cancelFD[1], "", 1) > 0);
#else
	OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	    sizeof(cancelAddr)) > 0);
#endif
}

- (void)removeStreamForWriting: (OFStream*)stream
{

	[mutex lock];
	@try {

		int qi = QUEUE_REMOVE | QUEUE_WRITE;
		int fd = [stream fileDescriptorForWriting];

		[queue addObject: stream];
		[queueInfo addItem: &qi];
		[queueFDs addItem: &fd];

	} @finally {
		[mutex unlock];
	}


#ifndef _WIN32
	OF_ENSURE(write(cancelFD[1], "", 1) > 0);
#else
	OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	    sizeof(cancelAddr)) > 0);
#endif







>


>






>



>






>


>






>



>






>


>






>



>











>


>






>



>







184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
- (void)setDelegate: (id <OFStreamObserverDelegate>)delegate_
{
	delegate = delegate_;
}

- (void)addStreamForReading: (OFStream*)stream
{
#ifdef OF_THREADS
	[mutex lock];
	@try {
#endif
		int qi = QUEUE_ADD | QUEUE_READ;
		int fd = [stream fileDescriptorForReading];

		[queue addObject: stream];
		[queueInfo addItem: &qi];
		[queueFDs addItem: &fd];
#ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
#endif

	[self cancel];
}

- (void)addStreamForWriting: (OFStream*)stream
{
#ifdef OF_THREADS
	[mutex lock];
	@try {
#endif
		int qi = QUEUE_ADD | QUEUE_WRITE;
		int fd = [stream fileDescriptorForWriting];

		[queue addObject: stream];
		[queueInfo addItem: &qi];
		[queueFDs addItem: &fd];
#ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
#endif

	[self cancel];
}

- (void)removeStreamForReading: (OFStream*)stream
{
#ifdef OF_THREADS
	[mutex lock];
	@try {
#endif
		int qi = QUEUE_REMOVE | QUEUE_READ;
		int fd = [stream fileDescriptorForReading];

		[queue addObject: stream];
		[queueInfo addItem: &qi];
		[queueFDs addItem: &fd];
#ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
#endif

#ifndef _WIN32
	OF_ENSURE(write(cancelFD[1], "", 1) > 0);
#else
	OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	    sizeof(cancelAddr)) > 0);
#endif
}

- (void)removeStreamForWriting: (OFStream*)stream
{
#ifdef OF_THREADS
	[mutex lock];
	@try {
#endif
		int qi = QUEUE_REMOVE | QUEUE_WRITE;
		int fd = [stream fileDescriptorForWriting];

		[queue addObject: stream];
		[queueInfo addItem: &qi];
		[queueFDs addItem: &fd];
#ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
#endif

#ifndef _WIN32
	OF_ENSURE(write(cancelFD[1], "", 1) > 0);
#else
	OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr,
	    sizeof(cancelAddr)) > 0);
#endif
286
287
288
289
290
291
292

293
294

295
296
297
298
299
300
301
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

- (void)OF_processQueue
{

	[mutex lock];
	@try {

		OFStream **queueObjects = [queue objects];
		int *queueInfoItems = [queueInfo items];
		int *queueFDsItems = [queueFDs items];
		size_t i, count = [queue count];

		for (i = 0; i < count; i++) {
			OFStream *stream = queueObjects[i];







>


>







302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
{
	[self doesNotRecognizeSelector: _cmd];
	abort();
}

- (void)OF_processQueue
{
#ifdef OF_THREADS
	[mutex lock];
	@try {
#endif
		OFStream **queueObjects = [queue objects];
		int *queueInfoItems = [queueInfo items];
		int *queueFDsItems = [queueFDs items];
		size_t i, count = [queue count];

		for (i = 0; i < count; i++) {
			OFStream *stream = queueObjects[i];
348
349
350
351
352
353
354

355
356
357

358
359
360
361
362
363
364
				assert(0);
			}
		}

		[queue removeAllObjects];
		[queueInfo removeAllItems];
		[queueFDs removeAllItems];

	} @finally {
		[mutex unlock];
	}

}

- (void)observe
{
	[self observeWithTimeout: -1];
}








>



>







366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
				assert(0);
			}
		}

		[queue removeAllObjects];
		[queueInfo removeAllItems];
		[queueFDs removeAllItems];
#ifdef OF_THREADS
	} @finally {
		[mutex unlock];
	}
#endif
}

- (void)observe
{
	[self observeWithTimeout: -1];
}