[Opensrf-commits] r1986 - in trunk: include/opensrf src/libopensrf (scottmk)
svn at svn.open-ils.org
svn at svn.open-ils.org
Thu Jul 29 15:38:26 EDT 2010
Author: scottmk
Date: 2010-07-29 15:38:21 -0400 (Thu, 29 Jul 2010)
New Revision: 1986
Modified:
trunk/include/opensrf/osrf_app_session.h
trunk/src/libopensrf/osrf_app_session.c
Log:
1. Add a buffer to osrfAppSession structure; for future use
2. New function osrfSendTransportPayload(). This a repackaging of
existing functionality pulled out into a separate function so that
it can be reused in other contexts.
These changes are preparation for future changes, and will have no
visible effect by themselves.
M include/opensrf/osrf_app_session.h
M src/libopensrf/osrf_app_session.c
Modified: trunk/include/opensrf/osrf_app_session.h
===================================================================
--- trunk/include/opensrf/osrf_app_session.h 2010-07-29 17:40:03 UTC (rev 1985)
+++ trunk/include/opensrf/osrf_app_session.h 2010-07-29 19:38:21 UTC (rev 1986)
@@ -19,7 +19,7 @@
extern "C" {
#endif
-enum OSRF_SESSION_STATE {
+enum OSRF_SESSION_STATE {
OSRF_SESSION_CONNECTING,
OSRF_SESSION_CONNECTED,
OSRF_SESSION_DISCONNECTED
@@ -80,7 +80,7 @@
/** Callback function for freeing user's session data. */
void (*userDataFree) (void*);
- int transport_error;
+ int transport_error;
/** Hash table of pending requests. */
osrfAppRequest* request_hash[ OSRF_REQUEST_HASH_SIZE ];
@@ -88,6 +88,9 @@
/** Boolean: true if the app wants to terminate the process. Typically this means that */
/** a drone has lost its database connection and can therefore no longer function. */
int panic;
+
+ /** Buffer used by server drone to collect outbound response messages */
+ growing_buffer* outbuf;
};
typedef struct osrf_app_session_struct osrfAppSession;
@@ -124,6 +127,8 @@
int osrf_app_session_request_resend( osrfAppSession*, int request_id );
+int osrfSendTransportPayload( osrfAppSession* session, const char* payload );
+
void osrf_app_session_reset_remote( osrfAppSession* );
void osrf_app_session_set_remote( osrfAppSession* session, const char* remote_id );
Modified: trunk/src/libopensrf/osrf_app_session.c
===================================================================
--- trunk/src/libopensrf/osrf_app_session.c 2010-07-29 17:40:03 UTC (rev 1985)
+++ trunk/src/libopensrf/osrf_app_session.c 2010-07-29 19:38:21 UTC (rev 1986)
@@ -479,6 +479,7 @@
session->session_locale = NULL;
session->transport_error = 0;
session->panic = 0;
+ session->outbuf = NULL; // Not used by client
#ifdef ASSUME_STATELESS
session->stateless = 1;
@@ -560,7 +561,8 @@
// to the compile-time macro ASSUME_STATELESS.
int stateless = 0;
char* statel = osrf_settings_host_value("/apps/%s/stateless", our_app );
- if(statel) stateless = atoi(statel);
+ if( statel )
+ stateless = atoi( statel );
free(statel);
session->remote_id = strdup(remote_id);
@@ -582,12 +584,16 @@
session->userData = NULL;
session->userDataFree = NULL;
+ session->transport_error = 0;
// Initialize the hash table
int i;
for( i = 0; i < OSRF_REQUEST_HASH_SIZE; ++i )
session->request_hash[ i ] = NULL;
+ session->panic = 0;
+ session->outbuf = buffer_init( 4096 );
+
_osrf_app_session_push_session( session );
return session;
}
@@ -952,28 +958,42 @@
}
}
- // Bundle all the osrfMessages into a single transport_message, then send it.
+ // Translate the collection of osrfMessages into a JSON array
char* string = osrfMessageSerializeBatch(msgs, size);
+ // Send the JSON as the payload of a transport_message
if( string ) {
+ retval = osrfSendTransportPayload( session, string );
+ free(string);
+ }
- transport_message* t_msg = message_init(
- string, "", session->session_id, session->remote_id, NULL );
- message_set_osrf_xid( t_msg, osrfLogGetXid() );
+ return retval;
+}
- retval = client_send_message( session->transport_handle, t_msg );
- if( retval )
- osrfLogError(OSRF_LOG_MARK, "client_send_message failed");
+/**
+ @brief Wrap a given string in a transport message and send it.
+ @param session Pointer to the osrfAppSession responsible for sending the message(s).
+ @param payload A string to be sent via Jabber.
+ @return 0 upon success, or -1 upon failure.
- osrfLogInfo(OSRF_LOG_MARK, "[%s] sent %d bytes of data to %s",
- session->remote_service, strlen(string), t_msg->recipient );
+ In practice the payload is normally a JSON string, but this function assumes nothing
+ about it.
+*/
+int osrfSendTransportPayload( osrfAppSession* session, const char* payload ) {
+ transport_message* t_msg = message_init(
+ payload, "", session->session_id, session->remote_id, NULL );
+ message_set_osrf_xid( t_msg, osrfLogGetXid() );
- osrfLogDebug(OSRF_LOG_MARK, "Sent: %s", string );
+ int retval = client_send_message( session->transport_handle, t_msg );
+ if( retval )
+ osrfLogError( OSRF_LOG_MARK, "client_send_message failed" );
- free(string);
- message_free( t_msg );
- }
+ osrfLogInfo(OSRF_LOG_MARK, "[%s] sent %d bytes of data to %s",
+ session->remote_service, strlen( payload ), t_msg->recipient );
+ osrfLogDebug( OSRF_LOG_MARK, "Sent: %s", payload );
+
+ message_free( t_msg );
return retval;
}
@@ -1077,6 +1097,10 @@
app = next;
}
}
+
+ if( session->outbuf )
+ buffer_free( session->outbuf );
+
free(session);
}
More information about the opensrf-commits
mailing list