summaryrefslogtreecommitdiffstats
path: root/Liaison/WriterThreadPool.m
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-04-14 21:45:08 -0400
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-04-14 21:45:08 -0400
commit17349a5e426dc7acf1216a3767a22f69974cbca0 (patch)
tree20029d02f07ab6257cccec36d34fb312f796e1d1 /Liaison/WriterThreadPool.m
downloadliaison-17349a5e426dc7acf1216a3767a22f69974cbca0.tar.gz
liaison-17349a5e426dc7acf1216a3767a22f69974cbca0.zip
Initial commit.
Diffstat (limited to 'Liaison/WriterThreadPool.m')
-rw-r--r--Liaison/WriterThreadPool.m95
1 files changed, 95 insertions, 0 deletions
diff --git a/Liaison/WriterThreadPool.m b/Liaison/WriterThreadPool.m
new file mode 100644
index 0000000..6aefc44
--- /dev/null
+++ b/Liaison/WriterThreadPool.m
@@ -0,0 +1,95 @@
+//
+// WriterThreadPool.m
+// Liaison
+//
+// Created by Brian Cully on Wed Feb 26 2003.
+// Copyright (c) 2003 Brian Cully. All rights reserved.
+//
+
+#import "WriterThreadPool.h"
+
+#import "WriterThread.h"
+
+#import <signal.h>
+
+@implementation WriterThreadPool
+static WriterThreadPool *sharedPool = nil;
+
++ (WriterThreadPool *)sharedPool
+{
+ if (sharedPool == nil)
+ sharedPool = [[WriterThreadPool alloc] init];
+ return sharedPool;
+}
+
+void ign_handler()
+{
+ return;
+}
+
+- (id)init
+{
+ NSNotificationCenter *defaultCenter;
+ struct sigaction ign_action;
+
+ self = [super init];
+
+ ign_action.sa_handler = ign_handler;
+ sigemptyset(&ign_action.sa_mask);
+ ign_action.sa_flags = SA_RESTART;
+ sigaction(SIGPIPE, &ign_action, NULL);
+
+ theWriterThreads = [[NSMutableDictionary alloc] init];
+
+ defaultCenter = [NSNotificationCenter defaultCenter];
+ [defaultCenter addObserver: self
+ selector: @selector(writerThreadDied:)
+ name: WriterThreadDied
+ object: nil];
+
+ return self;
+}
+
+- (void)dealloc
+{
+ [theWriterThreads release];
+ [super dealloc];
+}
+
+- (void)writeData: (NSData *)someData to: (NSFileHandle *)aFileHandle
+{
+ NSNumber *fd;
+ WriterThread *writer;
+
+ fd = [NSNumber numberWithInt: [aFileHandle fileDescriptor]];
+ writer = [theWriterThreads objectForKey: fd];
+ if (writer == nil) {
+ writer = [[WriterThread alloc] initWithFileHandle: aFileHandle];
+ [theWriterThreads setObject: writer forKey: fd];
+ [writer release];
+ }
+ [writer writeData: someData];
+}
+
+- (void)killThreadFor: (NSFileHandle *)aFileHandle
+{
+ NSNumber *fd;
+ WriterThread *writer;
+
+ fd = [NSNumber numberWithInt: [aFileHandle fileDescriptor]];
+ writer = [theWriterThreads objectForKey: fd];
+ [writer die];
+}
+
+- (void)writerThreadDied: (NSNotification *)aNotification
+{
+ NSNumber *fd;
+ WriterThread *writer;
+
+ writer = [aNotification object];
+
+ fd = [[aNotification userInfo] objectForKey: @"FileDescriptorKey"];
+ [theWriterThreads removeObjectForKey: fd];
+}
+@synthesize theWriterThreads;
+@end