Skip to content
Draft
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
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ if(LIBCORO_FEATURE_NETWORKING)
include/coro/net/connect.hpp src/net/connect.cpp
include/coro/net/hostname.hpp
include/coro/net/ip_address.hpp src/net/ip_address.cpp
include/coro/net/recv_status.hpp src/net/recv_status.cpp
include/coro/net/send_status.hpp src/net/send_status.cpp
include/coro/net/io_status.hpp src/net/io_status.cpp
include/coro/net/socket.hpp src/net/socket.cpp
include/coro/net/tcp/client.hpp src/net/tcp/client.cpp
include/coro/net/tcp/server.hpp src/net/tcp/server.cpp
Expand Down
424 changes: 278 additions & 146 deletions README.md

Large diffs are not rendered by default.

19 changes: 6 additions & 13 deletions examples/coro_tcp_echo_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,11 @@ auto main() -> int
// Wait for data to be available to read.
co_await client.poll(coro::poll_op::read);
auto [rstatus, rspan] = client.recv(buf);
switch (rstatus)
{
case coro::net::recv_status::ok:
// Make sure the client socket can be written to.
co_await client.poll(coro::poll_op::write);
client.send(std::span<const char>{rspan});
break;
case coro::net::recv_status::would_block:
break;
case coro::net::recv_status::closed:
default:
co_return;
if (rstatus.is_ok()) {
co_await client.poll(coro::poll_op::write);
client.send(std::span<const char>{rspan});
} else if (rstatus.is_closed()) {
co_return;
}
}
};
Expand All @@ -40,7 +33,7 @@ auto main() -> int
{
case coro::poll_status::read:
{
auto client = server.accept();
auto client = server.accept_now();
if (client.socket().is_valid())
{
scheduler->spawn_detached(make_on_connection_task(std::move(client)));
Expand Down
3 changes: 1 addition & 2 deletions include/coro/coro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#include "coro/net/connect.hpp"
#include "coro/net/hostname.hpp"
#include "coro/net/ip_address.hpp"
#include "coro/net/recv_status.hpp"
#include "coro/net/send_status.hpp"
#include "coro/net/io_status.hpp"
#include "coro/net/socket.hpp"
#include "coro/net/udp/peer.hpp"
#endif
Expand Down
50 changes: 50 additions & 0 deletions include/coro/net/io_status.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once

#include "coro/poll.hpp"
#include <cstddef>
#include <string>

namespace coro::net
{

struct io_status
{
enum class kind
{
ok,
closed,
connection_reset,
connection_refused,
timeout,

would_block_or_try_again,
polling_error,
cancelled,

udp_not_bound,
message_to_big,

native
};

kind type{};
int native_code{};

[[nodiscard]] auto is_ok() const -> bool { return type == kind::ok; }
[[nodiscard]] auto is_timeout() const -> bool { return type == kind::timeout; }
[[nodiscard]] auto is_closed() const -> bool { return type == kind::closed; }
[[nodiscard]] auto would_block() const -> bool { return type == kind::would_block_or_try_again; }

[[nodiscard]] auto is_native() const -> bool { return type == kind::native; }

explicit operator bool() const { return is_ok(); }

/**
* Returns a human-readable description of the error.
*/
[[nodiscard]] auto message() const -> std::string;
};

auto make_io_status_from_native(int native_code) -> io_status;
auto make_io_status_from_poll_status(coro::poll_status status) -> io_status;
} // namespace coro::net
32 changes: 0 additions & 32 deletions include/coro/net/recv_status.hpp

This file was deleted.

31 changes: 0 additions & 31 deletions include/coro/net/send_status.hpp

This file was deleted.

Loading
Loading