Browse Source

Replace some magic numbers with more understandable constants.

Daniel Alm 8 years ago
parent
commit
8b8e6c86dd
1 changed files with 9 additions and 3 deletions
  1. 9 3
      Sources/SwiftGRPC/Core/Server.swift

+ 9 - 3
Sources/SwiftGRPC/Core/Server.swift

@@ -21,6 +21,12 @@ import Foundation
 
 /// gRPC Server
 public class Server {
+  static let handlerCallTag = 101
+  
+  // These are sent by the CgRPC shim.
+  static let stopTag = 0
+  static let destroyTag = 1000
+  
   /// Pointer to underlying C representation
   private let underlyingServer: UnsafeMutableRawPointer
 
@@ -70,13 +76,13 @@ public class Server {
       while running {
         do {
           let handler = Handler(underlyingServer: self.underlyingServer)
-          try handler.requestCall(tag: 101)
+          try handler.requestCall(tag: Server.handlerCallTag)
 
           // block while waiting for an incoming request
           let event = self.completionQueue.wait(timeout: 600)
 
           if event.type == .complete {
-            if event.tag == 101 {
+            if event.tag == Server.handlerCallTag {
               // run the handler and remove it when it finishes
               if event.success != 0 {
                 // hold onto the handler while it runs
@@ -95,7 +101,7 @@ public class Server {
                 // call the handler function on the server thread
                 handlerFunction(handler)
               }
-            } else if event.tag == 0 || event.tag == 1000 {
+            } else if event.tag == Server.stopTag || event.tag == Server.destroyTag {
               running = false // exit the loop
             }
           } else if event.type == .queueTimeout {