diff options
| author | crupest <crupest@outlook.com> | 2021-06-06 23:51:32 +0800 | 
|---|---|---|
| committer | crupest <crupest@outlook.com> | 2021-06-06 23:51:32 +0800 | 
| commit | 2de4663d385ab54c5d8b8adc68611ad67636f56f (patch) | |
| tree | 669c7c55f6b2bf87d85c29d8a016e96cb7655c88 /works | |
| parent | 7a269e185fc59e5f81e7c91e6e75891ba2ca4b3b (diff) | |
| download | crupest-2de4663d385ab54c5d8b8adc68611ad67636f56f.tar.gz crupest-2de4663d385ab54c5d8b8adc68611ad67636f56f.tar.bz2 crupest-2de4663d385ab54c5d8b8adc68611ad67636f56f.zip | |
import(life): ...
Diffstat (limited to 'works')
| -rw-r--r-- | works/life/computer-network-experiment/Output.cpp | 2 | ||||
| -rw-r--r-- | works/life/computer-network-experiment/Output.h | 5 | ||||
| -rw-r--r-- | works/life/computer-network-experiment/server.cpp | 7 | 
3 files changed, 9 insertions, 5 deletions
| diff --git a/works/life/computer-network-experiment/Output.cpp b/works/life/computer-network-experiment/Output.cpp index ac4a47b..2968c19 100644 --- a/works/life/computer-network-experiment/Output.cpp +++ b/works/life/computer-network-experiment/Output.cpp @@ -1,6 +1,6 @@  #include "Output.h"
 -folly::MPMCQueue<Output> output_queue;
 +folly::MPMCQueue<Output> output_queue(100);
  void OutputThread() {
    while (true) {
 diff --git a/works/life/computer-network-experiment/Output.h b/works/life/computer-network-experiment/Output.h index 157e5c8..b81dbfd 100644 --- a/works/life/computer-network-experiment/Output.h +++ b/works/life/computer-network-experiment/Output.h @@ -29,10 +29,9 @@ inline void SendOutput(Output output) {    output_queue.blockingWrite(std::move(output));
  }
 -inline void SendOutput(String output) { SendOutput(std::move(output)); }
 +inline void SendOutput(String output) { SendOutput(Output{std::move(output)}); }
 -template <typename... Args>
 -void SendOutput(StringView format, Args &&...args) {
 +template <typename... Args> void SendOutput(StringView format, Args &&...args) {
    output_queue.blockingWrite(fmt::format(format, std::forward<Args>(args)...));
  }
 diff --git a/works/life/computer-network-experiment/server.cpp b/works/life/computer-network-experiment/server.cpp index ff03783..a5a7a9b 100644 --- a/works/life/computer-network-experiment/server.cpp +++ b/works/life/computer-network-experiment/server.cpp @@ -56,6 +56,8 @@ void ResponseThreadProc(int socket, sockaddr_in address) {  }
  int Main() {
 +  std::thread output_thread(OutputThread);
 +
    int server_socket;
    if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
 @@ -84,7 +86,10 @@ int Main() {      unsigned sin_size = sizeof(sockaddr_in);
      client_socket =
          accept(server_socket, reinterpret_cast<sockaddr *>(&client_address),
 -               &sin_size);
 +#ifdef WIN32
 +               reinterpret_cast<int *>
 +#endif
 +               (&sin_size));
      if (client_socket == -1) {
        PrintErrorMessageAndExit(CRUT("Failed to accecpt"));
 | 
