Skip to content

Commit

Permalink
Ticket #307: Avoid vos functions to block TimeSync
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.code.sf.net/p/tcnopen/trdp/trunk@2140 3b5a3598-5f4e-4449-9e63-bd40438bfec0
  • Loading branch information
andersoberg committed Dec 17, 2019
1 parent f365d47 commit ea34fd0
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 85 deletions.
4 changes: 4 additions & 0 deletions trdp/src/vos/windows_sim/vos_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/*
* $Id$
*
* AÖ 2019-12-18: Ticket #307: Avoid vos functions to block TimeSync
* AÖ 2019-11-11: Ticket #290: Add support for Virtualization on Windows, copy from windows VOS
*/

Expand Down Expand Up @@ -53,6 +54,9 @@ extern "C" {

#define MAX_SEM_COUNT 10

#define TS_POLLING_TIME_US 100000
#define INF_TIMEOUT 0xffffffffu

struct VOS_MUTEX
{
UINT32 magicNo;
Expand Down
78 changes: 54 additions & 24 deletions trdp/src/vos/windows_sim/vos_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
/*
* $Id$*
*
* AÖ 2019-11-18: Ticket #295 vos_sockSendUDP some times report err 183 in Windows Sim
* AÖ 2019-12-18: Ticket #307: Avoid vos functions to block TimeSync
* AÖ 2019-12-18: Ticket #295: vos_sockSendUDP some times report err 183 in Windows Sim
* AÖ 2019-11-11: Ticket #290: Add support for Virtualization on Windows
*
*/
Expand All @@ -46,6 +47,7 @@
#include "vos_sock.h"
#include "vos_thread.h"
#include "vos_mem.h"
#include "vos_private.h"
#include "SimSocket.h"

#pragma comment(lib, "Ws2_32.lib")
Expand Down Expand Up @@ -549,41 +551,68 @@ EXT_DECL BOOL8 vos_netIfUp (
* @retval number of ready file descriptors
*/

EXT_DECL INT32 vos_select (
EXT_DECL INT32 vos_select(
SOCKET highDesc,
VOS_FDS_T *pReadableFD,
VOS_FDS_T *pWriteableFD,
VOS_FDS_T *pErrorFD,
VOS_TIMEVAL_T *pTimeOut)
VOS_FDS_T* pReadableFD,
VOS_FDS_T* pWriteableFD,
VOS_FDS_T* pErrorFD,
VOS_TIMEVAL_T* pTimeOut)
{
int ret = -1;
sim_fd_set readFds;
sim_fd_set writeFds;
sim_fd_set errorFds;
sim_fd_set *pReadFds = &readFds;
sim_fd_set *pWriteFds = &writeFds;
sim_fd_set *pErrorFds = &errorFds;
sim_fd_set* pReadFds = &readFds;
sim_fd_set* pWriteFds = &writeFds;
sim_fd_set* pErrorFds = &errorFds;

/* Copy to sim_fd_set */
if (vosFdsToSimFds(pReadableFD, &pReadFds) != 0)
//In simulation use polling
{
return -1;
}
if(vosFdsToSimFds(pWriteableFD, &pWriteFds) != 0)
{
return -1;
}
if(vosFdsToSimFds(pErrorFD, &pErrorFds) != 0)
{
return -1;
}
VOS_TIMEVAL_T delyTime;
delyTime.tv_sec = 0;
delyTime.tv_usec = TS_POLLING_TIME_US;
VOS_TIMEVAL_T remTime = *pTimeOut;
VOS_TIMEVAL_T delyNull;
delyNull.tv_sec = 0;
delyNull.tv_usec = 0;

do
{
/* Copy to sim_fd_set */
if (vosFdsToSimFds(pReadableFD, &pReadFds) != 0)
{
return -1;
}
if (vosFdsToSimFds(pWriteableFD, &pWriteFds) != 0)
{
return -1;
}
if (vosFdsToSimFds(pErrorFD, &pErrorFds) != 0)
{
return -1;
}

ret = SimSelect((int)highDesc, pReadFds, pWriteFds,
pErrorFds, (struct timeval *) pTimeOut);
ret = SimSelect((int)highDesc, pReadFds, pWriteFds,
pErrorFds, (struct timeval*) &delyNull);

if (vos_cmpTime(&remTime, &delyTime) == -1)
{
//remTime < delyTime
vos_threadDelay(remTime.tv_usec);
vos_subTime(&remTime, &remTime);
}
else
{
vos_threadDelay(delyTime.tv_usec);
vos_subTime(&remTime, &delyTime);
}
} while (ret == 0 && (remTime.tv_sec != 0 || remTime.tv_usec != 0));
}

if (ret == -1)
{
int err = GetLastError();
int err = GetLastError();
vos_printLog(VOS_LOG_ERROR, "SimSelect() failed (Err: %d)\n", err);
}

Expand Down Expand Up @@ -1261,11 +1290,12 @@ EXT_DECL VOS_ERR_T vos_sockBind (

/* Dynamic ports not supported in SimSocket, we have to try
until we find a free port.*/

if (port == 0)
{
srcAddress.sin_port = vos_htons(dynPortNr++);
}

ret = VOS_NO_ERR;

do
Expand Down
Loading

0 comments on commit ea34fd0

Please sign in to comment.