Re: Highres delay help
From: A. Melinte (nospam_at_nospam.com)
Date: 05/27/05
- Next message: David Schwartz: "Re: Highres delay help"
- Previous message: Paul Keinanen: "Re: Suggestions for custom application-layer protocol?"
- In reply to: Carl W: "Highres delay help"
- Next in thread: David Schwartz: "Re: Highres delay help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 27 May 2005 14:01:18 -0400
"Carl W" <calle79@inorbit.com> wrote in message
news:c6416781.0505270421.5ff3ef02@posting.google.com...
> Dear all.
>
> I need a way to implement a high resolution delay with at least a
> resolution of 1 ms.
You can use select() to have a microsec resolution in a portable way:
/* restart select if call interrupted */
static int
rselect( int n, fd_set *rds, fd_set *wds, fd_set *eds, struct timeval
*tout )
{
int rc;
do {
rc = select( n, rds, wds, eds, tout );
} while ( rc == -1 && errno == EINTR );
return rc;
}
int
microsleep( int sock, int microsec )
{
struct timeval tv;
fd_set rfs, wfs, efs;
int ret;
tv.tv_sec = 0;
tv.tv_usec = microsec;
if ( sock == CFGST_INVALID_SOCKET ) {
ret = rselect( 0, NULL, NULL, NULL, &tv );
} else {
FD_ZERO( &rfs ); FD_SET( sock, &rfs );
FD_ZERO( &wfs ); //FD_SET( sock, &wfs );
FD_ZERO( &efs ); //FD_SET( sock, &efs );
ret = rselect( sock+1, &rfs, &wfs, &efs, &tv );
}
return ret;
}
- Next message: David Schwartz: "Re: Highres delay help"
- Previous message: Paul Keinanen: "Re: Suggestions for custom application-layer protocol?"
- In reply to: Carl W: "Highres delay help"
- Next in thread: David Schwartz: "Re: Highres delay help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|