//char* paramNotes; /**< Description of the params expected for this method. */
int options; /**< Bit switches setting various options for this method. */
void* userData; /**< Opaque pointer to application-specific data. */
+ size_t bufsize; /**< How big a buffer to use for non-atomic methods */
/*
int sysmethod;
int osrfAppRegisterExtendedMethod( const char* appName, const char* methodName,
const char* symbolName, const char* notes, int argc, int options, void* );
+int osrfMethodSetBufferSize( const char* appName, const char* methodName, size_t bufsize );
+
osrfMethod* _osrfAppFindMethod( const char* appName, const char* methodName );
int osrfAppRunMethod( const char* appName, const char* methodName,
#define OSRF_METHOD_ATOMIC 4
/*@}*/
+/**
+ @brief Default size of output buffer.
+*/
#define OSRF_MSG_BUFFER_SIZE 10240
/**
}
/**
- @brief Register a method for a specified application.
+ @brief Register an extended method for a specified application.
@param appName Name of the application that implements the method.
@param methodName The fully qualified name of the method.
if(user_data)
method->userData = user_data;
+ method->bufsize = OSRF_MSG_BUFFER_SIZE;
return method;
}
/**
+ @brief Set the effective output buffer size for a given method.
+ @param appName Name of the application.
+ @param methodName Name of the method.
+ @param bufsize Desired size of the output buffer, in bytes.
+ @return Zero if successful, or -1 if the specified method cannot be found.
+
+ A smaller buffer size may result in a lower latency for the first response, since we don't
+ wait for as many messages to accumulate before flushing the output buffer. On the other
+ hand a larger buffer size may result in higher throughput due to lower network overhead.
+
+ Since the buffer size is not an absolute limit, it may be set to zero, in which case each
+ output transport message will contain no more than one RESULT message.
+
+ This function has no effect on atomic methods, because all responses are sent in a single
+ message anyway. Likewise it has no effect on a method that returns only a single response.
+*/
+int osrfMethodSetBufferSize( const char* appName, const char* methodName, size_t bufsize ) {
+ osrfMethod* method = _osrfAppFindMethod( appName, methodName );
+ if( method ) {
+ osrfLogInfo( OSRF_LOG_MARK,
+ "Setting outbuf buffer size to %lu for method %s of application %s",
+ (unsigned long) bufsize, methodName, appName );
+ method->bufsize = bufsize;
+ return 0;
+ } else {
+ osrfLogWarning( OSRF_LOG_MARK,
+ "Unable to set outbuf buffer size to %lu for method %s of application %s",
+ (unsigned long) bufsize, methodName, appName );
+ return -1;
+ }
+}
+
+/**
@brief Register all of the system methods for this application.
@param app Pointer to the application.
// If the new message would overflow the buffer, flush the output buffer first
int len_so_far = buffer_length( ctx->session->outbuf );
- if( len_so_far && (strlen( json ) + len_so_far >= OSRF_MSG_BUFFER_SIZE - 3) ) {
+ if( len_so_far && (strlen( json ) + len_so_far + 3 >= ctx->method->bufsize )) {
if( flush_responses( ctx->session, ctx->session->outbuf ))
return -1;
}