Skip to content

Commit

Permalink
Merge pull request grpc#1169 from yang-g/pickport
Browse files Browse the repository at this point in the history
Add a macro to enable support of custom port picker.
  • Loading branch information
nicolasnoble committed Apr 2, 2015
2 parents 52bc8f9 + 7eb76cc commit 5228f62
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
4 changes: 4 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@
"name": "gpr_test_util",
"build": "private",
"language": "c",
"headers": [
"test/core/util/test_config.h"
],
"src": [
"test/core/util/test_config.c"
],
Expand Down Expand Up @@ -434,6 +437,7 @@
],
"deps": [
"gpr",
"gpr_test_util",
"grpc"
],
"vs_project_guid": "{17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}"
Expand Down
2 changes: 1 addition & 1 deletion include/grpc/support/port_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
#endif

#if defined(GPR_POSIX_SOCKET) + defined(GPR_WIN32) != 1
#error Must define exactly one of GPR_POSIX_POLLSET, GPR_WIN32
#error Must define exactly one of GPR_POSIX_SOCKET, GPR_WIN32
#endif

typedef int16_t gpr_int16;
Expand Down
7 changes: 4 additions & 3 deletions test/core/util/port_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
*/

#include <grpc/support/port_platform.h>
#ifdef GPR_POSIX_SOCKET
#include "test/core/util/test_config.h"
#if defined(GPR_POSIX_SOCKET) && defined(GRPC_TEST_PICK_PORT)

#include "test/core/util/port.h"

Expand Down Expand Up @@ -125,7 +126,7 @@ int grpc_pick_unused_port(void) {
} else {
port = 0;
}

if (!is_port_available(&port, is_tcp)) {
continue;
}
Expand Down Expand Up @@ -155,4 +156,4 @@ int grpc_pick_unused_port_or_die(void) {
return port;
}

#endif /* GPR_POSIX_SOCKET */
#endif /* GPR_POSIX_SOCKET && GRPC_TEST_PICK_PORT */
4 changes: 4 additions & 0 deletions test/core/util/test_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ extern "C" {
gpr_time_add(gpr_now(), \
gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)))

#ifndef GRPC_TEST_CUSTOM_PICK_PORT
#define GRPC_TEST_PICK_PORT
#endif

void grpc_test_init(int argc, char **argv);

#ifdef __cplusplus
Expand Down
3 changes: 3 additions & 0 deletions vsprojects/vs2013/gpr_test_util.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\test\core\util\test_config.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\test\core\util\test_config.c">
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions vsprojects/vs2013/grpc.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grpc_test_util", "grpc_test_util.vcxproj", "{17BCAFC0-5FDC-4C94-AEB9-95F3E220614B}"
ProjectSection(ProjectDependencies) = postProject
{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}
{EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037}
{29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9}
EndProjectSection
EndProject
Expand Down
3 changes: 3 additions & 0 deletions vsprojects/vs2013/grpc_test_util.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
<ProjectReference Include="gpr.vcxproj">
<Project>{B23D3D1A-9438-4EDA-BEB6-9A0A03D17792}</Project>
</ProjectReference>
<ProjectReference Include="gpr_test_util.vcxproj">
<Project>{EAB0A629-17A9-44DB-B5FF-E91A721FE037}</Project>
</ProjectReference>
<ProjectReference Include="grpc.vcxproj">
<Project>{29D16885-7228-4C31-81ED-5F9187C7F2A9}</Project>
</ProjectReference>
Expand Down

0 comments on commit 5228f62

Please sign in to comment.