• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nasa / trick / 25459968639

06 May 2026 08:42PM UTC coverage: 55.916% (-0.8%) from 56.7%
25459968639

Pull #2011

github

web-flow
Merge f11412d5f into 7054e405e
Pull Request #2011: Single-file CI and code style adoption

14607 of 26123 relevant lines covered (55.92%)

466416.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.33
/trick_source/sim_services/VariableServer/VariableServerSessionThread_loop.cpp
1

2
#include <iostream>
3
#ifdef __linux__
4
#include <cxxabi.h>
5
#endif
6

7
#include "trick/VariableServer.hh"
8
#include "trick/message_proto.h"
9
#include "trick/realtimesync_proto.h"
10
#include "trick/ExecutiveException.hh"
11
#include "trick/exec_proto.h"
12

13
#include "trick/VariableServerSessionThread.hh"
14

15
extern Trick::VariableServer * the_vs ;
16

17
void exit_var_thread(void *in_vst) ;
18

19
void * Trick::VariableServerSessionThread::thread_body() {
8✔
20

21
    // Check for short running sims
22
    test_shutdown(NULL, NULL);
8✔
23

24
    //  We need to make the thread to VariableServerSessionThread map before we accept the connection.
25
    //  Otherwise we have a race where this thread is unknown to the variable server and the
26
    //  client gets confirmation that the connection is ready for communication.
27
    _vs->add_vst( pthread_self() , this ) ;
8✔
28

29
    // Accept client connection
30
    int status = _connection->start();
8✔
31

32
    std::string new_ip = _connection->getClientHostname() ;
8✔
33
    //check against allowlist
34
    //skip this check if connection failed, don't want an erroneous error
35
    if (!_vs->get_bypass_ip_check() && status != CONNECTION_FAIL) {
8✔
36
        bool valid_ip = _vs->check_ip(new_ip);
×
37

38
        if ( !valid_ip ) {
×
39
            std::string err_msg = "ILLEGAL IP CONNECTION ATTEMPTED: " + new_ip + "\n";
×
40
            message_publish(MSG_ERROR, err_msg.c_str()) ;
×
41
            status = CONNECTION_FAIL ;
×
42
        }
×
43
    }
44

45
    if (status != 0) {
8✔
46
        _vs->delete_vst(pthread_self());
1✔
47

48
        // Tell main thread that we failed to initialize
49
        pthread_mutex_lock(&_connection_status_mutex);
1✔
50
        _connection_status = CONNECTION_FAIL;
1✔
51
        pthread_cond_signal(&_connection_status_cv);
1✔
52
        pthread_mutex_unlock(&_connection_status_mutex);
1✔
53

54
        thread_shutdown();
1✔
55
    }
56

57
    // if log is set on for variable server (e.g., in input file), turn log on for each client
58
    if (_vs->get_log()) {
7✔
59
        _session->set_log(true);
×
60
    }
61

62
    if (_vs->get_session_log()) {
7✔
63
        _session->set_session_log(true);
1✔
64
    }
65

66
    if (_vs->get_info_msg()) {
7✔
67
        _session->set_info_message(true);
×
68
    }
69

70
    // Give the initialized connection to the session
71
    // Don't touch the connection anymore until we shut them both down
72
    _session->set_connection(_connection);
7✔
73
    _vs->add_session( pthread_self(), _session );
7✔
74

75
    // Tell main that we are ready
76
    pthread_mutex_lock(&_connection_status_mutex);
7✔
77
    _connection_status = CONNECTION_SUCCESS;
7✔
78
    pthread_cond_signal(&_connection_status_cv);
7✔
79
    pthread_mutex_unlock(&_connection_status_mutex);
7✔
80

81
    try {
82
        while (1) {
83
            // Shutdown here if it's time
84
            test_shutdown(exit_var_thread, (void *) this);
16✔
85

86
            // Pause here if we are in a restart condition
87
            test_pause();
14✔
88

89
            // Look for a message from the client
90
            // Parse and execute if one is availible
91
            int read_status = _session->handle_message();
14✔
92
            if ( read_status < 0 ) {
14✔
93
                break ;
1✔
94
            }
95

96
            // Check to see if exit is necessary
97
            if (_session->get_exit_cmd() == true) {
13✔
98
                break;
4✔
99
            }
100

101
            // Tell session it's time to copy and write if the mode is correct
102
            int ret =_session->copy_and_write_async(); 
9✔
103
            if (ret < 0) {
9✔
104
                break;
×
105
            }
106

107
            // Sleep for the appropriate cycle time
108
            usleep((unsigned int) (_session->get_update_rate() * 1000000));
9✔
109
        }
9✔
110
    } catch (Trick::ExecutiveException & ex ) {
2✔
111
        message_publish(MSG_ERROR, "\nVARIABLE SERVER COMMANDED exec_terminate\n  ROUTINE: %s\n  DIAGNOSTIC: %s\n" ,
×
112
         ex.file.c_str(), ex.message.c_str()) ;
113

114
        exec_signal_terminate();
×
115

116
    } catch (const std::exception &ex) {
×
117
        message_publish(MSG_ERROR, "\nVARIABLE SERVER caught std::exception\n  DIAGNOSTIC: %s\n" ,
×
118
         ex.what()) ;
×
119
        
120
        exec_signal_terminate();
×
121

122
#ifdef __linux__
123
#ifdef __GNUC__
124
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 2
125
    // for post gcc 4.1.2 or whatever glibc version is used in RHEL6 and above.
126
    } catch (abi::__forced_unwind&) {
2✔
127
        //pthread_exit and pthread_cancel will cause an abi::__forced_unwind to be thrown. Rethrow it.
128
        throw;
2✔
129
#endif
130
#endif
131
#endif
132
    } catch (...) {
2✔
133
#ifdef __linux__
134
#ifdef __GNUC__
135
#if (__GNUC__ == 4 && __GNUC_MINOR__ == 1) || __GNUC__ == 12
136
        // for gcc 4.1.2 or whatever glib version in RHEL 5 that does not work with the abi::__forced_unwind
137
        // Also seems to have a problem with gcc 12
138
        throw;
139
#else
140
        message_publish(MSG_ERROR, "\nVARIABLE SERVER caught unknown exception\n" ) ;
×
141
        exec_signal_terminate();
×
142
#endif
143
#endif
144
#endif
145
    }
×
146

147
    if (_debug >= 3) {
5✔
148
        message_publish(MSG_DEBUG, "%p tag=<%s> var_server receive loop exiting\n", _connection, _connection->getClientTag().c_str());
×
149
    }
150

151
    thread_shutdown(exit_var_thread, this);
5✔
152
    // No return from this.
153
}
8✔
154

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc