Implement the sleep function for IrDA and bluetooth
This commit is contained in:
parent
ab37d94ee9
commit
680f233690
@ -110,7 +110,7 @@ static const dc_iostream_vtable_t dc_bluetooth_vtable = {
|
||||
dc_socket_write, /* write */
|
||||
NULL, /* flush */
|
||||
NULL, /* purge */
|
||||
NULL, /* sleep */
|
||||
dc_socket_sleep, /* sleep */
|
||||
dc_socket_close, /* close */
|
||||
};
|
||||
|
||||
|
||||
@ -102,7 +102,7 @@ static const dc_iostream_vtable_t dc_irda_vtable = {
|
||||
dc_socket_write, /* write */
|
||||
NULL, /* flush */
|
||||
NULL, /* purge */
|
||||
NULL, /* sleep */
|
||||
dc_socket_sleep, /* sleep */
|
||||
dc_socket_close, /* close */
|
||||
};
|
||||
#endif
|
||||
|
||||
22
src/socket.c
22
src/socket.c
@ -293,3 +293,25 @@ out:
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
dc_status_t
|
||||
dc_socket_sleep (dc_iostream_t *abstract, unsigned int timeout)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
Sleep (timeout);
|
||||
#else
|
||||
struct timespec ts;
|
||||
ts.tv_sec = (timeout / 1000);
|
||||
ts.tv_nsec = (timeout % 1000) * 1000000;
|
||||
|
||||
while (nanosleep (&ts, &ts) != 0) {
|
||||
int errcode = errno;
|
||||
if (errcode != EINTR ) {
|
||||
SYSERROR (abstract->context, errcode);
|
||||
return dc_socket_syserror (errcode);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
#include <sys/select.h> // select
|
||||
#include <sys/ioctl.h> // ioctl
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include <libdivecomputer/common.h>
|
||||
@ -113,6 +114,9 @@ dc_socket_read (dc_iostream_t *iostream, void *data, size_t size, size_t *actual
|
||||
dc_status_t
|
||||
dc_socket_write (dc_iostream_t *iostream, const void *data, size_t size, size_t *actual);
|
||||
|
||||
dc_status_t
|
||||
dc_socket_sleep (dc_iostream_t *abstract, unsigned int timeout);
|
||||
|
||||
dc_status_t
|
||||
dc_socket_close (dc_iostream_t *iostream);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user