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

mavlink / MAVSDK / 10059975553

23 Jul 2024 01:33PM UTC coverage: 37.622% (+0.09%) from 37.537%
10059975553

Pull #2357

github

web-flow
Merge 0b6ca6e1b into f1aff89a6
Pull Request #2357: core: Correctly close sockets

43 of 46 new or added lines in 5 files covered. (93.48%)

17 existing lines in 2 files now uncovered.

11469 of 30485 relevant lines covered (37.62%)

260.35 hits per line

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

85.71
/src/mavsdk/core/socket_holder.cpp
1
#include "socket_holder.h"
2

3
#ifndef WINDOWS
4
#include <sys/socket.h>
5
#include <unistd.h>
6
#endif
7

8
namespace mavsdk {
9

NEW
10
SocketHolder::SocketHolder(int fd) noexcept :
×
NEW
11
    _fd{fd}
×
NEW
12
{}
×
13

14
SocketHolder::~SocketHolder() noexcept
142✔
15
{
16
    close();
71✔
17
}
71✔
18

19
void SocketHolder::reset(int fd) noexcept
71✔
20
{
21
    if (_fd != fd) {
71✔
22
        close();
71✔
23
        _fd = fd;
71✔
24
    }
25
}
71✔
26

27
void SocketHolder::close() noexcept
213✔
28
{
29
    if (!empty()) {
213✔
30
#if defined(WINDOWS)
31
        shutdown(_fd, SD_BOTH);
32
        closesocket(_fd);
33
        WSACleanup();
34
#else
35
        // This should interrupt a recv/recvfrom call.
36
        shutdown(_fd, SHUT_RDWR);
71✔
37

38
        // But on Mac, closing is also needed to stop blocking recv/recvfrom.
39
        ::close(_fd);
71✔
40
#endif
41
    }
42
    _fd = invalid_socket_fd;
213✔
43
}
213✔
44

45
bool SocketHolder::empty() const noexcept
284✔
46
{
47
    return _fd == invalid_socket_fd;
284✔
48
}
49

50
int SocketHolder::get() const noexcept
41,957✔
51
{
52
    return _fd;
41,957✔
53
}
54
    
55
} // namespace mavsdk
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

© 2025 Coveralls, Inc