Skip to content

Commit

Permalink
Fix Linux errors
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed May 23, 2021
1 parent 2ed68fb commit 0d8243b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
9 changes: 2 additions & 7 deletions examples/xcpsim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ set(SOURCES
../../src/hw/terminal.c
../../src/hw/options.c
../../flsemu/common.c
../../src/tl/eth/common.c
app_config.c
appl1.c
main.c
Expand Down Expand Up @@ -79,21 +78,17 @@ endif()

if (WIN32)
add_definitions(-DETHER)
add_executable(xcp_sim ${SOURCES} "../../src/tl/eth/wineth.c")
add_executable(xcp_sim ${SOURCES} "../../src/tl/eth/wineth.c" "../../src/tl/eth/common.c")
target_include_directories(xcp_sim PUBLIC ${INCLUDES})
target_link_libraries(xcp_sim ${ADD_LIBS})
target_compile_features(xcp_sim PRIVATE c_std_11)
elseif(UNIX)
#remove_definitions(-DSOCKET_CAN)
#add_definitions(-DETHER)
add_executable(xcp_sim_eth ${SOURCES} "../../src/tl/eth/linuxeth.c")
add_executable(xcp_sim_eth ${SOURCES} "../../src/tl/eth/linuxeth.c" "../../src/tl/eth/common.c")
target_compile_definitions(xcp_sim_eth PUBLIC ETHER)
target_include_directories(xcp_sim_eth PUBLIC ${INCLUDES})
target_link_libraries(xcp_sim_eth ${ADD_LIBS})
target_compile_features(xcp_sim_eth PRIVATE c_std_11)

#remove_definitions(-DETHER)
#add_definitions(-DSOCKET_CAN)
add_executable(xcp_sim_can ${SOURCES} "../../src/tl/can/linux_socket_can.c")
target_compile_definitions(xcp_sim_can PUBLIC SOCKET_CAN)
target_include_directories(xcp_sim_can PUBLIC ${INCLUDES})
Expand Down
17 changes: 12 additions & 5 deletions src/tl/eth/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#include "xcp_eth.h"

#if defined(__unix__)
#define SOCKET_ERROR (-1)
#define SOCKET_ERROR (-1)
#define ZeroMemory(b,l ) memset((b), 0, (l))
#endif

static void XcpTl_Accept(void);
Expand Down Expand Up @@ -116,14 +117,22 @@ void XcpTl_RxHandler(void)
XCP_FOREVER {
res = XcpTl_ReadHeader(&dlc, &counter);
if (res == -1) {
#if defined(_WIN32)
XcpHw_ErrorMsg("XcpTl_RxHandler:XcpTl_ReadHeader()", WSAGetLastError());
#elif defined(__unix__)
XcpHw_ErrorMsg("XcpTl_RxHandler:XcpTl_ReadHeader()", errno);
#endif
exit(2);
} else if (res == 0) {
return;
}
res = XcpTl_ReadData(&XcpTl_RxBuffer[0], dlc);
if (res == -1) {
#if defined(_WIN32)
XcpHw_ErrorMsg("XcpTl_RxHandler:XcpTl_ReadData()", WSAGetLastError());
#elif defined(__unix__)
XcpHw_ErrorMsg("XcpTl_RxHandler:XcpTl_ReadData()", errno);
#endif
exit(2);
} else if (res == 0) {
return;
Expand All @@ -145,13 +154,11 @@ static void XcpTl_Accept(void)
FromLen = sizeof(From);
XcpTl_Connection.connectedSocket = accept(XcpTl_Connection.boundSocket, (struct sockaddr *)&XcpTl_Connection.currentAddress, &FromLen);
if (XcpTl_Connection.connectedSocket == -1) {
XcpHw_ErrorMsg("XcpTl_RxHandler::accept()", errno);
//WSACleanup();
XcpHw_ErrorMsg("XcpTl_Accept::accept()", errno);
exit(1);
return;
}
} else {
}

}
}

Expand Down
3 changes: 1 addition & 2 deletions src/tl/eth/linuxeth.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

socklen_t addrSize = sizeof(struct sockaddr_storage);

static XcpTl_ConnectionType XcpTl_Connection;
extern XcpTl_ConnectionType XcpTl_Connection;

static bool Xcp_EnableSocketOption(int sock, int option);
static bool Xcp_DisableSocketOption(int sock, int option);
Expand Down Expand Up @@ -113,7 +113,6 @@ void XcpTl_Init(void)
if (!Xcp_EnableSocketOption(XcpTl_Connection.boundSocket, SO_REUSEADDR)) {
XcpHw_ErrorMsg("XcpTl_Init:setsockopt(SO_REUSEADDR)", errno);
}

}

void XcpTl_DeInit(void)
Expand Down

0 comments on commit 0d8243b

Please sign in to comment.