diff --git a/vlib/picoev/errors.v b/vlib/picoev/errors.v new file mode 100644 index 00000000000000..dae7c451ac6d44 --- /dev/null +++ b/vlib/picoev/errors.v @@ -0,0 +1,6 @@ +module picoev + +@[if picoev_verbose_errors ?] +fn elog(msg string) { + eprintln(msg) +} diff --git a/vlib/picoev/picoev.v b/vlib/picoev/picoev.v index 717124f4ceec63..08c4d230bbfd16 100644 --- a/vlib/picoev/picoev.v +++ b/vlib/picoev/picoev.v @@ -112,7 +112,7 @@ pub fn (mut pv Picoev) add(fd int, events int, timeout int, callback voidptr) in if pv.update_events(fd, events | picoev_add) != 0 { if pv.delete(fd) != 0 { - eprintln('Error during del') + elog('Error during del') } return -1 @@ -143,7 +143,7 @@ pub fn (mut pv Picoev) delete(fd int) int { } if pv.update_events(fd, picoev_del) != 0 { - eprintln('Error during update_events. event: `picoev.picoev_del`') + elog('Error during update_events. event: `picoev.picoev_del`') return -1 } @@ -158,7 +158,7 @@ fn (mut pv Picoev) loop_once(max_wait_in_sec int) int { pv.loop.now = get_time() if pv.poll_once(max_wait_in_sec) != 0 { - eprintln('Error during poll_once') + elog('Error during poll_once') return -1 } @@ -216,7 +216,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) { return } - eprintln('Error during accept') + elog('Error during accept') return } @@ -231,7 +231,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) { } setup_sock(accepted_fd) or { - eprintln('setup_sock failed, fd: ${accepted_fd}, listen_fd: ${listen_fd}, err: ${err.code()}') + elog('setup_sock failed, fd: ${accepted_fd}, listen_fd: ${listen_fd}, err: ${err.code()}') pv.error_callback(pv.user_data, picohttpparser.Request{}, mut &picohttpparser.Response{}, err) close_socket(accepted_fd) // Close fd on failure @@ -244,7 +244,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) { @[inline] pub fn (mut pv Picoev) close_conn(fd int) { if pv.delete(fd) != 0 { - eprintln('Error during del') + elog('Error during del') } close_socket(fd) } @@ -306,7 +306,7 @@ fn raw_callback(fd int, events int, context voidptr) { return } - eprintln('Error during req_read') + elog('Error during req_read') // fatal error pv.close_conn(fd) @@ -344,14 +344,14 @@ fn raw_callback(fd int, events int, context voidptr) { } fn default_error_callback(data voidptr, req picohttpparser.Request, mut res picohttpparser.Response, error IError) { - eprintln('picoev: ${error}') + elog('picoev: ${error}') res.end() } // new creates a `Picoev` struct and initializes the main loop pub fn new(config Config) !&Picoev { listening_socket_fd := listen(config) or { - eprintln('Error during listen: ${err}') + elog('Error during listen: ${err}') return err } @@ -384,7 +384,7 @@ pub fn new(config Config) !&Picoev { } if pv.loop == unsafe { nil } { - eprintln('Failed to create loop') + elog('Failed to create loop') close_socket(listening_socket_fd) return unsafe { nil } }