-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b501927
commit aa7de3d
Showing
6 changed files
with
140 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
all: build-load-balancer build-is-port-free build-testmodel | ||
all: build-load-balancer build-is-port-free build-http-post build-testmodel | ||
|
||
build-load-balancer: | ||
- g++ -O3 -Wno-unused-result -std=c++17 -I../lib/ LoadBalancer.cpp -o load-balancer -pthread | ||
|
||
build-is-port-free: | ||
- g++ -O3 -std=c++17 is_port_free.cpp -o is_port_free | ||
|
||
build-http-post: | ||
- g++ -O3 -std=c++17 http_post.cpp -o http_post | ||
|
||
build-testmodel: | ||
- g++ -O3 -Wno-unused-result -std=c++17 -I../lib/ ../models/testmodel/minimal-server.cpp -o testmodel -pthread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "../lib/httplib.h" | ||
|
||
#include <iostream> | ||
|
||
// Usage: http_post <server url> <endpoint> <string message> | ||
int main(int argc, char* argv[]) | ||
{ | ||
// Get command line args | ||
if (argc < 2) { | ||
std::cerr << "Missing required positional argument: server url" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
const std::string url(argv[1]); | ||
|
||
if (argc < 3) { | ||
std::cerr << "Missing required positional argument: endpoint" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
const std::string endpoint(argv[2]); | ||
|
||
if (argc < 4) { | ||
std::cerr << "Missing required positional argument: string message" << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
const std::string message(argv[3]); | ||
|
||
httplib::Client cli(url); | ||
auto res = cli.Post(endpoint.c_str(), message, "text/plain"); | ||
|
||
if (!res) { | ||
std::cerr << "Client failed to POST: " << httplib::to_string(res.error()) << std::endl; | ||
std::cerr << "Failed connection attempt on URL: " << url << endpoint << std::endl; | ||
return EXIT_FAILURE; | ||
} else if (res->status != 200) { | ||
std::cerr << "Server returned error code: " << res->status << std::endl; | ||
return EXIT_FAILURE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters