48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
of_stream_async_read_line_block_t block;
of_string_encoding_t encoding;
}
@property (copy) of_stream_async_read_line_block_t block;
@property of_string_encoding_t encoding;
@end
@implementation OFRunLoop_ReadQueueItem
@synthesize buffer, length, block;
- (void)dealloc
{
[block release];
[super dealloc];
}
@end
@implementation OFRunLoop_ReadLineQueueItem
@synthesize block, encoding;
- (void)dealloc
{
[block release];
[super dealloc];
}
@end
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
|
of_stream_async_read_line_block_t block;
of_string_encoding_t encoding;
}
@property (copy) of_stream_async_read_line_block_t block;
@property of_string_encoding_t encoding;
@end
@interface OFRunLoop_AcceptQueueItem: OFObject
{
of_tcpsocket_async_accept_block_t block;
}
@property (copy) of_tcpsocket_async_accept_block_t block;
@end
@implementation OFRunLoop_ReadQueueItem
@synthesize buffer, length, block;
- (void)dealloc
{
[block release];
[super dealloc];
}
@end
@implementation OFRunLoop_ReadLineQueueItem
@synthesize block, encoding;
- (void)dealloc
{
[block release];
[super dealloc];
}
@end
@implementation OFRunLoop_AcceptQueueItem
@synthesize block;
- (void)dealloc
{
[block release];
[super dealloc];
}
@end
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
queueItem = [[[OFRunLoop_ReadLineQueueItem alloc] init] autorelease];
[queueItem setBlock: block];
[queueItem setEncoding: encoding];
[queue appendObject: queueItem];
objc_autoreleasePoolPop(pool);
}
#endif
- init
{
self = [super init];
@try {
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
177
178
179
180
181
182
183
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
|
queueItem = [[[OFRunLoop_ReadLineQueueItem alloc] init] autorelease];
[queueItem setBlock: block];
[queueItem setEncoding: encoding];
[queue appendObject: queueItem];
objc_autoreleasePoolPop(pool);
}
+ (void)_addAsyncAcceptForTCPSocket: (OFTCPSocket*)socket
block: (of_tcpsocket_async_accept_block_t)block
{
void *pool = objc_autoreleasePoolPush();
OFRunLoop *runLoop = [self currentRunLoop];
OFList *queue = [runLoop->readQueues objectForKey: socket];
OFRunLoop_AcceptQueueItem *queueItem;
if (queue == nil) {
queue = [OFList list];
[runLoop->readQueues setObject: queue
forKey: socket];
}
if ([queue count] == 0)
[runLoop->streamObserver addStreamForReading: socket];
queueItem = [[[OFRunLoop_AcceptQueueItem alloc] init] autorelease];
[queueItem setBlock: block];
[queue appendObject: queueItem];
objc_autoreleasePoolPop(pool);
}
#endif
- init
{
self = [super init];
@try {
|
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
if ([queue count] == 0) {
[streamObserver
removeStreamForReading: stream];
[readQueues removeObjectForKey: stream];
}
}
}
} else
OF_ENSURE(0);
}
#endif
- (void)run
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
if ([queue count] == 0) {
[streamObserver
removeStreamForReading: stream];
[readQueues removeObjectForKey: stream];
}
}
}
} else if ([listObject->object isKindOfClass:
[OFRunLoop_AcceptQueueItem class]]) {
OFRunLoop_AcceptQueueItem *queueItem = listObject->object;
OFTCPSocket *newSocket = [(OFTCPSocket*)stream accept];
if (![queueItem block]((OFTCPSocket*)stream, newSocket)) {
[queue removeListObject: listObject];
if ([queue count] == 0) {
[streamObserver removeStreamForReading: stream];
[readQueues removeObjectForKey: stream];
}
}
} else
OF_ENSURE(0);
}
#endif
- (void)run
|