Make withServer provide the actual port (#29)

* Make withServer provide the actual port

Again, useful to make a server listen on any available port by giving it
port zero (for testing).

* Re-introduce check on server port

* Add port field to Server

* Style: Remove unneeded newline

* Revert changes in tests
This commit is contained in:
Olivier Nicole 2017-08-21 17:34:30 +02:00 committed by intractable
parent ab8ec43d17
commit e0c567ec55

View File

@ -52,6 +52,7 @@ import qualified Network.GRPC.Unsafe.Security as C
data Server = Server
{ serverGRPC :: GRPC
, unsafeServer :: C.Server
, listeningPort :: Port
, serverCQ :: CompletionQueue
-- ^ CQ used for receiving new calls.
, serverCallCQ :: CompletionQueue
@ -160,7 +161,7 @@ startServer grpc conf@ServerConfig{..} =
let e = serverEndpoint conf
server <- C.grpcServerCreate args C.reserved
actualPort <- addPort server conf
when (actualPort /= unPort port) $
when (unPort port > 0 && actualPort /= unPort port) $
error $ "Unable to bind port: " ++ show port
cq <- createCompletionQueue grpc
grpcDebug $ "startServer: server CQ: " ++ show cq
@ -182,7 +183,8 @@ startServer grpc conf@ServerConfig{..} =
forks <- newTVarIO S.empty
shutdown <- newTVarIO False
ccq <- createCompletionQueue grpc
return $ Server grpc server cq ccq ns ss cs bs conf forks shutdown
return $ Server grpc server (Port actualPort) cq ccq ns ss cs bs conf forks
shutdown