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

nasa / trick / 42117787261

05 Nov 2026 10:00PM UTC coverage: 56.988% (-0.008%) from 56.996%
42117787261

push

github

web-flow
fix: Resolve compilation warnings (#2225)

5 of 36 new or added lines in 9 files covered. (13.89%)

1 existing line in 1 file now uncovered.

14985 of 26295 relevant lines covered (56.99%)

481005.11 hits per line

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

79.69
/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
        // No return from this, but thread_shutdown() is virtual and intentionally
56
        // not marked [[noreturn]] (not guaranteed across overrides).
57
        // Add return NULL to be safe and match the end of the function.
58
        thread_shutdown();
2 ✔
NEW
59
        return NULL;
×
60
    }
61

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

67
    if (_vs->get_session_log()) {
15 ✔
68
        _session->set_session_log(true);
5 ✔
69
    }
70

71
    if (_vs->get_info_msg()) {
15 ✔
72
        _session->set_info_message(true);
×
73
    }
74

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

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

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

91
            // Pause here if we are in a restart condition
92
            test_pause();
756 ✔
93

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

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

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

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

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

127
        exec_signal_terminate();
1 ✔
128

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

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

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

156
    thread_shutdown(exit_var_thread, this);
10 ✔
157
    // No return from this, but thread_shutdown() is virtual and intentionally
158
    // not marked [[noreturn]] (not guaranteed across overrides).
159
    // Return NULL to satisfy the compiler and stay safe.
NEW
160
    return NULL;
×
161
}
17 ✔
162

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