scottmk [Tue, 31 Mar 2009 18:30:10 +0000 (18:30 +0000)]
1. Create a new osrfListExtract function, which removes an item
from an osrfList without destroying it, and returns a pointer to
the item thus removed.
2. Create a new jsonObjectExtractIndex, which removes a
specified entry in a JSON_ARRAY, and returns a pointer
to it, without destroying it.
3. In osrf_json.h: Corrected an inaccurate comment about
jsonObjectRemoveIndex(). Contrary to the original comment, this
function does not shift other objects down to fill the gap.
scottmk [Tue, 31 Mar 2009 12:45:53 +0000 (12:45 +0000)]
In osrf_system_shutdown(): provide a return value for an early
return (since the function is of type int).
It's not clear whether these are the right semantics, since we
never capture the return value anyway. But if we're going
to return anything at all, it makes sense to return something
different in the case of an early return.
erickson [Tue, 17 Feb 2009 17:47:18 +0000 (17:47 +0000)]
not sure why this is an issue now (different perl/json:xs verions?), but
$obj->{$k} = JSONObject2Perl($bool)
results in 'Modification of a read-only value attempted', while
$obj->{$k} = $bool
does not, even though the JSON::XS::Boolean object is not altered by JSONObject2Perl().
just missing something?
patched
scottmk [Thu, 29 Jan 2009 03:58:26 +0000 (03:58 +0000)]
This update mainly tightens the error handling.
1. If there aren't enough arguments on the command line, return EXIT_FAILURE
instead of zero.
2. Defer the call to set_proc_title() until we are done using the command
line arguments, so that we don't have to make copies of them.
3. Check the return value from osrfConfigInit(). Otherwise a NULL (caused,
e.g., by a missing config file) leads to a segfault.
4. If the config file doesn't define any routers to spawn, exit immediately
with an error message before entering the fork loop.
5. If a child process returns (due to an error) instead of entering the
normal endless loop, break out of the fork loop. Otherwise the child
remains in the fork loop and spawns children of its own (unless it's the
last child to be spawned). At best, that's just silly.
6. Append an newline to a message issued from setupRouter(). (It's not
clear why this message goes directly to stderr instead of to the usual
logging machinery, which at this point is directed to stderr anyway.)
scottmk [Thu, 15 Jan 2009 02:05:24 +0000 (02:05 +0000)]
Add a new function osrfStringArrayTokenize. It parses an input
string into tokens separated by a specified delimiter character,
much like strtok() or strtok_r(), and loads them into an
osrfStringArray.
scottmk [Wed, 14 Jan 2009 14:36:14 +0000 (14:36 +0000)]
Add a function osrfMethodVerifyContext() to do what the
existing OSRF_METHOD_VERIFY_CONTEXT macro does. Use it in
_osrfAppRunSystemMethod() and osrfAppEcho().
erickson [Tue, 13 Jan 2009 20:33:01 +0000 (20:33 +0000)]
need a copy of the service when it's pulled from the cache, since the sessionCache object is freed. use apr_pstrdup so Apache will manage the memory for us
scottmk [Mon, 12 Jan 2009 05:35:10 +0000 (05:35 +0000)]
1. Replaced the innards of an osrfStringArray to include an
osrfList instead of a pointer to an osrfList. This change
eliminates a layer of malloc and free when creating and
destroying an osrfStringArray. It also eliminates a layer
of indirection when performing other operations.
2. Eliminated the prototype for string_array_get_total_size(),
since no such function exists.
3. Added the const qualifier to various function parameters.
scottmk [Sun, 11 Jan 2009 22:11:34 +0000 (22:11 +0000)]
In the macro OSRF_LIST_GET_INDEX: placed all occurrences of the macro arguments
in parentheses, to prevent unexpected effects when one or more of the
arguments is an expression.
scottmk [Fri, 9 Jan 2009 20:14:35 +0000 (20:14 +0000)]
Move the xmlSAXHandler out of the header and into the
implementation file, along with the prototypes of the
associated callback functions (which are now static)
scottmk [Fri, 9 Jan 2009 18:51:01 +0000 (18:51 +0000)]
Move the xmlSAXHandler out of the header and into the
implementation file, along with the declarations of the
associated callback functions (which are now static)
scottmk [Tue, 6 Jan 2009 20:55:03 +0000 (20:55 +0000)]
1. Make the functions reset_session_buffers() and grab_incoming()
static, since no other source file references them by name.
2. Delete various fragments of dead, obsolete, commented-out code.
3. In init_transport: delete the cleanup code after failure
of previous calls to buffer_init(). It's unreachable, since
buffer_init() can never return NULL.
4. Change transport_session.c so that it uses buffer_add_n()
instead of passing data through an intermediate buffer.
scottmk [Tue, 6 Jan 2009 16:01:41 +0000 (16:01 +0000)]
Tinkering with macros.
1. In OSRF_BUFFER_ADD, OSRF_BUFFER_ADD_CHAR, and OSRF_BUFFER_RESET:
eliminated multiple evaluations of macro arguments.
2. In OSRF_BUFFER_ADD: renamed local variable __tl to _tl, since
identifiers beginning with two underscores are reserved.
3. In OSRF_BUFFER_RESET: applied the do/while(0) trick so that the
macro will be work as intended when subject to an "if".
4. Added new macro OSRF_BUFFER_C_STR to return a const pointer to
the internal buffer of a growing_buffer. This new macro will enable
safe and direct access to the buffer contents without violating
encapsulation and without incurring a malloc and free.
scottmk [Mon, 5 Jan 2009 17:50:15 +0000 (17:50 +0000)]
This update boosts the performance of the jsonFormatString function.
1. Replaced the old _tabs function, which required the construction and
destruction of a growing_buffer, with a new append_indentation function,
which adds white space to an existing growing_buffer. This change
eliminates a passel of mallocs and frees.
2. Removed the call to strlen() from the loop condition.
3. Replaced calls to buffer_fadd(), a fairly slow function, with calls
to OSRF_BUFFER_ADD_CHAR() and append_indentation(). Also: replaced a
call to buffer_add_char with the corresponding macro.
4. Eliminated a harmless but wasteful bug that sometimes added
indentation to the end of a line.
In my benchmarking, using a moderately complex JSON string 201
characters long, the new version was seven times as fast as the old.
scottmk [Mon, 5 Jan 2009 17:36:42 +0000 (17:36 +0000)]
This update restructures the mechanism for queueing incoming transport
messages. In addition, the update to transport_client.c rearranges the
logic a bit in client_recv().
1. A transport_message now carries a pointer to be used in a linked list.
It is initialized to NULL when the message is created. We no longer use
a separately allocated list node to carry the message.
2. The queue of transport_messages no longer starts with a dummy node.
3. Instead of finding the tail of the queue by traversing the list from
the head, we maintain a separate pointer to the tail node. Thus the
enqueuing operation occurs in constant time instead of linear time.
4. In client_recv: we now have the dequeueing code in a single place,
instead of duplicating it.
5. In client_recv: I eliminated some conditional compilation that made
no real difference, since both branches of the #ifdef were effectively
identical.
6. In client_recv: changed both loops from while loops to do-while
loops, since in each case we want to perform at least one iteration.
scottmk [Mon, 5 Jan 2009 17:05:45 +0000 (17:05 +0000)]
1. In osrf_stack_transport_handler(): removed the memset() as
pointless.
2. Also in osrf_stack_transport_handler(), in the loop traversing
arr[]: changed the loop condition from "i != num_msgs" to
"i < num_msgs", for hygienic reasons.
3. Eliminated osrf_stack_message_handler(). The first half of it moved
into its caller. The second half moved into the two callees
_do_client() and _do_server(). This refactoring made it easier to
eliminate a memory leak where _do_server() was failing to free the
input osrfMessage. I also eliminated a bug whereby we potentially
tried to access a member of a freed osrfMessage.
4. osrf_stack_application_handler() now returns void instead of int,
since we were ignoring the return value anyway.