From 2af0d43ce885880d8b8c63d0c2c4a2c56545f3d5 Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Wed, 2 Oct 2013 16:38:54 +0200 Subject: Add tox_wait() for socket, allow tox.h include in tox.c tox.*, Messenger.*, network.*; - new function tox_wait() => waitMessenger() => networking_wait(): - waits for a given amount of time for any sort of socket activity - mustn't change anything inside, mustn't poll or do other stuff - the point is to be able to call this asynchronously from a second thread - the outside shall follow up with an immediate tox_do() when there's socket activity tox.*: - allow inclusion of tox.h into tox.c, ensuring that the outside interface and the internal always match util.c: - squished a few warnings about questionable format strings --- toxcore/Messenger.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'toxcore/Messenger.c') diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index c8d69494..54ee6cce 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -26,6 +26,7 @@ #endif #include "Messenger.h" +#include "network.h" #include "util.h" #define MIN(a,b) (((a)<(b))?(a):(b)) @@ -1388,6 +1389,21 @@ void doMessenger(Messenger *m) #endif } +/* + * Waits for something to happen on the socket for up to milliseconds milliseconds + * *** Function MUSTN'T poll. *** + * The function mustn't modify anything at all, so it can be called completely + * asynchronously without any worry. + * + * returns 0 if the timeout was reached + * returns 1 if there is socket activity (i.e. tox_do() should be called) + * + */ +int waitMessenger(Messenger *m, uint16_t milliseconds) +{ + return networking_wait(m->net, milliseconds); +}; + /* return size of the messenger data (for saving) */ uint32_t Messenger_size_old(Messenger *m) { -- cgit v1.2.3