mirror of
https://github.com/vlang/v.git
synced 2025-09-19 12:27:02 -04:00
picoev: support -d picoev_verbose_errors
, do not use any naked eprintln
by default, since that is a low level module
This commit is contained in:
parent
45cbf4f14e
commit
3939737a8d
6
vlib/picoev/errors.v
Normal file
6
vlib/picoev/errors.v
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
module picoev
|
||||||
|
|
||||||
|
@[if picoev_verbose_errors ?]
|
||||||
|
fn elog(msg string) {
|
||||||
|
eprintln(msg)
|
||||||
|
}
|
@ -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.update_events(fd, events | picoev_add) != 0 {
|
||||||
if pv.delete(fd) != 0 {
|
if pv.delete(fd) != 0 {
|
||||||
eprintln('Error during del')
|
elog('Error during del')
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1
|
return -1
|
||||||
@ -143,7 +143,7 @@ pub fn (mut pv Picoev) delete(fd int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pv.update_events(fd, picoev_del) != 0 {
|
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
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ fn (mut pv Picoev) loop_once(max_wait_in_sec int) int {
|
|||||||
pv.loop.now = get_time()
|
pv.loop.now = get_time()
|
||||||
|
|
||||||
if pv.poll_once(max_wait_in_sec) != 0 {
|
if pv.poll_once(max_wait_in_sec) != 0 {
|
||||||
eprintln('Error during poll_once')
|
elog('Error during poll_once')
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln('Error during accept')
|
elog('Error during accept')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_sock(accepted_fd) or {
|
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{},
|
pv.error_callback(pv.user_data, picohttpparser.Request{}, mut &picohttpparser.Response{},
|
||||||
err)
|
err)
|
||||||
close_socket(accepted_fd) // Close fd on failure
|
close_socket(accepted_fd) // Close fd on failure
|
||||||
@ -244,7 +244,7 @@ fn accept_callback(listen_fd int, events int, cb_arg voidptr) {
|
|||||||
@[inline]
|
@[inline]
|
||||||
pub fn (mut pv Picoev) close_conn(fd int) {
|
pub fn (mut pv Picoev) close_conn(fd int) {
|
||||||
if pv.delete(fd) != 0 {
|
if pv.delete(fd) != 0 {
|
||||||
eprintln('Error during del')
|
elog('Error during del')
|
||||||
}
|
}
|
||||||
close_socket(fd)
|
close_socket(fd)
|
||||||
}
|
}
|
||||||
@ -306,7 +306,7 @@ fn raw_callback(fd int, events int, context voidptr) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
eprintln('Error during req_read')
|
elog('Error during req_read')
|
||||||
|
|
||||||
// fatal error
|
// fatal error
|
||||||
pv.close_conn(fd)
|
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) {
|
fn default_error_callback(data voidptr, req picohttpparser.Request, mut res picohttpparser.Response, error IError) {
|
||||||
eprintln('picoev: ${error}')
|
elog('picoev: ${error}')
|
||||||
res.end()
|
res.end()
|
||||||
}
|
}
|
||||||
|
|
||||||
// new creates a `Picoev` struct and initializes the main loop
|
// new creates a `Picoev` struct and initializes the main loop
|
||||||
pub fn new(config Config) !&Picoev {
|
pub fn new(config Config) !&Picoev {
|
||||||
listening_socket_fd := listen(config) or {
|
listening_socket_fd := listen(config) or {
|
||||||
eprintln('Error during listen: ${err}')
|
elog('Error during listen: ${err}')
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +384,7 @@ pub fn new(config Config) !&Picoev {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if pv.loop == unsafe { nil } {
|
if pv.loop == unsafe { nil } {
|
||||||
eprintln('Failed to create loop')
|
elog('Failed to create loop')
|
||||||
close_socket(listening_socket_fd)
|
close_socket(listening_socket_fd)
|
||||||
return unsafe { nil }
|
return unsafe { nil }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user