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

nasa / trick / 32310771142

19 Aug 2026 10:52PM UTC coverage: 56.777% (+0.02%) from 56.76%
32310771142

Pull #2190

github

web-flow
Merge 1ceb274b2 into ebaf92acc
Pull Request #2190: Remove dead and deprecated code.

10 of 33 new or added lines in 5 files covered. (30.3%)

53 existing lines in 3 files now uncovered.

14954 of 26338 relevant lines covered (56.78%)

479334.24 hits per line

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

82.26
/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() {
17✔
20

21
    // Check for short running sims
22
    test_shutdown(NULL, NULL);
17✔
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 ) ;
17✔
28

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

32
    std::string new_ip = _connection->getClientHostname();
17✔
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)
17✔
36
    {
37
        bool valid_ip = _vs->check_ip(new_ip);
2✔
38

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

47
    if (status != 0) {
17✔
48
        _vs->delete_vst(pthread_self());
2✔
49

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

56
        thread_shutdown();
2✔
57
    }
58

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

64
    if (_vs->get_session_log()) {
15✔
65
        _session->set_session_log(true);
6✔
66
    }
67

68
    if (_vs->get_info_msg()) {
15✔
69
        _session->set_info_message(true);
×
70
    }
71

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

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

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

88
            // Pause here if we are in a restart condition
89
            test_pause();
756✔
90

91
            // If the variable server has been disabled (possibly at runtime), stop
92
            // servicing this client. No commands are read or executed and the session
93
            // disconnects. Broadcasting continues independently from the listen thread.
94
            if (!_vs->get_enabled())
756✔
95
            {
96
                break;
×
97
            }
98

99
            // Look for a message from the client
100
            // Parse and execute if one is availible
101
            int read_status = _session->handle_message();
756✔
102
            if ( read_status < 0 ) {
754✔
103
                break ;
1✔
104
            }
105

106
            // Check to see if exit is necessary
107
            if (_session->get_exit_cmd() == true) {
753✔
108
                break;
7✔
109
            }
110

111
            // Tell session it's time to copy and write if the mode is correct
112
            int ret =_session->copy_and_write_async(); 
746✔
113
            if (ret < 0) {
746✔
114
                break;
×
115
            }
116

117
            // Sleep for the appropriate cycle time
118
            usleep((unsigned int) (_session->get_update_rate() * 1000000));
746✔
119
        }
746✔
120
    } catch (Trick::ExecutiveException & ex ) {
7✔
121
        message_publish(MSG_ERROR, "\nVARIABLE SERVER COMMANDED exec_terminate\n  ROUTINE: %s\n  DIAGNOSTIC: %s\n" ,
1✔
122
         ex.file.c_str(), ex.message.c_str()) ;
123

124
        exec_signal_terminate();
1✔
125

126
    } catch (const std::exception &ex) {
2✔
127
        message_publish(MSG_ERROR, "\nVARIABLE SERVER caught std::exception\n  DIAGNOSTIC: %s\n" ,
1✔
128
         ex.what()) ;
1✔
129
        
130
        exec_signal_terminate();
1✔
131

132
#ifdef __linux__
133
    } catch (abi::__forced_unwind&) {
6✔
134
        //pthread_exit and pthread_cancel will cause an abi::__forced_unwind to be thrown. Rethrow it.
135
        throw;
5✔
136
#endif
137
    } catch (...) {
5✔
138
#ifdef __linux__
139
#if __GNUC__ == 12
140
        // gcc 12 seems to have a problem with the abi::__forced_unwind catch above.
141
        throw;
142
#else
143
        message_publish(MSG_ERROR, "\nVARIABLE SERVER caught unknown exception\n" ) ;
×
144
        exec_signal_terminate();
×
145
#endif
146
#endif
UNCOV
147
    }
×
148

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

153
    thread_shutdown(exit_var_thread, this);
10✔
154
    // No return from this.
155
}
17✔
156

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

© 2026 Coveralls, Inc