Skip to content

Commit

Permalink
update for code consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed Dec 1, 2021
1 parent ce868bb commit ed8a1c9
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 174 deletions.
2 changes: 1 addition & 1 deletion cs/remote/samples/VarLenServer/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Options
[Option("port", Required = false, Default = 3278, HelpText = "Port to run server on")]
public int Port { get; set; }

[Option("bind", Required = false, Default = "127.0.0.1", HelpText = "IP address to bind server to")]
[Option("bind", Required = false, Default = null, HelpText = "IP address to bind server to (default: any)")]
public string Address { get; set; }

[Option('m', "memory", Required = false, Default = "16g", HelpText = "Total log memory used in bytes (rounds down to power of 2)")]
Expand Down
1 change: 1 addition & 0 deletions cs/remote/samples/VarLenServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Program
{
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("DOTNET_SYSTEM_NET_SOCKETS_INLINE_COMPLETIONS", "1");
Trace.Listeners.Add(new ConsoleTraceListener());

Console.WriteLine("FASTER variable-length KV server");
Expand Down
47 changes: 24 additions & 23 deletions cs/remote/samples/VarLenServer/VarLenServer.csproj
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>AnyCPU;x64</Platforms>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Platforms>AnyCPU;x64</Platforms>
<LangVersion>latest</LangVersion>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DebugType>full</DebugType>
<OutputPath>bin\$(Platform)\Debug\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DebugType>full</DebugType>
<OutputPath>bin\$(Platform)\Debug\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<OutputPath>bin\$(Platform)\Release\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<OutputPath>bin\$(Platform)\Release\</OutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\FASTER.server\FASTER.server.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\FASTER.server\FASTER.server.csproj" />
</ItemGroup>

</Project>
163 changes: 163 additions & 0 deletions cs/remote/src/FASTER.server/PubSub/GlobUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

namespace FASTER.server
{
/// <summary>
/// Glob utils
/// </summary>
public static class GlobUtils
{
/// <summary>
/// Glob-style pattern matching
/// </summary>
/// <returns>Whether match was found</returns>
public static unsafe bool Match(byte* pattern, int patternLen, byte* key, int stringLen, bool nocase = false)
{
while (patternLen > 0 && stringLen > 0)
{
switch (pattern[0])
{
case (byte)'*':
while (patternLen > 0 && pattern[1] == '*')
{
pattern++;
patternLen--;
}
if (patternLen == 1)
return true; /* match */
while (stringLen > 0)
{
if (Match(pattern + 1, patternLen - 1, key, stringLen, nocase))
return true; /* match */
key++;
stringLen--;
}
return false; /* no match */

case (byte)'?':
key++;
stringLen--;
break;

case (byte)'[':
{
bool not, match;
pattern++;
patternLen--;
not = (pattern[0] == '^');
if (not)
{
pattern++;
patternLen--;
}
match = false;
while (true)
{
if (pattern[0] == '\\' && patternLen >= 2)
{
pattern++;
patternLen--;
if (pattern[0] == key[0])
match = true;
}
else if (pattern[0] == ']')
{
break;
}
else if (patternLen == 0)
{
pattern--;
patternLen++;
break;
}
else if (patternLen >= 3 && pattern[1] == '-')
{
int start = pattern[0];
int end = pattern[2];
int c = key[0];
if (start > end)
{
int t = start;
start = end;
end = t;
}
if (nocase)
{
start = char.ToLower((char)start);
end = char.ToLower((char)end);
c = char.ToLower((char)c);
}
pattern += 2;
patternLen -= 2;
if (c >= start && c <= end)
match = true;
}
else
{
if (!nocase)
{
if (pattern[0] == key[0])
match = true;
}
else
{
if (char.ToLower((char)pattern[0]) == char.ToLower((char)key[0]))
match = true;
}
}
pattern++;
patternLen--;
}

if (not)
match = !match;
if (!match)
return false; /* no match */
key++;
stringLen--;
break;
}

case (byte)'\\':
if (patternLen >= 2)
{
pattern++;
patternLen--;
}
goto default;

/* fall through */
default:
if (!nocase)
{
if (pattern[0] != key[0])
return false; /* no match */
}
else
{
if (char.ToLower((char)pattern[0]) != char.ToLower((char)key[0]))
return false; /* no match */
}
key++;
stringLen--;
break;
}
pattern++;
patternLen--;
if (stringLen == 0)
{
while (*pattern == '*')
{
pattern++;
patternLen--;
}
break;
}
}
if (patternLen == 0 && stringLen == 0)
return true;
return false;
}
}
}
Loading

0 comments on commit ed8a1c9

Please sign in to comment.