There are cases where a handler that returns a json element needs to
return a successfull empty response. This is common in async operation.
Though it is legit to return an empty string in this situation, it is
cleaner to return an empty response.
This adds a json_void class, that a method that needs to return a value
(i.e. the json_function) can return and the formatter will set the
response to empty.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This patch adds a general assignment operator to the json_list object.
It can accept any data structure that support const range iteration and
that its contained object can be assigned to the json_list object.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
The connection reset code posted an exception on the _data_received promise
to break a waiter (if any), but left the optional<promise<>> engaged. This
caused the connection destructor to attempt to post a new exception on the
same promise, which is not legal.
Fix by disengaging the optional promise, and give the same treatment to
_all_data_acked_promise.
Often a single file is used in multiple fibers, and so it is wrapped in a
lw_shared_ptr. Remove the need for this by making files internally reference
counted.
Often, when we create a directory, it is useful to make sure that the path
leading to it exists.
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
file_data_source_impl always calls file::size(), which can be slow. This
slows down applications that create many short-lived input streams on the
same file (for random-access processing of a subset of the data).
Fix by not calling size(), and letting the file code handle short reads
itself.
Our debugging builds always produce the annoying false warning like:
==1199==ERROR: AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) on 0x62300003d500
This error could be silenced by setting ASAN_OPTIONS=alloc_dealloc_mismatch=0
(and we do this in test.py), but it's still annoying for manual runs, and
can mask real bugs of this type.
The problem appears to be that the address sanitizer doesn't understand
our new(with_align(..)) trick we used to allocate the reactor object,
and when we eventually use ordinary "delete" on this object, it thinks
we mixed malloc and delete.
This patch uses posix_memalign() and free() to allocate and free the
reactor structure, and ASAN stops complaining.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
SIGALRM is used by the boost unit test library, which interferes with our
use. This causes spurious unit test failures.
Switch to a real-time signal instead.
After the implementation of the code that uses the scollectd API was
modified, the get_collectd_value gets the collectd ID as a const
reference, to remove unnessary creation of shared_ptr.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
gate_closed_exception::what() is currently a private member, thus
calling the method when handling the exception isn't possible.
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
Execute a function making sure it is wrapped in a gate.
This can afford to be considerably simpler than do_with, since we are not
playing any games with object creation, and the gate itself can be assumed to
be relatively long lived.
Among other things, this will allow us to make changes to enter / leave without
breaking existing code, and experiment with stronger ways of doing leave - as
Avi suggested recently.
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
Currently if rpc handler returns smart pointer rpc will try to serialize
the pointer object as opposite to an object the ptr is pointing to.
This patch fixes it by serializing real object instead of a pointer.
.then()'s return type is a complex template, which needs to be mangled into
the function's name. Move the return type into a defaulted template type
parameter, so that the entire type expression is eliminated, being replaced
by the result type.
Saves about 1% compile time and 3% object size on futures_test.o.
We can use sstring as an argument to sprint. In some cases, we already have the
string in a variable and end up being forced to call c_str() from the caller
site. Accepting sstring as a parameter makes for a cleaner interface.
Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
This patch adds a "class future" method for handling an exception result
of the future. It is impossible to discard a future's exception while passing
through the value of the result (what will we pass in the case of
exception?), so we discard the result as well.
An example of how this can be used, to log an error (but otherwise do
nothing) if removing a file fails:
remove_file(filename).handle_exception(
[] (std::exception_ptr eptr) {
print("Exception when deleting file: %s", eptr);
});
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
close() is a blocking call, so it must be called in the I/O thread, not
the main reactor thread. To do that, we need a file::close() method that
can return a future.