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

nasa / trick / 25517184738

07 May 2026 07:23PM UTC coverage: 56.804% (+0.03%) from 56.772%
25517184738

Pull #2108

github

web-flow
Merge ca1fc0f9c into 5596f9063
Pull Request #2108: chore: Format #2106

39 of 67 new or added lines in 4 files covered. (58.21%)

7 existing lines in 3 files now uncovered.

12919 of 22743 relevant lines covered (56.8%)

297778.66 hits per line

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

77.59
/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() {
14✔
20

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

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

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

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

47
    if (status != 0) {
14✔
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()) {
12✔
61
        _session->set_log(true);
1✔
62
    }
63

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

68
    if (_vs->get_info_msg()) {
12✔
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);
12✔
75
    _vs->add_session( pthread_self(), _session );
12✔
76

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

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

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

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

98
            // Check to see if exit is necessary
99
            if (_session->get_exit_cmd() == true) {
26✔
100
                break;
6✔
101
            }
102

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

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

116
        exec_signal_terminate();
1✔
117

118
    } catch (const std::exception &ex) {
2✔
119
        message_publish(MSG_ERROR, "\nVARIABLE SERVER caught std::exception\n  DIAGNOSTIC: %s\n" ,
1✔
120
         ex.what()) ;
1✔
121
        
122
        exec_signal_terminate();
1✔
123

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

149
    if (_debug >= 3) {
9✔
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);
9✔
154
    // No return from this.
155
}
×
156

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