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.
convert fileiotest.cc to Boost test case, making it easier to see what
is being tested, and to add more file io tests.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Similar to std::shared_mutex, allows shared and exclusive locking of a
resource (also known as a reader/writer lock). This implementation is
strictly FIFO.
For some reason, I added a fsync call when the file underlying the
stream gets truncated. That happens when flushing a file, which
size isn't aligned to the requested DMA buffer.
Instead, fsync should only be called when closing the stream, so this
patch changes the code to do that.
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
When a promise that still tracks its future is destroyed, but after
future::get() or future::then() was called, the promise thinks it was
destroyed before generating a value, and fails an assertion.
Fix be detaching the promise from the future as soon as get() or then()
remove the value.
Following std::async(), seastar::async(func) causes func to be executed
in a seastar thread, where it can block using future<>::get(). Whatever
func returns is converted to a future, and returned as async()s return
value.
This change how the json formatter handle float and adds double support.
float and double conversion will throw exceptions when try to convert
inf or nan.
It also contains tests for both float and double including inf, -inf and
nan for both float and double.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
The parameters in the request holds the path parameters. The current
implementation based on unorder_map has a few downside:
1. Because path parameters are sometime used to mark a file path and
they can extend to multiple url section (may contain /) the value will
always contain the leading slash. Though this is true for files, for
the common case, it would be easier to return the value without it.
2. The []operator of the hash map is non const, this mean that it cannot
be used in the common case where the request object is passed as a const
reference.
3. There is no exists method in an ordered_map - Usually query
parameters are mandatory, still it is usefull to have an easy way of
testing if a parameter is found.
This series wrap the unordered_map implementation in a manner more
suitable for the request.
The [] operator will be const and retrun a copy of the parameter value
without the leading slash.
The at method will keep the old meaning. For clearer code, a path method
was added to indicate that the return value has a leading slash.
A set method is used for assignment.
Older code will continue to work without changes.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Our input_stream::consume() mechanism allows feeding data from an input
stream into a consumer, piece by piece, until the consumer doesn't want
any more. It currently assumed the input can block (when reading from disk),
but the consumption is assumed to be immediate. This patch adds support for
blocking in the consumption function: The consumer now returns a future
which it promises to fulfill after consuming the given buffer.
This patch goes further by somewhat simplifying (?) the interface of the
consumer. Instead of receiving a mysterious "done" lambda the consumer
is supposed to call when done (doesn't want any more input), the consumer
now returns a future<optional<temporary_buffer<char>>, which means:
1. The future is fulfilled when the consumer is done with this buffer
and either wants more - or wants to stop.
2. If the consumer wants to stop, it returns the *remaining* part of the
buffer it didn't want to process (this will be pushed back into the
input stream).
3. If the consumer is not done, and wants to consume more, it returns an
unset optional.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
This patchset adds thread support to seastar. Threads can use the normal
seastar API, and may also "block" by calling future<>::get() on an
unavailable future. Synchronous and asynchronous code may be intermixed.
Threads may not issue blocking operating system calls.
The implementation of sleep() looks like a game of Seastar golf - doing
something in the minimum number of lines possible :-) Unfortunately, it
looks very clever, but not quite right. sleep() usually works correctly,
but the sanitizer (in the debug build) catches a use after free.
The problem was that we delete an object which contains a timer which
contains the callback (and std::function) - from inside this callback.
The workaround in this patch is to use our future chaining to only delete
the sleeper object after its future became ready - and at that point, none
of the sleeper object or code is needed any more.
This patch also includes a regression test for this issue. The test looks
silly (just sleeps and checks nothing), but in the debugging build it
failed (with a sanitizer reporting use-after-free) before this patch.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Separating the initial value (and accumulator) from the reducer function
can result in simpler invocations.
Unfortunately, the name conflicts with another variant, so we have to name
the method map_reduce0.
The foreign_ptr wrapper needs 'element_type' to be present in
shared_ptr to be able to access the data.
Fixes the following compilation failure when trying to use shared_ptr
with foreign_ptr:
In file included from tests/foreign_ptr_test.cc:24:0:
./core/distributed.hh: In instantiation of ‘class foreign_ptr<shared_ptr<basic_sstring<char, unsigned int, 15u> > >’:
tests/foreign_ptr_test.cc:28:54: required from here
./core/distributed.hh:272:56: error: no type named ‘element_type’ in ‘class shared_ptr<basic_sstring<char, unsigned int, 15u> >’
using element_type = typename PtrType::element_type;
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
When serving a request with multiple query parameters the last parameter
was parsed incorectly.
This fix the issue and add a test to verify it
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
So that it's compiled only once and not for every test. This change
reduced recompilation time for a dummy test module from 40 seconds to
4 on my laptop.
This change also makes it now possible to pass seastar framework command
line arguments to every test using this framework.
If the engine exits premauterly the _task exchanger may be occupied by
a pending task in which case give() will block indefinitely. Fix by
using interruption.
Files transformers are used to replace file content before retrieving
it. Specifically, it is used to return swagger definition files with the
host and protocol replaced.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
The boost::replace_all uses insert and erase to perform a change, those
method are missing from sstring.
Following the std:string implemntation the implementation of both
functionalities is based on the replace method, either as c string
replace or with templated iterators.
Not all the variation of insert, replace and erase where added, but it
will be possible to add them in the future if needed by calling the
existing functionality.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
Http url encode query parameters by adding a question mark after the uri
with pairs of key=value items.
All values in the url are url decoded.
This add the url encoding and query parameters support
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
The http server handlers can sometimes need to perform async operation,
specifically, when reading files from the disk. To support async
behavior the handlers handle function will return a future, that will be
propagate back, when the future will be ready it will return the reply
to be sent.
When switching from direct function call to future, there is also a need
to switch from references to pointers.
Note that while the request will be discarded, the reply will be
propagate back via the future to the caller.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This adds the back method that return a reference or const reference to
the last char in an sstring.
find_last_of, which return the index of the last occurance of a char in
the string.
And append with append C string to a string.
The logic and definition are similiar to the std::string.
Note that following the std::string definition, calling back on an empty
string is forbiden and the results are undefined.
Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>