Skip to content

Commit

Permalink
Minor fix for re-bind and remove debug print.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobMeades committed Mar 10, 2024
1 parent 2d39de3 commit 99995bd
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions port/platform/linux/src/u_port_ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,6 @@ static void socketTask(void *pParameters)
if ((dataSize > 0) &&
(pPppInterface->pTransmitCallback != NULL) &&
!pPppInterface->dataTransferSuspended) {
for (size_t rob = 0; rob < dataSize; rob++) {
uPortLog(" 0x%02x", buffer[rob]);
}
uPortLog("\n");
// Write the data to the cellular module
retryCount = 0;
pData = buffer;
Expand Down Expand Up @@ -525,6 +521,7 @@ static int32_t startSocketTask(uPortPppInterface_t *pPppInterface,
int32_t errorCode;
struct sockaddr_in socketAddress = {0};
uSockAddress_t sockUbxlib;
int reuse = 1;

errorCode = uSockStringToAddress(pAddressString, &sockUbxlib);
if (errorCode == 0) {
Expand All @@ -533,6 +530,24 @@ static int32_t startSocketTask(uPortPppInterface_t *pPppInterface,
pPppInterface->connectedSocket = -1;
pPppInterface->listeningSocket = socket(AF_INET, SOCK_STREAM, 0);
if (pPppInterface->listeningSocket >= 0) {
if (setsockopt(pPppInterface->listeningSocket, SOL_SOCKET, SO_REUSEADDR,
(const char*) &reuse, sizeof(reuse)) < 0) {
// This is not fatal, it just means that the OS might prevent
// us binding to the same address again if we come back into
// here too quickly
uPortLog("U_PORT_PPP: *** WARNING *** setting socket option SO_REUSEADDR"
" returned errno %d.\n", errno);
}
#ifdef SO_REUSEPORT
if (setsockopt(pPppInterface->listeningSocket, SOL_SOCKET, SO_REUSEPORT,
(const char*) &reuse, sizeof(reuse)) < 0) {
// This is not fatal, it just means that the OS might prevent
// us binding to the same address again if we come back into
// here too quickly
uPortLog("U_PORT_PPP: *** WARNING *** setting socket option SO_REUSEPORT"
" returned errno %d.\n", errno);
}
#endif
errorCode = (int32_t) U_ERROR_COMMON_INVALID_ADDRESS;
socketAddress.sin_family = AF_INET;
if (sockUbxlib.ipAddress.type == U_SOCK_ADDRESS_TYPE_V4) {
Expand All @@ -541,6 +556,8 @@ static int32_t startSocketTask(uPortPppInterface_t *pPppInterface,
// TODO: find out how this copy should work for an IPV6 address
errorCode = (int32_t) U_ERROR_COMMON_NOT_SUPPORTED;
}
// Set SO_REUSEADDR (and, in some cases SO_REUSEPORT) so that we
// can re-bind to the socket when we come back into here
socketAddress.sin_port = htons(sockUbxlib.port);
if (bind(pPppInterface->listeningSocket,
(struct sockaddr *) &socketAddress,
Expand Down

0 comments on commit 99995bd

Please sign in to comment.