Skip to content

Commit 507eacd

Browse files
committed
BREAKING CHANGE - change srv name to io and enforce namespace + minor fixes
1 parent 0580409 commit 507eacd

27 files changed

+8791
-8364
lines changed

examples/client.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ This program uses a single thread, which reduces complexity.
2020
#include "fio-stl/include.h"
2121

2222
/** Called When the client socket is attached to the server. */
23-
FIO_SFUNC void on_attach(fio_s *io);
23+
FIO_SFUNC void on_attach(fio_io_s *io);
2424
/** Called there's incoming data (from the server). */
25-
FIO_SFUNC void on_data(fio_s *io);
25+
FIO_SFUNC void on_data(fio_io_s *io);
2626
/** Called when the monitored IO is closed or has a fatal error. */
27-
FIO_SFUNC void on_close(void *udata);
27+
FIO_SFUNC void on_close(void *buf, void *udata);
2828

2929
/** Socket client protocol */
30-
static fio_protocol_s CLIENT_PROTOCOL = {
30+
static fio_io_protocol_s CLIENT_PROTOCOL = {
3131
.on_attach = on_attach,
3232
.on_data = on_data,
3333
.on_close = on_close,
@@ -56,14 +56,14 @@ FIO_SFUNC void client_on_finish(fio_http_s *h);
5656
FIO_SFUNC void client_on_ready(fio_http_s *h);
5757

5858
/** Called there's incoming data from STDIN. */
59-
FIO_SFUNC void on_input(fio_s *io);
59+
FIO_SFUNC void on_input(fio_io_s *io);
6060
/** Called when STDIN closed. */
61-
FIO_SFUNC void on_input_closed(void *udata);
61+
FIO_SFUNC void on_input_closed(void *buf, void *udata);
6262
/** Called if connection failed to establish. */
63-
FIO_SFUNC void on_failed(fio_protocol_s *p, void *arg);
63+
FIO_SFUNC void on_failed(fio_io_protocol_s *p, void *arg);
6464

6565
/** STDIN protocol (REPL) */
66-
static fio_protocol_s STDIN_PROTOCOL = {
66+
static fio_io_protocol_s STDIN_PROTOCOL = {
6767
.on_data = on_input,
6868
.on_close = on_input_closed,
6969
};
@@ -134,7 +134,7 @@ int main(int argc, char const *argv[]) {
134134
/* set connection task in master process. */
135135
fio_state_callback_add(FIO_CALL_ON_START, open_client_connection, is_http);
136136
/* start server, connection termination will stop it. */
137-
fio_srv_start(0);
137+
fio_io_start(0);
138138
return 0;
139139
}
140140

@@ -161,10 +161,10 @@ FIO_SFUNC void open_client_connection(void *is_http) {
161161
} else {
162162
/* Raw TCP/IP / UDP Client */
163163
CLIENT_PROTOCOL.timeout = (fio_cli_get_i("-t") * 1000);
164-
FIO_ASSERT(fio_srv_connect(fio_cli_unnamed(0),
165-
.protocol = &CLIENT_PROTOCOL,
166-
.on_failed = on_failed,
167-
.timeout = (fio_cli_get_i("-w") * 1000)),
164+
FIO_ASSERT(fio_io_connect(fio_cli_unnamed(0),
165+
.protocol = &CLIENT_PROTOCOL,
166+
.on_failed = on_failed,
167+
.timeout = (fio_cli_get_i("-w") * 1000)),
168168
"Connection error!");
169169
}
170170
}
@@ -174,7 +174,7 @@ Input from STDIN - directed to the client's socket using pub/sub
174174
***************************************************************************** */
175175

176176
/** Called there's incoming data (from STDIN / the client socket). */
177-
FIO_SFUNC void on_input(fio_s *io) {
177+
FIO_SFUNC void on_input(fio_io_s *io) {
178178
struct {
179179
size_t len;
180180
char buf[4080];
@@ -192,10 +192,10 @@ FIO_SFUNC void on_input(fio_s *io) {
192192
}
193193

194194
/** Called when STDIN closed. */
195-
FIO_SFUNC void on_input_closed(void *udata) {
195+
FIO_SFUNC void on_input_closed(void *buf, void *udata) {
196196
FIO_LOG_DEBUG2("STDIN input stream closed.");
197-
fio_srv_stop();
198-
(void)udata;
197+
fio_io_stop();
198+
(void)buf, (void)udata;
199199
}
200200

201201
/* Debug messages for STDIN round-trip */
@@ -208,7 +208,7 @@ void debug_subscriber(fio_msg_s *msg) {
208208
/* Attach STDIN */
209209
FIO_SFUNC void attach_stdin(void) {
210210
FIO_LOG_DEBUG2("listening to user input on STDIN.");
211-
fio_srv_attach_fd(fileno(stdin), &STDIN_PROTOCOL, NULL, NULL);
211+
fio_io_attach_fd(fileno(stdin), &STDIN_PROTOCOL, NULL, NULL);
212212
if (fio_cli_get_bool("-V"))
213213
fio_subscribe(.channel = FIO_BUF_INFO1("client"),
214214
.on_message = debug_subscriber,
@@ -220,36 +220,36 @@ IO callback(s)
220220
***************************************************************************** */
221221

222222
/** Called When the client socket is attached to the server. */
223-
FIO_SFUNC void on_attach(fio_s *io) {
223+
FIO_SFUNC void on_attach(fio_io_s *io) {
224224
fio_subscribe(.io = io, .channel = FIO_BUF_INFO1("client"));
225-
fio_udata_set(io, (void *)1);
225+
fio_io_udata_set(io, (void *)1);
226226
FIO_LOG_DEBUG2("* connection established.\n");
227227
FIO_LOG_DEBUG2("Connected client IO to pub/sub");
228228
attach_stdin();
229229
}
230230
/** Called there's incoming data from the client socket. */
231-
FIO_SFUNC void on_data(fio_s *io) {
231+
FIO_SFUNC void on_data(fio_io_s *io) {
232232
FIO_LOG_DEBUG2("on_data callback called for: %p", io);
233233
char buf[4080];
234234
for (;;) { /* read until done */
235-
size_t l = fio_read(io, buf, 4080);
235+
size_t l = fio_io_read(io, buf, 4080);
236236
if (!l)
237237
return;
238238
fwrite(buf, 1, l, stdout); /* test for incomplete `write`? */
239239
}
240240
}
241241

242242
/** Called when the monitored IO is closed or has a fatal error. */
243-
FIO_SFUNC void on_close(void *arg) {
243+
FIO_SFUNC void on_close(void *buf, void *udata) {
244244
FIO_LOG_DEBUG2("Connection lost, shutting down client.");
245-
fio_srv_stop();
246-
(void)arg;
245+
fio_io_stop();
246+
(void)buf, (void)udata;
247247
}
248248

249249
/** Called if connection failed to establish. */
250-
FIO_SFUNC void on_failed(fio_protocol_s *p, void *arg) {
250+
FIO_SFUNC void on_failed(fio_io_protocol_s *p, void *arg) {
251251
FIO_LOG_ERROR("Connection failed / no data received: %s", fio_cli_unnamed(0));
252-
p->on_close(arg);
252+
p->on_close(arg, NULL);
253253
}
254254

255255
/* *****************************************************************************
@@ -287,7 +287,7 @@ FIO_SFUNC void client_on_http(fio_http_s *h) {
287287
printf("%.*s", (int)buf.len, buf.buf);
288288
}
289289

290-
fio_srv_stop();
290+
fio_io_stop();
291291
}
292292

293293
/** Called once a WebSocket / SSE connection upgrade is complete. */
@@ -335,13 +335,13 @@ FIO_SFUNC void client_on_eventsource(fio_http_s *h,
335335
FIO_SFUNC void client_on_finish(fio_http_s *h) {
336336
if (!fio_cli_get_bool("-b"))
337337
FIO_LOG_INFO("Connection Closed");
338-
fio_srv_stop();
338+
fio_io_stop();
339339
(void)h;
340340
}
341341

342342
/** Called for show. */
343343
FIO_SFUNC void client_on_ready(fio_http_s *h) {
344344
FIO_LOG_DEBUG2("ON_READY Called! %zu bytes in outgoing buffer.",
345-
fio_srv_backlog(fio_http_io(h)));
345+
fio_io_backlog(fio_http_io(h)));
346346
(void)h;
347347
}

examples/server.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Main
7777
***************************************************************************** */
7878

7979
int main(int argc, char const *argv[]) {
80-
static fio_srv_async_s http_queue; /* async queue for worker threads. */
80+
static fio_io_async_s http_queue; /* async queue for worker threads. */
8181

8282
/* setup CLI options */
8383
fio_cli_start(
@@ -162,18 +162,18 @@ int main(int argc, char const *argv[]) {
162162
}
163163

164164
/* Debug data: print type sizes */
165-
FIO_LOG_DEBUG2("IO overhead: %zu bytes", sizeof(fio_s) + 8);
165+
FIO_LOG_DEBUG2("IO overhead: %zu bytes", sizeof(fio_io_s) + 8);
166166
FIO_LOG_DEBUG2("HTTP connection overhead: %zu bytes state + %zu bytes buffer",
167167
sizeof(fio___http_connection_s) + 8,
168168
FIO_HTTP_DEFAULT_MAX_LINE_LEN);
169169
FIO_LOG_DEBUG2("HTTP handle overhead: %zu", sizeof(fio_http_s) + 8);
170170
FIO_LOG_DEBUG2("Total HTTP overhead: %zu+%zu bytes",
171-
sizeof(fio_s) + sizeof(fio___http_connection_s) +
171+
sizeof(fio_io_s) + sizeof(fio___http_connection_s) +
172172
sizeof(fio_http_s) + 24,
173173
FIO_HTTP_DEFAULT_MAX_LINE_LEN);
174174

175175
/* initialize Async HTTP queue */
176-
fio_srv_async_init(&http_queue, fio_srv_workers(fio_cli_get_i("-t")));
176+
fio_io_async_attach(&http_queue, fio_io_workers(fio_cli_get_i("-t")));
177177

178178
/* Clustering */
179179
if (fio_cli_get_i("-bp") > 0) {
@@ -183,19 +183,19 @@ int main(int argc, char const *argv[]) {
183183
}
184184

185185
/* Test for TLS */
186-
fio_tls_s *tls = (fio_cli_get("--tls-cert") && fio_cli_get("--tls-key"))
187-
? fio_tls_cert_add(fio_tls_new(),
188-
fio_cli_get("--tls-name"),
189-
fio_cli_get("--tls-cert"),
190-
fio_cli_get("--tls-key"),
191-
fio_cli_get("-tls-pass"))
192-
: fio_cli_get("-tls")
193-
? fio_tls_cert_add(fio_tls_new(),
194-
fio_cli_get("-tls-name"),
195-
NULL,
196-
NULL,
197-
NULL)
198-
: NULL;
186+
fio_io_tls_s *tls = (fio_cli_get("--tls-cert") && fio_cli_get("--tls-key"))
187+
? fio_io_tls_cert_add(fio_io_tls_new(),
188+
fio_cli_get("--tls-name"),
189+
fio_cli_get("--tls-cert"),
190+
fio_cli_get("--tls-key"),
191+
fio_cli_get("-tls-pass"))
192+
: fio_cli_get("-tls")
193+
? fio_io_tls_cert_add(fio_io_tls_new(),
194+
fio_cli_get("-tls-name"),
195+
NULL,
196+
NULL,
197+
NULL)
198+
: NULL;
199199
/* support -b and -p for when a URL isn't provided */
200200
if (!fio_cli_get("-b"))
201201
fio_cli_set(fio_cli_get("-b"), fio_cli_unnamed(0));
@@ -251,19 +251,19 @@ int main(int argc, char const *argv[]) {
251251
.log = fio_cli_get_bool("-v")),
252252
"Could not open listening socket as requested.");
253253
/* we don't need the tls object any more. */
254-
fio_tls_free(tls);
254+
fio_io_tls_free(tls);
255255

256-
FIO_LOG_INFO("\n\tStarting HTTP echo server example app."
257-
"\n\tEngine: " FIO_POLL_ENGINE_STR "\n\tWorkers: %d\t(%s)"
258-
"\n\tThreads: 1+%d\t(per worker)"
259-
"\n\tPress ^C to exit.",
260-
fio_srv_workers(fio_cli_get_i("-w")),
261-
(fio_srv_workers(fio_cli_get_i("-w")) ? "cluster mode"
262-
: "single process"),
263-
(int)http_queue.count);
256+
FIO_LOG_INFO(
257+
"\n\tStarting HTTP echo server example app."
258+
"\n\tEngine: " FIO_POLL_ENGINE_STR "\n\tWorkers: %d\t(%s)"
259+
"\n\tThreads: 1+%d\t(per worker)"
260+
"\n\tPress ^C to exit.",
261+
fio_io_workers(fio_cli_get_i("-w")),
262+
(fio_io_workers(fio_cli_get_i("-w")) ? "cluster mode" : "single process"),
263+
(int)http_queue.count);
264264

265265
/* start server reactor */
266-
fio_srv_start(fio_cli_get_i("-w"));
266+
fio_io_start(fio_cli_get_i("-w"));
267267

268268
/* shutdown starts here */
269269
FIO_LOG_INFO("Shutdown complete.");
@@ -325,12 +325,12 @@ static void http_respond(fio_http_s *h) {
325325
FIO_STRING_WRITE_STR2(body.buf, body.len),
326326
FIO_STRING_WRITE_STR2("\r\n", 2));
327327
}
328-
/* fio_env_set(io, ...) example */
328+
/* fio_io_env_set(io, ...) example */
329329
if (0) {
330-
fio_env_set(fio_http_io(h),
331-
.name = FIO_BUF_INFO2("my key", 6),
332-
.udata = fio_bstr_write(NULL, "my env data", 11),
333-
.on_close = (void (*)(void *))fio_bstr_free);
330+
fio_io_env_set(fio_http_io(h),
331+
.name = FIO_BUF_INFO2("my key", 6),
332+
.udata = fio_bstr_write(NULL, "my env data", 11),
333+
.on_close = (void (*)(void *))fio_bstr_free);
334334
}
335335
/* ETag header example */
336336
if (1) {
@@ -348,22 +348,22 @@ static void http_respond(fio_http_s *h) {
348348
.dealloc = (void (*)(void *))fio_bstr_free,
349349
.copy = 0,
350350
.finish = 1);
351-
#else
351+
#else /* HTTP_RESPONSE_ECHO */
352352
fio_http_write(h, .buf = "Hello World!", .len = 12, .finish = 1);
353-
#endif
353+
#endif /* HTTP_RESPONSE_ECHO */
354354
}
355355

356356
/* *****************************************************************************
357357
Pub/Sub Logger / Recorder
358358
***************************************************************************** */
359359
#if 0
360360
FIO_SFUNC void logger_detached(const fio_pubsub_engine_s *eng) {
361-
FIO_LOG_INFO("%d (logger) detached", fio_srv_pid());
361+
FIO_LOG_INFO("%d (logger) detached", fio_io_pid());
362362
(void)eng;
363363
}
364364
FIO_SFUNC void logger_on_msg(fio_msg_s *msg) {
365365
FIO_LOG_INFO("%d (logger) pub/sub message for %s (%d):\n%s",
366-
fio_srv_pid(),
366+
fio_io_pid(),
367367
(msg->channel.len ? msg->channel.buf : "<null>"),
368368
(int)msg->filter,
369369
(msg->message.len ? msg->message.buf : "<null>"));

0 commit comments

Comments
 (0)