void _osrf_app_request_free( void * req ){
if( req == NULL ) return;
osrfAppRequest* r = (osrfAppRequest*) req;
-
if( r->payload ) osrf_message_free( r->payload );
-
- /*
- osrf_message* cur_msg = req->result;
- while( cur_msg != NULL ) {
- osrf_message* next_msg = cur_msg->next;
- osrf_message_free( cur_msg );
- cur_msg = next_msg;
- }
- osrf_message_free( req->payload );
- */
-
free( r );
}
ptr2 = ptr2->next;
}
ptr->next = result;
-
- /*
- result->next = req->result;
- req->result = result;
- */
}
}
/* tell the session to wait for stuff */
osrfLogDebug( OSRF_LOG_MARK, "In app_request receive with remaining time [%d]", (int) remaining );
- osrf_app_session_queue_wait( req->session, 0 );
+ osrf_app_session_queue_wait( req->session, 0, NULL );
if( req->result != NULL ) { /* if we received anything */
/* pop off the first message in the list */
if( req->complete )
return NULL;
- osrf_app_session_queue_wait( req->session, (int) remaining );
+ osrf_app_session_queue_wait( req->session, (int) remaining, NULL );
if( req->result != NULL ) { /* if we received anything */
/* pop off the first message in the list */
osrf_app_session* osrf_app_server_session_init(
char* session_id, char* our_app, char* remote_id ) {
- osrfLogInfo( OSRF_LOG_MARK, "Initing server session with session id %s, service %s,"
+ osrfLogDebug( OSRF_LOG_MARK, "Initing server session with session id %s, service %s,"
" and remote_id %s", session_id, our_app, remote_id );
osrf_app_session* session = osrf_app_session_find_session( session_id );
time_t remaining = (time_t) timeout;
while( session->state != OSRF_SESSION_CONNECTED && remaining >= 0 ) {
- osrf_app_session_queue_wait( session, remaining );
+ osrf_app_session_queue_wait( session, remaining, NULL );
remaining -= (int) (time(NULL) - start);
}
if( !(session && msgs && size > 0) ) return 0;
int retval = 0;
-
osrfMessage* msg = msgs[0];
if(msg) {
- osrf_app_session_queue_wait( session, 0 );
+ osrf_app_session_queue_wait( session, 0, NULL );
if(session->state != OSRF_SESSION_CONNECTED) {
transport_message* t_msg = message_init(
string, "", session->session_id, session->remote_id, NULL );
-
- osrfLogDebug(OSRF_LOG_MARK, "Session [%s] [%s] sending to %s \nData: %s",
- session->remote_service, session->session_id, t_msg->recipient, string );
retval = client_send_message( session->transport_handle, t_msg );
if( retval ) osrfLogError(OSRF_LOG_MARK, "client_send_message failed");
-
+
+ osrfLogInfo(OSRF_LOG_MARK, "[%s] sent %d bytes of data to %s",
+ session->remote_service, strlen(string), t_msg->recipient );
+
+ osrfLogDebug(OSRF_LOG_MARK, "Sent: %s", string );
+
free(string);
message_free( t_msg );
}
return retval;
-
}
* payload and message type. This method will return after
* any data has arrived.
*/
-int osrf_app_session_queue_wait( osrf_app_session* session, int timeout ){
+int osrf_app_session_queue_wait( osrf_app_session* session, int timeout, int* recvd ){
if(session == NULL) return 0;
int ret_val = 0;
osrfLogDebug(OSRF_LOG_MARK, "AppSession in queue_wait with timeout %d", timeout );
- ret_val = osrf_stack_entry_point(session->transport_handle, timeout);
+ ret_val = osrf_stack_entry_point(session->transport_handle, timeout, recvd);
return ret_val;
}
osrf_message* msg = osrf_message_init( RESULT, requestId, 1 );
char* json = jsonObjectToJSON( data );
+
osrf_message_set_result_content( msg, json );
_osrf_app_session_send( ses, msg );
osrf_message_free( status );
- /* join and free */
-
return 0;
}
enum OSRF_SESSION_TYPE { OSRF_SESSION_SERVER, OSRF_SESSION_CLIENT };
/* entry point for data into the stack. gets set in osrf_stack.c */
-int (*osrf_stack_entry_point) (transport_client* client, int timeout );
+int (*osrf_stack_entry_point) (transport_client* client, int timeout, int* recvd );
struct osrf_app_request_struct {
/** Our controlling session */
* payload and message type. This method will return after
* any data has arrived.
*/
-int osrf_app_session_queue_wait( osrf_app_session*, int timeout );
+int osrf_app_session_queue_wait( osrf_app_session*, int timeout, int* recvd );
/** Disconnects (if client), frees any attached app_reuqests, removes the session from the
* global session cache and frees the session. Needless to say, only call this when the
/* this is the method we're gonna run */
int (*meth) (osrfMethodContext*);
- osrfLogInfo( OSRF_LOG_MARK, "Running method [%s] for app [%s] with request id %d and "
- "thread trace %s", methodName, appName, reqId, ses->session_id );
-
if( !(app = _osrfAppFindApplication(appName)) )
return osrfAppRequestRespondException( ses,
reqId, "Application not found: %s", appName );
}
return 0;
-
}
int osrfAppRequestRespondException( osrfAppSession* ses, int request, char* msg, ... ) {
osrfLogDebug( OSRF_LOG_MARK, "Entering keepalive loop for session %s", session->session_id );
int keepalive = child->keepalive;
int retval;
+ int recvd;
time_t start;
time_t end;
osrfLogDebug(OSRF_LOG_MARK,
"osrf_prefork calling queue_wait [%d] in keepalive loop", keepalive);
start = time(NULL);
- retval = osrf_app_session_queue_wait(session, keepalive);
+ retval = osrf_app_session_queue_wait(session, keepalive, &recvd);
end = time(NULL);
+ osrfLogDebug(OSRF_LOG_MARK, "Data received == %d", recvd);
+
if(retval) {
osrfLogError(OSRF_LOG_MARK, "queue-wait returned non-success %d", retval);
break;
/* see if the client disconnected from us */
if(session->state != OSRF_SESSION_CONNECTED) break;
- /* see if the used up the timeout */
- if( (end - start) >= keepalive ) {
-
- osrfLogDebug(OSRF_LOG_MARK, "Keepalive timed out, exiting connected session");
-
+ /* if no data was reveived within the timeout interval */
+ if( !recvd && (end - start) >= keepalive ) {
+ osrfLogInfo(OSRF_LOG_MARK, "No data was reveived in %d seconds, exiting stateful session", keepalive);
osrfAppSessionStatus(
session,
OSRF_STATUS_TIMEOUT,
osrf_message* _do_server( osrf_app_session*, osrf_message* );
/* tell osrf_app_session where the stack entry is */
-int (*osrf_stack_entry_point) (transport_client*, int) = &osrf_stack_process;
+int (*osrf_stack_entry_point) (transport_client*, int, int*) = &osrf_stack_process;
-int osrf_stack_process( transport_client* client, int timeout ) {
+int osrf_stack_process( transport_client* client, int timeout, int* msg_received ) {
if( !client ) return -1;
transport_message* msg = NULL;
+ if(msg_received) *msg_received = 0;
while( (msg = client_recv( client, timeout )) ) {
+ if(msg_received) *msg_received = 1;
osrfLogDebug( OSRF_LOG_MARK, "Received message from transport code from %s", msg->sender );
osrf_stack_transport_handler( msg, NULL );
timeout = 0;
case OSRF_STATUS_EXPFAILED:
osrf_app_session_reset_remote( session );
session->state = OSRF_SESSION_DISCONNECTED;
- /* set the session to 'stateful' then resend */
- // osrf_app_session_request_resend( session, msg->thread_trace );
return NULL;
case OSRF_STATUS_TIMEOUT:
-
int osrf_stack_application_handler( osrf_app_session* session, osrf_message* msg ) {
-
if(session == NULL || msg == NULL) return 0;
if(msg->m_type == RESULT && session->type == OSRF_SESSION_CLIENT) {
jsonObject* params = msg->_params;
osrfAppRunMethod( app, method, session, msg->thread_trace, params );
-
osrfMessageFree(msg);
return 1;
-
}
+
#define OSRF_MAX_MSGS_PER_PACKET 256
// -----------------------------------------------------------------------------
-int osrf_stack_process( transport_client* client, int timeout );
+int osrf_stack_process( transport_client* client, int timeout, int* msg_received );
osrfAppSession* osrf_stack_transport_handler( transport_message* msg, char* my_service );
int osrf_stack_message_handler( osrf_app_session* session, osrf_message* msg );
int osrf_stack_application_handler( osrf_app_session* session, osrf_message* msg );