Change style of if block with single statement
Reset rx_empty_counter in uart_open()
This commit is contained in:
wh201906 2023-12-27 22:13:26 +08:00
commit e5dd9952d7
No known key found for this signature in database
2 changed files with 18 additions and 8 deletions

View file

@ -90,6 +90,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
} }
sp->udpBuffer = NULL; sp->udpBuffer = NULL;
rx_empty_counter = 0;
// init timeouts // init timeouts
timeout.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000; timeout.tv_usec = UART_FPC_CLIENT_RX_TIMEOUT_MS * 1000;
g_conn.send_via_local_ip = false; g_conn.send_via_local_ip = false;
@ -157,10 +158,12 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
} }
// for bind option, it's possible to only specify address or port // for bind option, it's possible to only specify address or port
if (strlen(bindAddrStr) == 0) if (strlen(bindAddrStr) == 0) {
bindAddrStr = NULL; bindAddrStr = NULL;
if (bindPortStr != NULL && strlen(bindPortStr) == 0) }
if (bindPortStr != NULL && strlen(bindPortStr) == 0) {
bindPortStr = NULL; bindPortStr = NULL;
}
} }
const char *addrStr = NULL; const char *addrStr = NULL;
@ -208,8 +211,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
for (rp = addr; rp != NULL; rp = rp->ai_next) { for (rp = addr; rp != NULL; rp = rp->ai_next) {
sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sfd == -1) if (sfd == -1) {
continue; continue;
}
if (!uart_bind(&sfd, bindAddrStr, bindPortStr, isBindingIPv6)) { if (!uart_bind(&sfd, bindAddrStr, bindPortStr, isBindingIPv6)) {
PrintAndLogEx(ERR, "error: Could not bind. errno: %d", errno); PrintAndLogEx(ERR, "error: Could not bind. errno: %d", errno);
@ -220,8 +224,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) {
break; break;
}
close(sfd); close(sfd);
} }

View file

@ -93,6 +93,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
} }
sp->udpBuffer = NULL; sp->udpBuffer = NULL;
rx_empty_counter = 0;
g_conn.send_via_local_ip = false; g_conn.send_via_local_ip = false;
g_conn.send_via_ip = PM3_NONE; g_conn.send_via_ip = PM3_NONE;
@ -149,10 +150,12 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
} }
// for bind option, it's possible to only specify address or port // for bind option, it's possible to only specify address or port
if (strlen(bindAddrStr) == 0) if (strlen(bindAddrStr) == 0) {
bindAddrStr = NULL; bindAddrStr = NULL;
if (bindPortStr != NULL && strlen(bindPortStr) == 0) }
if (bindPortStr != NULL && strlen(bindPortStr) == 0) {
bindPortStr = NULL; bindPortStr = NULL;
}
} }
const char *addrStr = NULL; const char *addrStr = NULL;
@ -211,8 +214,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
for (rp = addr; rp != NULL; rp = rp->ai_next) { for (rp = addr; rp != NULL; rp = rp->ai_next) {
hSocket = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); hSocket = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (hSocket == INVALID_SOCKET) if (hSocket == INVALID_SOCKET) {
continue; continue;
}
if (!uart_bind(&hSocket, bindAddrStr, bindPortStr, isBindingIPv6)) { if (!uart_bind(&hSocket, bindAddrStr, bindPortStr, isBindingIPv6)) {
PrintAndLogEx(ERR, "error: Could not bind. error: %u", WSAGetLastError()); PrintAndLogEx(ERR, "error: Could not bind. error: %u", WSAGetLastError());
@ -225,8 +229,9 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
if (connect(hSocket, rp->ai_addr, (int)rp->ai_addrlen) != INVALID_SOCKET) if (connect(hSocket, rp->ai_addr, (int)rp->ai_addrlen) != INVALID_SOCKET) {
break; break;
}
closesocket(hSocket); closesocket(hSocket);
hSocket = INVALID_SOCKET; hSocket = INVALID_SOCKET;