Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions wish/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.14)
project(wish_cpp)

Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_executable(plain_benchmark_client
plain_client.cc
)
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/benchmark/benchmark.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import shlex
import subprocess
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/benchmark/high_qps_client.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <absl/flags/flag.h>
#include <absl/flags/parse.h>
#include <absl/log/initialize.h>
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/benchmark/plain_client.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <absl/flags/flag.h>
#include <absl/flags/parse.h>
#include <absl/log/initialize.h>
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/benchmark/tls_client.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <absl/flags/flag.h>
#include <absl/flags/parse.h>
#include <absl/log/initialize.h>
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/deployments/benchmark.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: batch/v1
kind: Job
metadata:
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/deployments/echo-server.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/deployments/stress.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: batch/v1
kind: Job
metadata:
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/deployments/tls-echo-server.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
14 changes: 14 additions & 0 deletions wish/cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

add_executable(plain_echo_server
plain_echo_server.cc
)
Expand Down
111 changes: 69 additions & 42 deletions wish/cpp/examples/h2_echo_server.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <absl/flags/flag.h>
#include <absl/flags/parse.h>
#include <absl/log/initialize.h>
Expand All @@ -14,56 +28,69 @@ int main(int argc, char** argv) {

const int port = absl::GetFlag(FLAGS_port);

H2Server server(port);

if (!server.Init()) {
LOG(ERROR) << "Init() failed";
event_base* base = event_base_new();
if (!base) {
LOG(ERROR) << "Failed to create event_base";

return 1;
}

server.SetOnStream([](WebStream* stream) {
LOG(INFO) << "OnStream";

stream->SetOnMessage([stream](uint8_t opcode, const std::string& msg) {
std::string type;
switch (opcode) {
case WEB_STREAM_OPCODE_TEXT:
type = "TEXT";
break;
case WEB_STREAM_OPCODE_BINARY:
type = "BINARY";
break;
case WEB_STREAM_OPCODE_METADATA:
type = "METADATA";
break;
default:
type = "UNKNOWN(" + std::to_string(opcode) + ")";
break;
}

LOG(INFO) << "OnMessage (opcode: " << type << ", message: " << msg << ")";

// Echo back
if (opcode == WEB_STREAM_OPCODE_TEXT) {
stream->SendText(msg);
} else if (opcode == WEB_STREAM_OPCODE_BINARY) {
stream->SendBinary(msg);
} else if (opcode == WEB_STREAM_OPCODE_METADATA) {
stream->SendMetadata(msg);
} else {
LOG(WARNING) << "Unknown opcode, cannot echo.";
}
});
{
H2Server server(base, port);

if (!server.Init()) {
LOG(ERROR) << "Init() failed";

event_base_free(base);

return 1;
}

stream->SetOnClose([stream]() {
LOG(INFO) << "OnClose";
server.SetOnStream([](WebStream* stream) {
LOG(INFO) << "OnStream";

stream->Close();
stream->SetOnMessage([stream](uint8_t opcode, const std::string& msg) {
std::string type;
switch (opcode) {
case WEB_STREAM_OPCODE_TEXT:
type = "TEXT";
break;
case WEB_STREAM_OPCODE_BINARY:
type = "BINARY";
break;
case WEB_STREAM_OPCODE_METADATA:
type = "METADATA";
break;
default:
type = "UNKNOWN(" + std::to_string(opcode) + ")";
break;
}

LOG(INFO) << "OnMessage (opcode: " << type << ", message: " << msg << ")";

// Echo back
if (opcode == WEB_STREAM_OPCODE_TEXT) {
stream->SendText(msg);
} else if (opcode == WEB_STREAM_OPCODE_BINARY) {
stream->SendBinary(msg);
} else if (opcode == WEB_STREAM_OPCODE_METADATA) {
stream->SendMetadata(msg);
} else {
LOG(WARNING) << "Unknown opcode, cannot echo.";
}
});

stream->SetOnClose([stream]() {
LOG(INFO) << "OnClose";

stream->Close();
});
});
});

server.Run();
server.Run();
}

event_base_free(base);

return 0;
}
Loading