doing better job of propogating network errors up the stack
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 1 Sep 2006 21:29:43 +0000 (21:29 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Fri, 1 Sep 2006 21:29:43 +0000 (21:29 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@774 9efc2488-bf62-4759-914b-345cdb29e865

src/gateway/osrf_json_gateway.c
src/libstack/osrf_app_session.c
src/libstack/osrf_stack.c
src/libtransport/transport_client.c
src/libtransport/transport_client.h
src/libtransport/transport_session.c
src/utils/socket_bundle.c

index 213ea52..3e15742 100644 (file)
@@ -164,6 +164,16 @@ static int osrf_json_gateway_method_handler (request_rec *r) {
 
                double starttime = get_timestamp_millis();
                int req_id = osrf_app_session_make_req( session, NULL, method, api_level, mparams );
+
+
+               if( req_id == -1 ) {
+                       osrfLogError(OSRF_LOG_MARK, "I am unable to communcate with opensrf..going away...");
+                       /* we don't want to spawn an intense re-forking storm 
+                        * if there is no jabber server.. so give it some time before we die */
+                       sleep(1); 
+                       exit(1);
+               }
+
                osrf_message* omsg = NULL;
 
                int statuscode = 200;
index e9b88e1..008f25f 100644 (file)
@@ -525,6 +525,8 @@ int osrfAppSessionSendBatch( osrfAppSession* session, osrf_message* msgs[], int
                                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");
        
                free(string);
                message_free( t_msg );
index ee3254c..2e5027c 100644 (file)
@@ -17,6 +17,11 @@ int osrf_stack_process( transport_client* client, int timeout ) {
                timeout = 0;
        }
 
+       if( client->error ) {
+               osrfLogWarning(OSRF_LOG_MARK, "transport_client had trouble reading from the socket..");
+               return -1;
+       }
+
        if( ! client_connected( client ) ) return -1;
 
        return 0;
index c5f30e3..4c91581 100644 (file)
@@ -61,6 +61,7 @@ transport_client* client_init( char* server, int port, char* unix_path, int comp
        client->session = init_transport( server, port, unix_path, client, component );
 
        client->session->message_callback = client_message_handler;
+       client->error = 0;
 
        return client;
 }
@@ -87,6 +88,7 @@ int client_connected( transport_client* client ) {
 
 int client_send_message( transport_client* client, transport_message* msg ) {
        if(client == NULL) return 0;
+       if( client->error ) return -1;
        return session_send_msg( client->session, msg );
 }
 
@@ -115,6 +117,7 @@ transport_message* client_recv( transport_client* client, int timeout ) {
                        int x;
                        if( (x = session_wait( client->session, -1 )) ) {
                                osrfLogWarning(OSRF_LOG_MARK, "session_wait returned failure code %d\n", x);
+                               client->error = 1;
                                return NULL;
                        }
                }
@@ -131,8 +134,11 @@ transport_message* client_recv( transport_client* client, int timeout ) {
                int wait_ret;
                while( client->m_list->next == NULL && remaining >= 0 ) {
 
-                       if( (wait_ret= session_wait( client->session, remaining)) ) 
+                       if( (wait_ret= session_wait( client->session, remaining)) ) {
+                               client->error = 1;
+                               osrfLogWarning(OSRF_LOG_MARK, "session_wait returned failure code %d: setting error=1\n", wait_ret);
                                return NULL;
+                       }
 
                        ++counter;
 
index 4d37cc4..aa0b921 100644 (file)
@@ -31,6 +31,7 @@ typedef struct message_list_struct transport_message_node;
 struct transport_client_struct {
        transport_message_list* m_list;
        transport_session* session;
+       int error;
 };
 typedef struct transport_client_struct transport_client;
 
index 3de292f..9351c20 100644 (file)
@@ -117,6 +117,7 @@ int session_wait( transport_session* session, int timeout ) {
        int ret =  socket_wait( session->sock_mgr, timeout, session->sock_id );
 
        if( ret ) {
+               osrfLogError(OSRF_LOG_MARK, "socket_wait returned error code %d", ret);
                session->state_machine->connected = 0;
        }
        return ret;
index 73cecb4..a8f2aad 100644 (file)
@@ -661,8 +661,8 @@ int _socket_handle_client_data(socket_manager* mgr, socket_node* node) {
        if(read_bytes == 0) {  /* socket closed by client */
                if(mgr->on_socket_closed) {
                        mgr->on_socket_closed(mgr->blob, sock_fd);
-                       return -1;
                }
+               return -1;
        }
 
        return 0;