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

nasa / trick / 38950168522

16 Oct 2026 06:48PM UTC coverage: 56.879% (-0.005%) from 56.884%
38950168522

Pull #2225

github

web-flow
Merge f77fc6e50 into e101223ed
Pull Request #2225: fix: Resolve compilation warnings

5 of 32 new or added lines in 9 files covered. (15.63%)

14978 of 26333 relevant lines covered (56.88%)

483764.74 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() isn't marked noreturn,
56
        // add return NULL to be safe and match the code at end of function.
57
        thread_shutdown();
2 ✔
NEW
58
        return NULL;
×
59
    }
60

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

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

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

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

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

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

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

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

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

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

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

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

126
        exec_signal_terminate();
1 ✔
127

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

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

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

155
    thread_shutdown(exit_var_thread, this);
10 ✔
156
    // No return from this, but thread_shutdown() isn't marked noreturn, add return NULL to satisfy the compiler.
NEW
157
    return NULL;
×
158
}
17 ✔
159

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