send can fail silently when sending would block (EWOULDBLOCK return for send) (#18)

* try to use a pipe for communication

* flush send buffer on the background thread

* cleanup

* linux fix / linux still use event fd for now

* cleanup
This commit is contained in:
Benjamin Sergeant
2019-03-13 23:09:45 -07:00
committed by GitHub
parent d6597d9f52
commit 2750df8aa7
19 changed files with 277 additions and 115 deletions

View File

@ -51,6 +51,7 @@ int main(int argc, char** argv)
CLI::App* transferApp = app.add_subcommand("transfer", "Broadcasting server");
transferApp->add_option("--port", port, "Connection url");
transferApp->add_option("--host", hostname, "Hostname");
CLI::App* connectApp = app.add_subcommand("connect", "Connect to a remote server");
connectApp->add_option("url", url, "Connection url")->required();
@ -60,11 +61,12 @@ int main(int argc, char** argv)
chatApp->add_option("user", user, "User name")->required();
CLI::App* echoServerApp = app.add_subcommand("echo_server", "Echo server");
echoServerApp->add_option("--port", port, "Connection url");
echoServerApp->add_option("--port", port, "Port");
echoServerApp->add_option("--host", hostname, "Hostname");
CLI::App* broadcastServerApp = app.add_subcommand("broadcast_server", "Broadcasting server");
broadcastServerApp->add_option("--port", port, "Connection url");
broadcastServerApp->add_option("--hostname", hostname, "Hostname");
broadcastServerApp->add_option("--port", port, "Port");
broadcastServerApp->add_option("--host", hostname, "Hostname");
CLI::App* pingPongApp = app.add_subcommand("ping", "Ping pong");
pingPongApp->add_option("url", url, "Connection url")->required();
@ -90,7 +92,7 @@ int main(int argc, char** argv)
if (app.got_subcommand("transfer"))
{
return ix::ws_transfer_main(port);
return ix::ws_transfer_main(port, hostname);
}
else if (app.got_subcommand("send"))
{
@ -111,7 +113,7 @@ int main(int argc, char** argv)
}
else if (app.got_subcommand("echo_server"))
{
return ix::ws_echo_server_main(port);
return ix::ws_echo_server_main(port, hostname);
}
else if (app.got_subcommand("broadcast_server"))
{

View File

@ -24,9 +24,9 @@ namespace ix
int ws_ping_pong_main(const std::string& url);
int ws_echo_server_main(int port);
int ws_echo_server_main(int port, const std::string& hostname);
int ws_broadcast_server_main(int port, const std::string& hostname);
int ws_transfer_main(int port, const std::string& hostname);
int ws_chat_main(const std::string& url,
const std::string& user);
@ -36,8 +36,6 @@ namespace ix
int ws_receive_main(const std::string& url,
bool enablePerMessageDeflate);
int ws_transfer_main(int port);
int ws_send_main(const std::string& url,
const std::string& path);
}

View File

@ -71,6 +71,15 @@ namespace ix
<< " out of " << total << std::endl;
return true;
});
do
{
size_t bufferedAmount = client->bufferedAmount();
std::cerr << bufferedAmount << " bytes left to be sent" << std::endl;
std::chrono::duration<double, std::milli> duration(10);
std::this_thread::sleep_for(duration);
} while (client->bufferedAmount() != 0);
}
}
}

View File

@ -10,11 +10,11 @@
namespace ix
{
int ws_echo_server_main(int port)
int ws_echo_server_main(int port, const std::string& hostname)
{
std::cout << "Listening on port " << port << std::endl;
std::cout << "Listening on " << hostname << ":" << port << std::endl;
ix::WebSocketServer server(port);
ix::WebSocketServer server(port, hostname);
server.setOnConnectionCallback(
[](std::shared_ptr<ix::WebSocket> webSocket)

View File

@ -257,6 +257,15 @@ namespace ix
return true;
});
do
{
size_t bufferedAmount = _webSocket.bufferedAmount();
std::cout << bufferedAmount << " bytes left to be sent" << std::endl;
std::chrono::duration<double, std::milli> duration(10);
std::this_thread::sleep_for(duration);
} while (_webSocket.bufferedAmount() != 0);
bench.report();
auto duration = bench.getDuration();
auto transferRate = 1000 * content.size() / duration;

View File

@ -10,11 +10,11 @@
namespace ix
{
int ws_transfer_main(int port)
int ws_transfer_main(int port, const std::string& hostname)
{
std::cout << "Listening on port " << port << std::endl;
std::cout << "Listening on " << hostname << ":" << port << std::endl;
ix::WebSocketServer server(port);
ix::WebSocketServer server(port, hostname);
server.setOnConnectionCallback(
[&server](std::shared_ptr<ix::WebSocket> webSocket)
@ -70,6 +70,15 @@ namespace ix
<< " out of " << total << std::endl;
return true;
});
do
{
size_t bufferedAmount = client->bufferedAmount();
std::cerr << bufferedAmount << " bytes left to be sent" << std::endl;
std::chrono::duration<double, std::milli> duration(10);
std::this_thread::sleep_for(duration);
} while (client->bufferedAmount() != 0);
}
}
}