@@ -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);
5656FIO_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 */
209209FIO_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,
335335FIO_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. */
343343FIO_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}
0 commit comments