get free port that can be used by non root users (> 1024)
This commit is contained in:
		@@ -69,7 +69,7 @@ namespace ix
 | 
				
			|||||||
        Logger() << msg;
 | 
					        Logger() << msg;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int getFreePort()
 | 
					    int getAnyFreePort()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int defaultPort = 8090;
 | 
					        int defaultPort = 8090;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -117,4 +117,23 @@ namespace ix
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return port;
 | 
					        return port;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    int getFreePort()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        while (true)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            int port = getAnyFreePort();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            //
 | 
				
			||||||
 | 
					            // Only port above 1024 can be used by non root users, but for some
 | 
				
			||||||
 | 
					            // reason I got port 7 returned with macOS when binding on port 0...
 | 
				
			||||||
 | 
					            //
 | 
				
			||||||
 | 
					            if (port > 1024)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return port;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user