Skip to content

Commit 5d9e68d

Browse files
committed
Normalize debug macros and private header guard
Standardize debug macro names across files (DEBUG_NET_NETIF -> DEBUG_NETIF, DEBUG_NET_TCP -> DEBUG_TCP, DEBUG_NET_UDP -> DEBUG_UDP). Rename include guard in network_private.h to NETWORK_PRIVATE_H_, implement a simple Error() that prints messages and add an ERROR() macro, and replace direct network::Error(...) calls with ERROR(...). Add conditional guard around TCP optimization pragmas (CONFIG_TCP_NO_OPTIMIZE). Minor formatting and control-flow cleanups, and add /lib-network/include/noemac to .gitignore.
1 parent a35b859 commit 5d9e68d

5 files changed

Lines changed: 19 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ compile_commands.json
6262
/common/scripts/gd32/venv
6363
software_version_id.h
6464
lib-remoteconfig/http/content/generate_content
65+
/lib-network/include/noemac

lib-network/src/core/netif.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* THE SOFTWARE.
2424
*/
2525

26-
#if defined(DEBUG_NET_NETIF)
26+
#if defined(DEBUG_NETIF)
2727
#undef NDEBUG
2828
#endif
2929

lib-network/src/core/network_private.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
* THE SOFTWARE.
2424
*/
2525

26-
#ifndef NET_NET_PRIVATE_H_
27-
#define NET_NET_PRIVATE_H_
26+
#ifndef NETWORK_PRIVATE_H_
27+
#define NETWORK_PRIVATE_H_
2828

2929
#include <cstdint>
3030
#include <cstdio>
@@ -33,7 +33,6 @@
3333
#include "core/protocol/igmp.h"
3434
#include "core/protocol/udp.h"
3535
#include "core/protocol/tcp.h"
36-
3736
#include "net_platform.h" // IWYU pragma: keep
3837

3938
#ifndef ALIGNED
@@ -53,9 +52,11 @@ void FreePkt();
5352
} // namespace emac::eth
5453

5554
namespace network {
56-
inline void Error([[maybe_unused]] const char* func, [[maybe_unused]] const char* s) {}
55+
inline void Error(const char* func, const char* s) {
56+
printf("%s: %s\n", func, s);
57+
}
5758

58-
#define ERROR(s) Error(__func__, (s))
59+
#define ERROR(s) Error(__func__, (s))
5960

6061
namespace global {
6162
extern uint32_t broadcast_mask;
@@ -125,4 +126,4 @@ void Run();
125126
} // namespace tcp
126127
} // namespace network
127128

128-
#endif // NET_NET_PRIVATE_H_
129+
#endif // NETWORK_PRIVATE_H_

lib-network/src/core/tcp.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,19 @@
4343
* - Zero-window probing
4444
*/
4545

46-
#if defined(DEBUG_NET_TCP)
46+
#if defined(DEBUG_TCP)
4747
#undef NDEBUG
4848
#endif
4949
#pragma GCC diagnostic push
5050
#if (__GNUC__ < 10)
5151
#pragma GCC diagnostic ignored "-Wconversion"
5252
#pragma GCC diagnostic ignored "-Wsign-conversion"
5353
#endif
54+
#if !defined(CONFIG_TCP_NO_OPTIMIZE)
5455
#pragma GCC push_options
5556
#pragma GCC optimize("O2")
5657
#pragma GCC optimize("no-tree-loop-distribute-patterns")
58+
#endif
5759

5860
#include <cstdint>
5961
#include <cstring>
@@ -1494,15 +1496,15 @@ static uint16_t s_local_port = kLocalPortRangeStart;
14941496
ConnHandle Connect(uint32_t remote_ip, uint16_t remote_port, CallbackConnect cb_connect, CallbackData cb_data, void* context) {
14951497
const auto& netif = netif::global::netif_default;
14961498
if (__builtin_expect((netif.ip.addr == 0), 0)) {
1497-
network::Error(__func__, "Connect: No ip!");
1499+
ERROR("Connect: No ip!");
14981500
return kInvalidConnHandle;
14991501
}
15001502

15011503
uint32_t out_index = 0;
15021504

15031505
auto* tcb = AllocTcb(remote_port, &out_index);
15041506
if (tcb == nullptr) {
1505-
network::Error(__func__, "Connect: No TCB!");
1507+
ERROR("Connect: No TCB!");
15061508
return kInvalidConnHandle;
15071509
}
15081510

@@ -1542,14 +1544,14 @@ ConnHandle Connect(uint32_t remote_ip, uint16_t remote_port, CallbackConnect cb_
15421544
int32_t Close(ConnHandle conn_handle) // graceful FIN
15431545
{
15441546
if (conn_handle >= TCP_MAX_TCBS_ALLOWED) {
1545-
network::Error(__func__, "Close: Connection handle!");
1547+
ERROR("Close: Connection handle!");
15461548
return -1;
15471549
}
15481550

15491551
auto* c = &s_tcbs[conn_handle];
15501552

15511553
if (!c->in_use || c->state == kStateClosed) {
1552-
network::Error(__func__, "Close: TCB!");
1554+
ERROR("Close: TCB!");
15531555
return -1;
15541556
}
15551557

@@ -1568,7 +1570,7 @@ int32_t Close(ConnHandle conn_handle) // graceful FIN
15681570

15691571
// We only support graceful close from states where FIN makes sense here.
15701572
if (c->state != kStateEstablished && c->state != kStateCloseWait) {
1571-
network::Error(__func__, "Close: Not graceful!");
1573+
ERROR("Close: Not graceful!");
15721574
return -1;
15731575
}
15741576

@@ -1588,8 +1590,7 @@ int32_t Close(ConnHandle conn_handle) // graceful FIN
15881590

15891591
if (c->state == kStateEstablished) {
15901592
NEW_STATE(c, kStateFinWait1);
1591-
} else /* kStateCloseWait */
1592-
{
1593+
} else {
15931594
NEW_STATE(c, kStateLastAck);
15941595
}
15951596

lib-network/src/core/udp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
#include "core/protocol/ethernet.h"
27-
#if defined(DEBUG_NET_UDP)
27+
#if defined(DEBUG_UDP)
2828
#undef NDEBUG
2929
#endif
3030

0 commit comments

Comments
 (0)