-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
161 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,3 @@ CTestTestfile.cmake | |
_deps | ||
.vs | ||
out | ||
CMakeSettings.json |
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,9 +1,7 @@ | ||
# CMakeList.txt : CMake project for StreamBase, include source and define | ||
# project specific logic here. | ||
# | ||
project(StreamBase) | ||
cmake_minimum_required (VERSION 3.8) | ||
|
||
# Add source to this project's executable. | ||
add_executable (server "server.cpp" "server.h") | ||
add_executable (exampleClient "exampleClient.cpp" "CustomClass.cpp" "CustomClass.h" "client.cpp" "client.h") | ||
add_executable (exampleAsyncClient "exampleAsyncClient.cpp" "CustomClass.cpp" "CustomClass.h" "client.cpp" "client.h") | ||
add_executable (server "server.cpp" "server.h" "common.cpp" "common.h") | ||
add_executable (exampleClient "exampleClient.cpp" "CustomClass.cpp" "CustomClass.h" "client.cpp" "client.h" "common.cpp" "common.h") | ||
add_executable (exampleAsyncClient "exampleAsyncClient.cpp" "CustomClass.cpp" "CustomClass.h" "client.cpp" "client.h" "common.cpp" "common.h") |
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,28 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "x64-Debug", | ||
"generator": "Ninja", | ||
"configurationType": "Debug", | ||
"inheritEnvironments": [ "msvc_x64_x64" ], | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"buildCommandArgs": "-v", | ||
"ctestCommandArgs": "", | ||
"variables": [] | ||
}, | ||
{ | ||
"name": "x64-Release", | ||
"generator": "Ninja", | ||
"configurationType": "Release", | ||
"buildRoot": "${projectDir}\\out\\build\\${name}", | ||
"installRoot": "${projectDir}\\out\\install\\${name}", | ||
"cmakeCommandArgs": "", | ||
"buildCommandArgs": "-v", | ||
"ctestCommandArgs": "", | ||
"inheritEnvironments": [ "msvc_x64_x64" ], | ||
"variables": [] | ||
} | ||
] | ||
} |
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 +1,32 @@ | ||
StreamBase | ||
# StreamBase | ||
|
||
Clients communicate with the server by initially sending a header message containing an Action which specifies whether they want to do a save or a get and what key to use. | ||
|
||
## Send | ||
On receiving a send action, the server will expect and read a second message containing the binary archive of the data. | ||
After inserting the data into the store, the server will send a message back to the client notifying it the save has been completed. | ||
|
||
## Get | ||
On receiving a get action, the server will retrieve the binary archive for the given key from the store and send it back in a message to the client. | ||
Note that the client-side `get()` function requires the type of the data being returned to be specified. | ||
|
||
## Data Store | ||
The server stores data in a map from the given key to a binary archive of the provided object. | ||
The map is guarded by a shared mutex to ensure thread-safe access. | ||
|
||
## Serialization | ||
|
||
This implementation of StreamBase depends on `cereal` to serialize data. | ||
This means extra code may be required for certain types of data | ||
e.g. for custom classes a `serialize` method that is a `friend` of the class may be required in order to serialize its attributes, as C++ lacks reflection. | ||
|
||
## Assumptions | ||
|
||
For simplicity it is assumed data being sent fits within a single message, and that cases will conform to the spec meaning there is currently no error handling | ||
e.g. attempting to retrieve data which has not been saved is unhandled, clients expect the server to be running, etc. | ||
|
||
## Multithreading | ||
|
||
This implementation of StreamBase supports async via multithreading. The server uses a different thread and pipe instance for each client connection. | ||
|
||
Multithreaded code uses a custom `log()` function as `cout` is not thread-safe. |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <iostream> | ||
#include <mutex> | ||
#include "common.h" | ||
|
||
std::mutex coutLock; | ||
|
||
void log(std::string msg) { | ||
std::lock_guard<std::mutex> lg{ coutLock }; | ||
std::cout << msg << std::endl; | ||
} |
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
Oops, something went wrong.