Develop and Download Open Source Software

Browse CVS Repository

Contents of /undmail/proto/POPEngineAndPOPController/CommunicationChannel.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Fri Feb 14 13:05:02 2003 UTC (21 years, 2 months ago) by masakih
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +4 -23 lines
remive connection using NSConnection.

1 //
2 // CommunicationChannel.m
3 //
4 // Created by Hori,Masaki on Tue Nov 26 2002.
5 //
6
7 #import "CommunicationChannel.h"
8 #import "Queue.h"
9
10 @interface CommunicationChannel (Private)
11 -(void)makeWorkers:(int)num;
12 -(void)makeWorker;
13 @end
14
15 @implementation CommunicationChannel
16
17 -(id)initWithWorkersNum:(int)num queueSize:(unsigned)size
18 {
19 self = [super init];
20 if( self ) {
21 queue = [[Queue alloc] initWithCapacity:size];
22 workers = [[NSMutableArray alloc] initWithCapacity:num];
23 [self makeWorkers:num];
24 }
25
26 return self;
27 }
28
29 -(void)putResuest:(id <CommunicationRequest>)request
30 {
31 NSLock* lock = [[NSLock alloc] init];
32
33 [lock lock];
34
35 NS_DURING
36 [queue put:request];
37 NS_HANDLER
38 if( ![[localException name] isEqualTo:QueueOverflow] ) {
39 [lock unlock];
40 [lock release];
41 [localException raise];
42 }
43 NS_ENDHANDLER
44
45 [lock unlock];
46 [lock release];
47
48 }
49
50 -(id <CommunicationRequest>)takeRequest
51 {
52 NSLock* lock = [[NSLock alloc] init];
53 id result;
54
55 [lock lock];
56 result = [queue take];
57 [lock unlock];
58 [lock release];
59
60 return result;
61 }
62
63 -(void)terminateAll
64 {
65 NSLock* lock = [[NSLock alloc] init];
66
67 [lock lock];
68 while( [queue take] ) ;
69 [lock unlock];
70 [lock release];
71
72 [workers makeObjectsPerformSelector:@selector(terminate)];
73 }
74
75
76 @end
77
78 @implementation CommunicationChannel (Private)
79 -(void)makeWorkers:(int)num
80 {
81 int i;
82
83 for( i = 0; i < num; i++ ) {
84 [self makeWorker];
85 }
86 }
87
88 -(void)makeWorker
89 {
90 CommunicationWorker* worker = [[[CommunicationWorker alloc] initWithChannel:self] autorelease];
91
92 [workers addObject:worker];
93
94 [NSThread detachNewThreadSelector:@selector(startWorking) toTarget:worker withObject:nil];
95 }
96
97 @end
98

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26