Skip to content

Commit

Permalink
*: Split enums in headers
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Jan 11, 2024
1 parent a51bc73 commit 475ff77
Show file tree
Hide file tree
Showing 64 changed files with 649 additions and 364 deletions.
25 changes: 14 additions & 11 deletions example/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../poseidon/precompiled.ipp"
#include "../poseidon/easy/easy_http_client.hpp"
#include "../poseidon/easy/easy_timer.hpp"
#include "../poseidon/easy/enums.hpp"
#include "../poseidon/utils.hpp"
namespace {
using namespace ::poseidon;
Expand All @@ -12,35 +13,37 @@ extern Easy_HTTP_Client my_client;
extern Easy_Timer my_timer;

void
event_callback(shptrR<HTTP_Client_Session> session, Abstract_Fiber& /*fiber*/, Easy_Socket_Event event, HTTP_Response_Headers&& resp, linear_buffer&& data)
event_callback(shptrR<HTTP_Client_Session> session, Abstract_Fiber& /*fiber*/,
Easy_HTTP_Event event, HTTP_Response_Headers&& resp, linear_buffer&& data)
{
switch(event) {
case easy_socket_msg_bin: {
POSEIDON_LOG_ERROR(("HTTP client received response from `$1`: $2 $3"),
session->remote_address(), resp.status, resp.reason);
case easy_http_open:
POSEIDON_LOG_ERROR(("example HTTP client connected to server: $1"),
session->remote_address());
break;

case easy_http_message: {
POSEIDON_LOG_ERROR(("example HTTP client received response: $1 $2"),
resp.status, resp.reason);
for(const auto& pair : resp.headers)
POSEIDON_LOG_ERROR((" $1 --> $2"), pair.first, pair.second);

POSEIDON_LOG_ERROR((" payload ($1 bytes):\n$2"), data.size(), data);
break;
}

case easy_socket_close:
POSEIDON_LOG_ERROR(("example HTTP client shut down connection: $1"), data);
case easy_http_close:
POSEIDON_LOG_ERROR(("example HTTP client shutdown: $1"), data);
break;

case easy_socket_open:
case easy_socket_stream:
case easy_socket_msg_text:
case easy_socket_pong:
default:
ASTERIA_TERMINATE(("shouldn't happen: event = $1"), event);
}
}

void
timer_callback(shptrR<Abstract_Timer> /*timer*/, Abstract_Fiber& /*fiber*/, steady_time /*now*/)
timer_callback(shptrR<Abstract_Timer> /*timer*/, Abstract_Fiber& /*fiber*/,
steady_time /*now*/)
{
static uint32_t state;

Expand Down
26 changes: 16 additions & 10 deletions example/http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@

#include "../poseidon/precompiled.ipp"
#include "../poseidon/easy/easy_http_server.hpp"
#include "../poseidon/easy/enums.hpp"
#include "../poseidon/utils.hpp"
namespace {
using namespace ::poseidon;

extern Easy_HTTP_Server my_server;

void
event_callback(shptrR<HTTP_Server_Session> session, Abstract_Fiber& /*fiber*/, Easy_Socket_Event event, HTTP_Request_Headers&& req, linear_buffer&& data)
event_callback(shptrR<HTTP_Server_Session> session, Abstract_Fiber& /*fiber*/,
Easy_HTTP_Event event, HTTP_Request_Headers&& req, linear_buffer&& data)
{
switch(event) {
case easy_socket_msg_bin: {
POSEIDON_LOG_ERROR(("HTTP request --> $1 $2: $3"), req.method, req.uri_path, req.uri_query);
case easy_http_open:
POSEIDON_LOG_ERROR(("example HTTP server accepted connection: $1"),
session->remote_address());
break;

case easy_http_message: {
POSEIDON_LOG_ERROR(("HTTP request --> $1 $2: $3"),
req.method, req.uri_path, req.uri_query);
for(const auto& r : req.headers)
POSEIDON_LOG_ERROR(("HTTP header --> $1: $2"), r.first, r.second);

// send a response
HTTP_Response_Headers resp;
resp.status = 200;
resp.headers.emplace_back(sref("Date"), system_clock::now());
Expand All @@ -30,14 +39,10 @@ event_callback(shptrR<HTTP_Server_Session> session, Abstract_Fiber& /*fiber*/, E
break;
}

case easy_socket_close:
POSEIDON_LOG_ERROR(("example HTTP server shut down connection: $1"), data);
case easy_http_close:
POSEIDON_LOG_ERROR(("example HTTP server shutdown: $1"), data);
break;

case easy_socket_open:
case easy_socket_stream:
case easy_socket_msg_text:
case easy_socket_pong:
default:
ASTERIA_TERMINATE(("shouldn't happen: event = $1"), event);
}
Expand All @@ -47,7 +52,8 @@ int
start_server()
{
my_server.start(sref("[::]:3804"));
POSEIDON_LOG_ERROR(("example HTTP server started: bind = $1"), my_server.local_address());
POSEIDON_LOG_ERROR(("example HTTP server started: bind = $1"),
my_server.local_address());
return 0;
}

Expand Down
25 changes: 14 additions & 11 deletions example/https_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../poseidon/precompiled.ipp"
#include "../poseidon/easy/easy_https_client.hpp"
#include "../poseidon/easy/easy_timer.hpp"
#include "../poseidon/easy/enums.hpp"
#include "../poseidon/utils.hpp"
namespace {
using namespace ::poseidon;
Expand All @@ -12,35 +13,37 @@ extern Easy_HTTPS_Client my_client;
extern Easy_Timer my_timer;

void
event_callback(shptrR<HTTPS_Client_Session> session, Abstract_Fiber& /*fiber*/, Easy_Socket_Event event, HTTP_Response_Headers&& resp, linear_buffer&& data)
event_callback(shptrR<HTTPS_Client_Session> session, Abstract_Fiber& /*fiber*/,
Easy_HTTP_Event event, HTTP_Response_Headers&& resp, linear_buffer&& data)
{
switch(event) {
case easy_socket_msg_bin: {
POSEIDON_LOG_WARN(("HTTPS client received response from `$1`: $2 $3"),
session->remote_address(), resp.status, resp.reason);
case easy_http_open:
POSEIDON_LOG_WARN(("example HTTPS client connected to server: $1"),
session->remote_address());
break;

case easy_http_message: {
POSEIDON_LOG_WARN(("example HTTPS client received response: $1 $2"),
resp.status, resp.reason);
for(const auto& pair : resp.headers)
POSEIDON_LOG_WARN((" $1 --> $2"), pair.first, pair.second);

POSEIDON_LOG_WARN((" payload ($1 bytes):\n$2"), data.size(), data);
break;
}

case easy_socket_close:
POSEIDON_LOG_WARN(("example HTTPS client shut down connection: $1"), data);
case easy_http_close:
POSEIDON_LOG_WARN(("example HTTPS client shutdown: $1"), data);
break;

case easy_socket_open:
case easy_socket_stream:
case easy_socket_msg_text:
case easy_socket_pong:
default:
ASTERIA_TERMINATE(("shouldn't happen: event = $1"), event);
}
}

void
timer_callback(shptrR<Abstract_Timer> /*timer*/, Abstract_Fiber& /*fiber*/, steady_time /*now*/)
timer_callback(shptrR<Abstract_Timer> /*timer*/, Abstract_Fiber& /*fiber*/,
steady_time /*now*/)
{
static uint32_t state;

Expand Down
24 changes: 15 additions & 9 deletions example/https_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,30 @@

#include "../poseidon/precompiled.ipp"
#include "../poseidon/easy/easy_https_server.hpp"
#include "../poseidon/easy/enums.hpp"
#include "../poseidon/utils.hpp"
namespace {
using namespace ::poseidon;

extern Easy_HTTPS_Server my_server;

void
event_callback(shptrR<HTTPS_Server_Session> session, Abstract_Fiber& /*fiber*/, Easy_Socket_Event event,HTTP_Request_Headers&& req, linear_buffer&& data)
event_callback(shptrR<HTTPS_Server_Session> session, Abstract_Fiber& /*fiber*/,
Easy_HTTP_Event event,HTTP_Request_Headers&& req, linear_buffer&& data)
{
switch(event) {
case easy_socket_msg_bin: {
POSEIDON_LOG_WARN(("HTTPS request --> $1 $2: $3"), req.method, req.uri_path, req.uri_query);
case easy_http_open:
POSEIDON_LOG_WARN(("example HTTPS server accepted connection: $1"),
session->remote_address());
break;

case easy_http_message: {
POSEIDON_LOG_WARN(("HTTPS request --> $1 $2: $3"),
req.method, req.uri_path, req.uri_query);
for(const auto& r : req.headers)
POSEIDON_LOG_WARN(("HTTPS header --> $1: $2"), r.first, r.second);

// send a response
HTTP_Response_Headers resp;
resp.status = 200;
resp.headers.emplace_back(sref("Date"), system_clock::now());
Expand All @@ -30,14 +39,10 @@ event_callback(shptrR<HTTPS_Server_Session> session, Abstract_Fiber& /*fiber*/,
break;
}

case easy_socket_close:
case easy_http_close:
POSEIDON_LOG_WARN(("example HTTPS server shut down connection: $1"), data);
break;

case easy_socket_open:
case easy_socket_stream:
case easy_socket_msg_text:
case easy_socket_pong:
default:
ASTERIA_TERMINATE(("shouldn't happen: event = $1"), event);
}
Expand All @@ -47,7 +52,8 @@ int
start_server()
{
my_server.start(sref("[::]:3805"));
POSEIDON_LOG_WARN(("example HTTPS server started: bind = $1"), my_server.local_address());
POSEIDON_LOG_WARN(("example HTTPS server started: bind = $1"),
my_server.local_address());
return 0;
}

Expand Down
25 changes: 14 additions & 11 deletions example/ssl_echo_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@

#include "../poseidon/precompiled.ipp"
#include "../poseidon/easy/easy_ssl_server.hpp"
#include "../poseidon/easy/enums.hpp"
#include "../poseidon/utils.hpp"
namespace {
using namespace ::poseidon;

extern Easy_SSL_Server my_server;

void
event_callback(shptrR<SSL_Socket> socket, Abstract_Fiber& /*fiber*/, Easy_Socket_Event event, linear_buffer& data, int code)
event_callback(shptrR<SSL_Socket> socket, Abstract_Fiber& /*fiber*/,
Easy_Stream_Event event, linear_buffer& data, int code)
{
switch(event) {
case easy_socket_open:
POSEIDON_LOG_WARN(("example SSL server accepted connection: $1"), socket->remote_address());
case easy_stream_open:
POSEIDON_LOG_WARN(("example SSL server accepted connection: $1"),
socket->remote_address());
break;

case easy_socket_stream:
POSEIDON_LOG_WARN(("example SSL server received data (eof = $1): $2"), code, data);
case easy_stream_data:
POSEIDON_LOG_WARN(("example SSL server received data (eof = $1): $2"),
code, data);
socket->ssl_send(data);
data.clear();
break;

case easy_socket_close:
POSEIDON_LOG_WARN(("example SSL server shut down connection: (errno = $1) $2"), code, data);
case easy_stream_close:
POSEIDON_LOG_WARN(("example SSL server shutdown: (errno = $1) $2"),
code, data);
break;

case easy_socket_msg_text:
case easy_socket_msg_bin:
case easy_socket_pong:
default:
ASTERIA_TERMINATE(("shouldn't happen: event = $1"), event);
}
Expand All @@ -39,7 +41,8 @@ int
start_server()
{
my_server.start(sref("[::]:3803"));
POSEIDON_LOG_WARN(("example SSL server started: bind = $1"), my_server.local_address());
POSEIDON_LOG_WARN(("example SSL server started: bind = $1"),
my_server.local_address());
return 0;
}

Expand Down
25 changes: 14 additions & 11 deletions example/tcp_echo_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@

#include "../poseidon/precompiled.ipp"
#include "../poseidon/easy/easy_tcp_server.hpp"
#include "../poseidon/easy/enums.hpp"
#include "../poseidon/utils.hpp"
namespace {
using namespace ::poseidon;

extern Easy_TCP_Server my_server;

void
event_callback(shptrR<TCP_Socket> socket, Abstract_Fiber& /*fiber*/, Easy_Socket_Event event, linear_buffer& data, int code)
event_callback(shptrR<TCP_Socket> socket, Abstract_Fiber& /*fiber*/,
Easy_Stream_Event event, linear_buffer& data, int code)
{
switch(event) {
case easy_socket_open:
POSEIDON_LOG_ERROR(("example SSL server accepted connection: $1"), socket->remote_address());
case easy_stream_open:
POSEIDON_LOG_ERROR(("example SSL server accepted connection: $1"),
socket->remote_address());
break;

case easy_socket_stream:
POSEIDON_LOG_ERROR(("example SSL server received data (eof = $1): $2"), code, data);
case easy_stream_data:
POSEIDON_LOG_ERROR(("example SSL server received data (eof = $1): $2"),
code, data);
socket->tcp_send(data);
data.clear();
break;

case easy_socket_close:
POSEIDON_LOG_ERROR(("example SSL server shut down connection: (errno = $1) $2"), code, data);
case easy_stream_close:
POSEIDON_LOG_ERROR(("example SSL server shutdown: (errno = $1) $2"),
code, data);
break;

case easy_socket_msg_text:
case easy_socket_msg_bin:
case easy_socket_pong:
default:
ASTERIA_TERMINATE(("shouldn't happen: event = $1"), event);
}
Expand All @@ -39,7 +41,8 @@ int
start_server()
{
my_server.start(sref("[::]:3802"));
POSEIDON_LOG_ERROR(("example TCP server started: bind = $1"), my_server.local_address());
POSEIDON_LOG_ERROR(("example TCP server started: bind = $1"),
my_server.local_address());
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion example/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ using namespace ::poseidon;
extern Easy_Timer my_timer;

void
timer_callback(shptrR<Abstract_Timer> /*timer*/, Abstract_Fiber& /*fiber*/, steady_time now)
timer_callback(shptrR<Abstract_Timer> /*timer*/, Abstract_Fiber& /*fiber*/,
steady_time now)
{
POSEIDON_LOG_WARN(("example timer: now = $1"), now.time_since_epoch());
}
Expand Down
Loading

0 comments on commit 475ff77

Please sign in to comment.