You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2014/01/29 13:10:21 UTC
svn commit: r1562425 - in /subversion/trunk/subversion:
bindings/javahl/native/ include/ libsvn_client/ libsvn_ra_svn/
tests/libsvn_ra/
Author: rhuijben
Date: Wed Jan 29 12:10:21 2014
New Revision: 1562425
URL: http://svn.apache.org/r1562425
Log:
Tweak the ra-svn tunnel close api to be more like our other close apis
and to auto-document that the errors returned from the close function
are 100% ignored (like all other errors from pool cleanup handlers).
Both the JavaHL implementation and the test suite had assumptions that
these errors would be properly handled to show their test results, while
any error from a pool cleanup is really just ignored by apr.
(So the assertions in the tests would just be ignored).
Make ra_svn close streams from callbacks at pool cleanup too, to allow
implementations to just implement a proper stream class.
* subversion/bindings/javahl/native/ClientContext.cpp
(ClientContext::ClientContext,
ClientContext::setTunnelCallback): Update caller.
* subversion/bindings/javahl/native/OperationContext.cpp
(TunnelContext::TunnelContext): Add arguments.
(TunnelContext): Add fields.
(OperationContext::openTunnel): Update prototype.
Store data for close callback.
(OperationContext::closeTunnel): Temporarily rename to
(OperationContext::inner_closeTunnel): ... this and update prototype.
(OperationContext::closeTunnel): New function with explicit error clear to
document the true behavior.
* subversion/bindings/javahl/native/OperationContext.h
(openTunnel): Update prototype.
(inner_closeTunnel): Rename and tweak prototype.
(closeTunnel): New function.
* subversion/bindings/javahl/native/RemoteSessionContext.cpp
(RemoteSessionContext::RemoteSessionContext): Update caller.
* subversion/include/svn_client.h
(svn_client_ctx_t): Remove callback. Tweak comment.
* subversion/include/svn_ra.h
(svn_ra_close_tunnel_func_t): Move here (above the open function) and remove
unneeded arguments. Update to return void to make it obvious that errors
can't be handled.
(svn_ra_open_tunnel_func_t): Add close_func output argument.
(svn_ra_callbacks2_t): Remove close func callback.
* subversion/libsvn_client/ra.c
(svn_client__open_ra_session_internal): Update caller.
* subversion/libsvn_ra_svn/client.c
(tunnel_data_t): Store streams in baton. Remove init values.
(close_tunnel_cleanup): Allow NULL callback. Explicitly close streams.
(open_session): Always initialize cleanup.
* subversion/tests/libsvn_ra/ra-test.c
(includes): Add assert.h.
(close_tunnel): Add forward declaration.
(open_tunnel): Update prototype. Update caller. Don't return address of local
variable.
(close_tunnel): Update prototype. Use assert that *will* show errors during
testing.
Modified:
subversion/trunk/subversion/bindings/javahl/native/ClientContext.cpp
subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp
subversion/trunk/subversion/bindings/javahl/native/OperationContext.h
subversion/trunk/subversion/bindings/javahl/native/RemoteSessionContext.cpp
subversion/trunk/subversion/include/svn_client.h
subversion/trunk/subversion/include/svn_ra.h
subversion/trunk/subversion/libsvn_client/ra.c
subversion/trunk/subversion/libsvn_ra_svn/client.c
subversion/trunk/subversion/tests/libsvn_ra/ra-test.c
Modified: subversion/trunk/subversion/bindings/javahl/native/ClientContext.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/ClientContext.cpp?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/ClientContext.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/ClientContext.cpp Wed Jan 29 12:10:21 2014
@@ -75,7 +75,6 @@ ClientContext::ClientContext(jobject jsv
{
m_context->check_tunnel_func = checkTunnel;
m_context->open_tunnel_func = openTunnel;
- m_context->close_tunnel_func = closeTunnel;
m_context->tunnel_baton = m_jtunnelcb;
}
}
@@ -91,14 +90,12 @@ void ClientContext::setTunnelCallback(jo
{
m_context->check_tunnel_func = checkTunnel;
m_context->open_tunnel_func = openTunnel;
- m_context->close_tunnel_func = closeTunnel;
m_context->tunnel_baton = m_jtunnelcb;
}
else
{
m_context->check_tunnel_func = NULL;
m_context->open_tunnel_func = NULL;
- m_context->close_tunnel_func = NULL;
m_context->tunnel_baton = NULL;
}
}
Modified: subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/OperationContext.cpp Wed Jan 29 12:10:21 2014
@@ -485,7 +485,9 @@ namespace {
class TunnelContext
{
public:
- explicit TunnelContext(apr_pool_t *pool)
+ explicit TunnelContext(const char *t_name, const char *t_user,
+ const char *t_hostname, int t_port,
+ apr_pool_t *pool)
: request_in(NULL),
request_out(NULL),
response_in(NULL),
@@ -506,6 +508,10 @@ public:
if (!status)
status = apr_file_pipe_create(&response_in, &response_out, pool);
#endif
+ tunnel_name = apr_pstrdup(pool, t_name);
+ user = apr_pstrdup(pool, t_user);
+ hostname = apr_pstrdup(pool, t_hostname);
+ port = t_port;
}
~TunnelContext()
@@ -519,6 +525,11 @@ public:
apr_file_t *response_in;
apr_file_t *response_out;
apr_status_t status;
+
+ const char *tunnel_name;
+ const char *user;
+ const char *hostname;
+ int port;
};
jobject create_Channel(const char *class_name, JNIEnv *env, apr_file_t *fd)
@@ -573,12 +584,15 @@ OperationContext::checkTunnel(void *tunn
svn_error_t *
OperationContext::openTunnel(svn_stream_t **request, svn_stream_t **response,
- void **tunnel_context, void *tunnel_baton,
+ svn_ra_close_tunnel_func_t *close_func,
+ void **close_baton,
+ void *tunnel_baton,
const char *tunnel_name, const char *user,
const char *hostname, int port,
apr_pool_t *pool)
{
- TunnelContext *tc = new TunnelContext(pool);
+ TunnelContext *tc = new TunnelContext(tunnel_name, user, hostname, port,
+ pool);
if (tc->status)
{
delete tc;
@@ -586,7 +600,8 @@ OperationContext::openTunnel(svn_stream_
svn_error_wrap_apr(tc->status, _("Could not open tunnel streams")));
}
- *tunnel_context = tc;
+ *close_func = closeTunnel;
+ *close_baton = tc;
*request = svn_stream_from_aprfile2(tc->request_out, FALSE, pool);
*response = svn_stream_from_aprfile2(tc->response_in, FALSE, pool);
@@ -632,11 +647,17 @@ OperationContext::openTunnel(svn_stream_
}
svn_error_t *
-OperationContext::closeTunnel(void *tunnel_context, void *tunnel_baton,
- const char *tunnel_name, const char *user,
- const char *hostname, int port)
+OperationContext::inner_closeTunnel(void *tunnel_context, void *tunnel_baton)
{
- delete static_cast<TunnelContext*>(tunnel_context);
+ TunnelContext* tc = static_cast<TunnelContext*>(tunnel_context);
+
+ /* ### These are allocated in the pool, so it is safe to cache them here */
+ const char *tunnel_name = tc->tunnel_name;
+ const char *user = tc->user;
+ const char *hostname = tc->hostname;
+ int port = tc->port;
+
+ delete tc;
jstring jtunnel_name = JNIUtil::makeJString(tunnel_name);
SVN_JNI_CATCH(, SVN_ERR_BASE);
@@ -670,3 +691,11 @@ OperationContext::closeTunnel(void *tunn
return SVN_NO_ERROR;
}
+
+void
+OperationContext::closeTunnel(void *tunnel_context, void *tunnel_baton)
+{
+ /* ### We now ignore all errors here. We used to ignore them in the
+ Subversion API */
+ svn_error_clear(inner_closeTunnel(tunnel_context, tunnel_baton));
+}
Modified: subversion/trunk/subversion/bindings/javahl/native/OperationContext.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/OperationContext.h?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/OperationContext.h (original)
+++ subversion/trunk/subversion/bindings/javahl/native/OperationContext.h Wed Jan 29 12:10:21 2014
@@ -70,15 +70,17 @@ class OperationContext
static svn_error_t *openTunnel(
svn_stream_t **request, svn_stream_t **response,
- void **tunnel_context, void *tunnel_baton,
+ svn_ra_close_tunnel_func_t *close_func, void **close_baton,
+ void *tunnel_baton,
const char *tunnel_name, const char *user,
const char *hostname, int port,
apr_pool_t *pool);
- static svn_error_t *closeTunnel(
- void *tunnel_context, void *tunnel_baton,
- const char *tunnel_name, const char *user,
- const char *hostname, int port);
+ static svn_error_t *inner_closeTunnel(
+ void *tunnel_context, void *tunnel_baton);
+
+ static void closeTunnel(
+ void *tunnel_context, void *tunnel_baton);
public:
OperationContext(SVN::Pool &pool);
Modified: subversion/trunk/subversion/bindings/javahl/native/RemoteSessionContext.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/RemoteSessionContext.cpp?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/RemoteSessionContext.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/RemoteSessionContext.cpp Wed Jan 29 12:10:21 2014
@@ -75,7 +75,6 @@ RemoteSessionContext::RemoteSessionConte
{
m_raCallbacks->check_tunnel_func = checkTunnel;
m_raCallbacks->open_tunnel_func = openTunnel;
- m_raCallbacks->close_tunnel_func = closeTunnel;
m_raCallbacks->tunnel_baton = m_jtunnelcb;
}
}
Modified: subversion/trunk/subversion/include/svn_client.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_client.h?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_client.h (original)
+++ subversion/trunk/subversion/include/svn_client.h Wed Jan 29 12:10:21 2014
@@ -1040,17 +1040,7 @@ typedef struct svn_client_ctx_t
*/
svn_ra_open_tunnel_func_t open_tunnel_func;
- /** Close-tunnel callback
- *
- * If not @c NULL, this callback will be invoked when the pool that
- * owns the connection created by the open_tunnel callback is
- * cleared or destroyed. This callback is used only for ra_svn and
- * ignored by the other RA modules.
- * @since New in 1.9.
- */
- svn_ra_close_tunnel_func_t close_tunnel_func;
-
- /** A baton used with open_tunnel_func and close_tunnel_func.
+ /** The baton used with check_tunnel_func and open_tunnel_func.
* @since New in 1.9.
*/
void *tunnel_baton;
Modified: subversion/trunk/subversion/include/svn_ra.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_ra.h?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_ra.h (original)
+++ subversion/trunk/subversion/include/svn_ra.h Wed Jan 29 12:10:21 2014
@@ -284,6 +284,22 @@ typedef svn_boolean_t (*svn_ra_check_tun
void *tunnel_baton, const char *tunnel_name);
/**
+ * Callback function for closing a tunnel in ra_svn.
+ *
+ * This function will be called when the pool that owns the tunnel
+ * connection is cleared or destroyed.
+ *
+ * @a tunnel_context is the baton as returned from the
+ * svn_ra_open_tunnel_func_t.
+ *
+ * @a tunnel_baton was returned by the open-tunnel callback.
+ *
+ * @since New in 1.9.
+ */
+typedef void (*svn_ra_close_tunnel_func_t)(
+ void *close_baton, void *tunnel_baton);
+
+/**
* Callback function for opening a tunnel in ra_svn.
*
* Given the @a tunnel_name, tunnel @a user and server @a hostname and
@@ -293,38 +309,21 @@ typedef svn_boolean_t (*svn_ra_check_tun
* @a request and @a response represent the standard input and output,
* respectively, of the process on the other end of the tunnel.
*
- * @a tunnel_context will be passed on to the close-unnel callback.
+ * If @a *close_func is set it will be called with @a close_baton when
+ * the tunnel is closed.
*
- * @a tunnel_baton is the baton as originally passed to ra_open.
+ * @a tunnel_baton is the baton as set in the callbacks.
*
* @since New in 1.9.
*/
typedef svn_error_t *(*svn_ra_open_tunnel_func_t)(
svn_stream_t **request, svn_stream_t **response,
- void **tunnel_context, void *tunnel_baton,
+ svn_ra_close_tunnel_func_t *close_func, void **close_baton,
+ void *tunnel_baton,
const char *tunnel_name, const char *user,
const char *hostname, int port,
apr_pool_t *pool);
-/**
- * Callback function for closing a tunnel in ra_svn.
- *
- * This function will be called when the pool that owns the tunnel
- * connection is cleared or destroyed. It receives the @a baton that
- * was created by the open-tunnel callback, and the same
- * @a tunnel_name, @a user, @a hostname and @a port parameters.
- *
- * @a tunel_baton was returned by the open-tunnel callback.
- *
- * @a open_baton is the baton as originally passed to ra_open.
- *
- * @since New in 1.9.
- */
-typedef svn_error_t *(*svn_ra_close_tunnel_func_t)(
- void *tunnel_context, void *tunnel_baton,
- const char *tunnel_name, const char *user,
- const char *hostname, int port);
-
/**
* The update Reporter.
@@ -614,16 +613,6 @@ typedef struct svn_ra_callbacks2_t
*/
svn_ra_open_tunnel_func_t open_tunnel_func;
- /** Close-tunnel callback
- *
- * If not @c NULL, this callback will be invoked when the pool that
- * owns the connection created by the open_tunnel callback is
- * cleared or destroyed. This callback is used only for ra_svn and
- * ignored by the other RA modules.
- * @since New in 1.9.
- */
- svn_ra_close_tunnel_func_t close_tunnel_func;
-
/** A baton used with open_tunnel_func and close_tunnel_func.
* @since New in 1.9.
*/
Modified: subversion/trunk/subversion/libsvn_client/ra.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/ra.c?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/ra.c (original)
+++ subversion/trunk/subversion/libsvn_client/ra.c Wed Jan 29 12:10:21 2014
@@ -352,7 +352,6 @@ svn_client__open_ra_session_internal(svn
cbtable->get_wc_contents = get_wc_contents;
cbtable->check_tunnel_func = ctx->check_tunnel_func;
cbtable->open_tunnel_func = ctx->open_tunnel_func;
- cbtable->close_tunnel_func = ctx->close_tunnel_func;
cbtable->tunnel_baton = ctx->tunnel_baton;
cb->commit_items = commit_items;
Modified: subversion/trunk/subversion/libsvn_ra_svn/client.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_svn/client.c?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_svn/client.c (original)
+++ subversion/trunk/subversion/libsvn_ra_svn/client.c Wed Jan 29 12:10:21 2014
@@ -571,24 +571,26 @@ static svn_error_t *parse_url(const char
struct tunnel_data_t {
void *tunnel_context;
void *tunnel_baton;
- const char *tunnel_name;
- const char *user;
- const char *hostname;
- int port;
svn_ra_close_tunnel_func_t close_tunnel;
+ svn_stream_t *request;
+ svn_stream_t *response;
};
-/* Pool cleanup function that invokes the close-tunel callback. */
+/* Pool cleanup function that invokes the close-tunnel callback. */
static apr_status_t close_tunnel_cleanup(void *baton)
{
const struct tunnel_data_t *const td = baton;
- svn_error_t *const err =
- svn_error_root_cause(td->close_tunnel(td->tunnel_context, td->tunnel_baton,
- td->tunnel_name, td->user,
- td->hostname, td->port));
- const apr_status_t ret = (err ? err->apr_err : 0);
- svn_error_clear(err);
- return ret;
+
+ if (td->close_tunnel)
+ td->close_tunnel(td->tunnel_context, td->tunnel_baton);
+
+ svn_error_clear(svn_stream_close(td->request));
+
+ /* We might have one stream to use for both request and response! */
+ if (td->request != td->response);
+ svn_error_clear(svn_stream_close(td->response));
+
+ return APR_SUCCESS; /* ignored */
}
/* Open a session to URL, returning it in *SESS_P, allocating it in POOL.
@@ -640,29 +642,22 @@ static svn_error_t *open_session(svn_ra_
SVN_ERR(make_tunnel(tunnel_argv, &conn, pool));
else
{
- void *tunnel_context;
- svn_stream_t *request;
- svn_stream_t *response;
+ struct tunnel_data_t *const td = apr_palloc(pool, sizeof(*td));
+
+ td->tunnel_baton = callbacks->tunnel_baton;
+ td->close_tunnel = NULL;
+
SVN_ERR(callbacks->open_tunnel_func(
- &request, &response, &tunnel_context,
+ &td->request, &td->response,
+ &td->close_tunnel, &td->tunnel_context,
callbacks->tunnel_baton, tunnel_name,
uri->user, uri->hostname, uri->port,
pool));
- if (callbacks->close_tunnel_func)
- {
- struct tunnel_data_t *const td = apr_palloc(pool, sizeof(*td));
- td->tunnel_context = tunnel_context;
- td->tunnel_baton = callbacks->tunnel_baton;
- td->tunnel_name = apr_pstrdup(pool, tunnel_name);
- td->user = apr_pstrdup(pool, uri->user);
- td->hostname = apr_pstrdup(pool, uri->hostname);
- td->port = uri->port;
- td->close_tunnel = callbacks->close_tunnel_func;
- apr_pool_cleanup_register(pool, td, close_tunnel_cleanup,
- apr_pool_cleanup_null);
- }
- conn = svn_ra_svn_create_conn4(NULL, response, request,
+ apr_pool_cleanup_register(pool, td, close_tunnel_cleanup,
+ apr_pool_cleanup_null);
+
+ conn = svn_ra_svn_create_conn4(NULL, td->response, td->request,
SVN_DELTA_COMPRESSION_LEVEL_DEFAULT,
0, 0, pool);
SVN_ERR(svn_ra_svn__skip_leading_garbage(conn, pool));
Modified: subversion/trunk/subversion/tests/libsvn_ra/ra-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_ra/ra-test.c?rev=1562425&r1=1562424&r2=1562425&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_ra/ra-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_ra/ra-test.c Wed Jan 29 12:10:21 2014
@@ -26,7 +26,7 @@
#include <apr_general.h>
#include <apr_pools.h>
#include <apr_file_io.h>
-
+#include <assert.h>
#define SVN_DEPRECATED
#include "svn_error.h"
@@ -108,9 +108,13 @@ check_tunnel(void *tunnel_baton, const c
return last_tunnel_check;
}
+static void
+close_tunnel(void *tunnel_context, void *tunnel_baton);
+
static svn_error_t *
open_tunnel(svn_stream_t **request, svn_stream_t **response,
- void **tunnel_context, void *tunnel_baton,
+ svn_ra_close_tunnel_func_t *close_func, void **close_baton,
+ void *tunnel_baton,
const char *tunnel_name, const char *user,
const char *hostname, int port,
apr_pool_t *pool)
@@ -160,20 +164,18 @@ open_tunnel(svn_stream_t **request, svn_
*request = svn_stream_from_aprfile2(proc->in, FALSE, pool);
*response = svn_stream_from_aprfile2(proc->out, FALSE, pool);
- open_tunnel_context = *tunnel_context = &kind;
+ *close_func = close_tunnel;
+ open_tunnel_context = *close_baton = &last_tunnel_check;
++tunnel_open_count;
return SVN_NO_ERROR;
}
-static svn_error_t *
-close_tunnel(void *tunnel_context, void *tunnel_baton,
- const char *tunnel_name, const char *user,
- const char *hostname, int port)
+static void
+close_tunnel(void *tunnel_context, void *tunnel_baton)
{
- SVN_TEST_ASSERT(tunnel_context == open_tunnel_context);
- SVN_TEST_ASSERT(tunnel_baton == check_tunnel_baton);
+ assert(tunnel_context == open_tunnel_context);
+ assert(tunnel_baton == check_tunnel_baton);
--tunnel_open_count;
- return SVN_NO_ERROR;
}
@@ -255,7 +257,6 @@ check_tunnel_callback_test(const svn_tes
SVN_ERR(svn_ra_create_callbacks(&cbtable, pool));
cbtable->check_tunnel_func = check_tunnel;
cbtable->open_tunnel_func = open_tunnel;
- cbtable->close_tunnel_func = close_tunnel;
cbtable->tunnel_baton = check_tunnel_baton = &cbtable;
SVN_ERR(svn_cmdline_create_auth_baton(&cbtable->auth_baton,
TRUE /* non_interactive */,
@@ -293,7 +294,6 @@ tunel_callback_test(const svn_test_opts_
SVN_ERR(svn_ra_create_callbacks(&cbtable, pool));
cbtable->check_tunnel_func = check_tunnel;
cbtable->open_tunnel_func = open_tunnel;
- cbtable->close_tunnel_func = close_tunnel;
cbtable->tunnel_baton = check_tunnel_baton = &cbtable;
SVN_ERR(svn_cmdline_create_auth_baton(&cbtable->auth_baton,
TRUE /* non_interactive */,