Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Include what you use
Browse files Browse the repository at this point in the history
There are a couple of things to call out here:

1. I have done this naively. We may want consumers of this API to only have to include <transport/transport.h> to get all/some subset of the <transport/*.h> headers. We can add a pragma to mark those as exported, that consumers of the API and ourselves will understand if they also run clang-tidy or IWYU.
2. On MacOS at least, IncludeCleaner suggests some private MacOS headers that contain the actual implementations rather than the more canonical UNIX headers. E.g timeval should come from sys/time.h not <sys/types/_timeval.h>. IWYU allows a mapping file to correct these, but clang-tidy's version doesn't seem to. I have marked them NOLINT for now.
  • Loading branch information
RichLogan committed Aug 15, 2024
1 parent 6ead4dd commit e906fa3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Checks: '
-*,
clang-analyzer-*,
misc-include-cleaner,
misc-misplaced-const,
performance-*,
readability-avoid-const-params-in-decls,
Expand Down
3 changes: 3 additions & 0 deletions src/transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <transport_picoquic.h>
#endif
#include <cantina/logger.h>
#include <memory>
#include <ostream>
#include <stdexcept>

namespace qtransport {

Expand Down
38 changes: 30 additions & 8 deletions src/transport_picoquic.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,47 @@
#include "transport_picoquic.h"

// PicoQuic.
#include <picoquic.h>
#include <picoquic_internal.h>
#include <picoquic_packet_loop.h>
#include <autoqlog.h>
#include <picoquic_utils.h>

#include <picoquic_config.h>
#include <picosocks.h>

// Transport.
#include "transport/transport.h"
#include "transport/transport_metrics.h"
#include "transport/safe_queue.h"
#include "transport/stream_buffer.h"
#include "transport/priority_queue.h"
#include "transport/span.h"
#include "transport/time_queue.h"
#include <cantina/logger.h>
#include <cantina/logger_macros.h>

// System.
#include <arpa/inet.h>
#include <sys/socket.h>
#include <cassert>
#include <cstring>
#include <ctime>
#include <iostream>
#include <thread>
#include <unistd.h>
#include <cstdint>
#include <optional>
#include <utility>
#include <memory>
#include <mutex>
#include <vector>
#include <string>
#include <chrono>
#include <sstream>
#include <stdexcept>

#include <arpa/inet.h>
#include <sys/select.h>
#include <netdb.h>
#if defined(__linux__)
#include <net/ethernet.h>
#include <netpacket/packet.h>
#elif defined(__APPLE__)
#include <net/if_dl.h>
#endif

using namespace qtransport;
Expand Down Expand Up @@ -836,7 +858,7 @@ PicoQuicTransport::ConnectionContext& PicoQuicTransport::createConnContext(picoq
/*(const void*)(&((struct sockaddr_in*)addr)->sin_addr),*/
conn_ctx.peer_addr_text,
sizeof(conn_ctx.peer_addr_text));
conn_ctx.peer_port = ntohs(((struct sockaddr_in*)addr)->sin_port);
conn_ctx.peer_port = ntohs(((struct sockaddr_in*)addr)->sin_port); // NOLINT (include)
break;

case AF_INET6:
Expand Down
37 changes: 28 additions & 9 deletions src/transport_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,40 @@
#include <iostream>
#include <thread>
#include <unistd.h>

#include <optional>
#include <memory>
#include <cstdint>
#include <mutex>
#include <utility>
#include <vector>
#include <chrono>
#include <string>
#include <sstream>
#include <stdexcept>

#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/select.h> // IWYU pragma: keep
#include <sys/time.h> // IWYU pragma: keep
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>

#if defined(__linux__)
#include <net/ethernet.h>
#include <netpacket/packet.h>
#elif defined(__APPLE__)

#include <net/if_dl.h>

#endif

#include "transport_udp.h"
#include "transport_udp_protocol.h"

#include "transport/transport.h"
#include "transport/time_queue.h"
#include "transport/transport_metrics.h"
#include "transport/uintvar.h"
#include "transport/priority_queue.h"
#include <cantina/logger.h>


#if defined(PLATFORM_ESP)
#include <lwip/netdb.h>
Expand Down Expand Up @@ -503,7 +522,7 @@ bool UDPTransport::send_data(ConnectionContext& conn, DataContext& data_ctx, con
* - loop reads data from fd_write_queue and writes it to the socket
*/
void UDPTransport::fd_writer() {
timeval to;
timeval to; // NOLINT (include).
to.tv_usec = 1000;
to.tv_sec = 0;

Expand Down Expand Up @@ -614,7 +633,7 @@ void UDPTransport::fd_writer() {
if (all_empty_count > 5) {
all_empty_count = 1;
to.tv_usec = 300;
select(0, NULL, NULL, NULL, &to);
select(0, NULL, NULL, NULL, &to); // NOLINT (include).
}
}

Expand Down Expand Up @@ -1134,7 +1153,7 @@ int err = 0;

struct sockaddr_in srvAddr;
srvAddr.sin_family = AF_INET;
srvAddr.sin_addr.s_addr = htonl(INADDR_ANY);
srvAddr.sin_addr.s_addr = htonl(INADDR_ANY); // NOLINT (include).
srvAddr.sin_port = 0;
err = bind(_fd, (struct sockaddr *) &srvAddr, sizeof(srvAddr));
if (err) {
Expand All @@ -1147,7 +1166,7 @@ int err = 0;
#endif
}

std::string sPort = std::to_string(htons(_serverInfo.port));
std::string sPort = std::to_string(htons(_serverInfo.port)); // NOLINT (include).
struct addrinfo hints = {}, *address_list = NULL;
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
Expand Down

0 comments on commit e906fa3

Please sign in to comment.