Author: rfm
Date: Tue Jun 21 18:14:22 2016
New Revision: 39898

URL: http://svn.gna.org/viewcvs/gnustep?rev=39898&view=rev
Log:
Alter to allow notifications to be sent to observers asynchronously

Modified:
    libs/sqlclient/trunk/Postgres.m

Modified: libs/sqlclient/trunk/Postgres.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/Postgres.m?rev=39898&r1=39897&r2=39898&view=diff
==============================================================================
--- libs/sqlclient/trunk/Postgres.m     (original)
+++ libs/sqlclient/trunk/Postgres.m     Tue Jun 21 18:14:22 2016
@@ -39,6 +39,7 @@
 #import        <Foundation/NSNotificationQueue.h>
 #import        <Foundation/NSNull.h>
 #import        <Foundation/NSProcessInfo.h>
+#import        <Foundation/NSRunLoop.h>
 #import        <Foundation/NSString.h>
 #import        <Foundation/NSThread.h>
 #import        <Foundation/NSTimeZone.h>
@@ -61,14 +62,25 @@
 - (NSDate*) dbToDateFromBuffer: (char*)b length: (int)l;
 @end
 
+#if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
+@interface SQLClientPostgres (RunLoop) <RunLoopEvents>
+- (void) receivedEvent: (void*)data
+                  type: (RunLoopEventType)type
+                 extra: (void*)extra
+               forMode: (NSString*)mode;
+@end
+#endif
+
 typedef struct {
   PGconn       *_connection;
   int           _backendPID;
+  NSRunLoop     *_runLoop;
 } ConnectionInfo;
 
 #define        cInfo                   ((ConnectionInfo*)(self->extra))
 #define        backendPID              (cInfo->_backendPID)
 #define        connection              (cInfo->_connection)
+#define        runLoop                 (cInfo->_runLoop)
 
 static NSDate  *future = nil;
 static NSNull  *null = nil;
@@ -497,6 +509,16 @@
 {
   if (extra != 0 && connection != 0)
     {
+#if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
+      if (runLoop != nil)
+        {
+          [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
+                          type: ET_RDESC
+                       forMode: NSDefaultRunLoopMode
+                           all: YES];
+          DESTROY(runLoop);
+        }
+#endif
       NS_DURING
        {
          if ([self isInTransaction] == YES)
@@ -707,6 +729,16 @@
 - (void) backendListen: (NSString*)name
 {
   [self execute: @"LISTEN ", name, nil];
+#if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
+  if (nil == runLoop && 0 != connection)
+    {
+      ASSIGN(runLoop, [NSRunLoop currentRunLoop]);
+      [runLoop addEvent: (void*)(uintptr_t)PQsocket(connection)
+                   type: ET_RDESC
+                watcher: self
+                forMode: NSDefaultRunLoopMode];
+    }
+#endif
 }
 
 - (void) backendNotify: (NSString*)name payload: (NSString*)more
@@ -1176,6 +1208,16 @@
 
 - (void) backendUnlisten: (NSString*)name
 {
+#if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
+  if (runLoop != nil)
+    {
+      [runLoop removeEvent: (void*)(uintptr_t)PQsocket(connection)
+                      type: ET_RDESC
+                   forMode: NSDefaultRunLoopMode
+                       all: YES];
+      DESTROY(runLoop);
+    }
+#endif
   [self execute: @"UNLISTEN ", name, nil];
 }
 
@@ -1619,3 +1661,18 @@
 
 @end
 
+#if     defined(GNUSTEP_BASE_LIBRARY) && !defined(__MINGW__)
+@implementation SQLClientPostgres (RunLoop)
+- (void) receivedEvent: (void*)data
+                  type: (RunLoopEventType)type
+                 extra: (void*)extra
+               forMode: (NSString*)mode
+{
+  if (0 != connection)
+    {
+      PQconsumeInput(connection);
+      [self _checkNotifications];
+    }
+}
+@end
+#endif


_______________________________________________
Gnustep-cvs mailing list
Gnustep-cvs@gna.org
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to