diff options
author | irungentoo <irungentoo@gmail.com> | 2014-05-30 13:20:36 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2014-05-30 13:20:36 -0400 |
commit | 0e814904e4494705c82e8ef30b7b0cc090ea617e (patch) | |
tree | 147e653b1a2251daaff4f64ae1105f964f437964 | |
parent | 6b152d2bac5e7512ee748b906d96c94f2d0e7bc7 (diff) |
Replaced tox_wait* functions with tox_do_run_interval().
Build system fixes.
-rw-r--r-- | libtoxcore.pc.in | 2 | ||||
-rw-r--r-- | testing/Makefile.inc | 6 | ||||
-rw-r--r-- | testing/nTox.c | 14 | ||||
-rw-r--r-- | toxcore/tox.c | 10 | ||||
-rw-r--r-- | toxcore/tox.h | 45 |
5 files changed, 24 insertions, 53 deletions
diff --git a/libtoxcore.pc.in b/libtoxcore.pc.in index 57d3f8ef..e05e51cd 100644 --- a/libtoxcore.pc.in +++ b/libtoxcore.pc.in | |||
@@ -7,5 +7,5 @@ Name: libtoxcore | |||
7 | Description: Tox protocol library | 7 | Description: Tox protocol library |
8 | Requires: | 8 | Requires: |
9 | Version: @PACKAGE_VERSION@ | 9 | Version: @PACKAGE_VERSION@ |
10 | Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} @NACL_LDFLAGS@ -ltoxcore @NACL_LIBS@ @LIBS@ | 10 | Libs: @NACL_OBJECTS_PKGCONFIG@ -L${libdir} @NACL_LDFLAGS@ -ltoxcore @NACL_LIBS@ @LIBS@ @MATH_LDFLAGS@ |
11 | Cflags: -I${includedir} | 11 | Cflags: -I${includedir} |
diff --git a/testing/Makefile.inc b/testing/Makefile.inc index b3912033..ab452a94 100644 --- a/testing/Makefile.inc +++ b/testing/Makefile.inc | |||
@@ -10,10 +10,12 @@ nTox_CFLAGS = $(LIBSODIUM_CFLAGS) \ | |||
10 | $(NCURSES_CFLAGS) | 10 | $(NCURSES_CFLAGS) |
11 | 11 | ||
12 | nTox_LDADD = $(LIBSODIUM_LDFLAGS) \ | 12 | nTox_LDADD = $(LIBSODIUM_LDFLAGS) \ |
13 | $(NAC_LDFLAGS) \ | 13 | $(NAC_LDFLAGS) \ |
14 | libtoxcore.la \ | 14 | libtoxcore.la \ |
15 | $(LIBSODIUM_LIBS) \ | 15 | $(LIBSODIUM_LIBS) \ |
16 | $(NACL_OBJECTS) \ | ||
16 | $(NACL_LIBS) \ | 17 | $(NACL_LIBS) \ |
18 | $(MATH_LDFLAGS) \ | ||
17 | $(NCURSES_LIBS) \ | 19 | $(NCURSES_LIBS) \ |
18 | $(WINSOCK2_LIBS) | 20 | $(WINSOCK2_LIBS) |
19 | endif | 21 | endif |
@@ -51,6 +53,7 @@ Messenger_test_LDADD = $(LIBSODIUM_LDFLAGS) \ | |||
51 | $(LIBSODIUM_LIBS) \ | 53 | $(LIBSODIUM_LIBS) \ |
52 | $(NACL_OBJECTS) \ | 54 | $(NACL_OBJECTS) \ |
53 | $(NACL_LIBS) \ | 55 | $(NACL_LIBS) \ |
56 | $(MATH_LDFLAGS) \ | ||
54 | $(WINSOCK2_LIBS) | 57 | $(WINSOCK2_LIBS) |
55 | 58 | ||
56 | 59 | ||
@@ -85,6 +88,7 @@ tox_sync_LDADD = $(LIBSODIUM_LDFLAGS) \ | |||
85 | $(LIBSODIUM_LIBS) \ | 88 | $(LIBSODIUM_LIBS) \ |
86 | $(NACL_OBJECTS) \ | 89 | $(NACL_OBJECTS) \ |
87 | $(NACL_LIBS) \ | 90 | $(NACL_LIBS) \ |
91 | $(MATH_LDFLAGS) \ | ||
88 | $(WINSOCK2_LIBS) | 92 | $(WINSOCK2_LIBS) |
89 | endif | 93 | endif |
90 | 94 | ||
diff --git a/testing/nTox.c b/testing/nTox.c index 7af3124d..83561716 100644 --- a/testing/nTox.c +++ b/testing/nTox.c | |||
@@ -542,6 +542,7 @@ void line_eval(Tox *m, char *line) | |||
542 | } else if (inpt_command == 'q') { //exit | 542 | } else if (inpt_command == 'q') { //exit |
543 | save_data(m); | 543 | save_data(m); |
544 | endwin(); | 544 | endwin(); |
545 | tox_kill(m); | ||
545 | exit(EXIT_SUCCESS); | 546 | exit(EXIT_SUCCESS); |
546 | } else if (inpt_command == 'c') { //set conversation partner | 547 | } else if (inpt_command == 'c') { //set conversation partner |
547 | if (line[2] == 'r') { | 548 | if (line[2] == 'r') { |
@@ -1274,17 +1275,8 @@ int main(int argc, char *argv[]) | |||
1274 | } | 1275 | } |
1275 | } | 1276 | } |
1276 | 1277 | ||
1277 | if (numfilesenders > 0) | 1278 | |
1278 | // during file transfer wasting cpu cycles is almost unavoidable | 1279 | c_sleep(tox_do_run_interval(m)); |
1279 | c_sleep(1); | ||
1280 | else { | ||
1281 | if (pollok && (tox_wait_prepare(m, data) == 1)) { | ||
1282 | /* 250ms is more than fast enough in "regular" mode */ | ||
1283 | tox_wait_execute(data, 0, 100000); | ||
1284 | tox_wait_cleanup(m, data); | ||
1285 | } else | ||
1286 | c_sleep(25); | ||
1287 | } | ||
1288 | 1280 | ||
1289 | send_filesenders(m); | 1281 | send_filesenders(m); |
1290 | tox_do(m); | 1282 | tox_do(m); |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 884223ff..f9df7860 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -782,6 +782,16 @@ int tox_isconnected(Tox *tox) | |||
782 | return DHT_isconnected(m->dht); | 782 | return DHT_isconnected(m->dht); |
783 | } | 783 | } |
784 | 784 | ||
785 | /* Return the optimal interval in milliseconds between tox_do() calls. | ||
786 | * This function should be called after every tox_do() call for best performance. | ||
787 | */ | ||
788 | uint32_t tox_do_run_interval(Tox *tox) | ||
789 | { | ||
790 | Messenger *m = tox; | ||
791 | //TODO | ||
792 | return 10; | ||
793 | } | ||
794 | |||
785 | /* Run this at startup. | 795 | /* Run this at startup. |
786 | * | 796 | * |
787 | * return allocated instance of tox on success. | 797 | * return allocated instance of tox on success. |
diff --git a/toxcore/tox.h b/toxcore/tox.h index f54d113e..e2207336 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -644,48 +644,13 @@ Tox *tox_new(uint8_t ipv6enabled); | |||
644 | * Free all datastructures. */ | 644 | * Free all datastructures. */ |
645 | void tox_kill(Tox *tox); | 645 | void tox_kill(Tox *tox); |
646 | 646 | ||
647 | /* The main loop that needs to be run at least 20 times per second. */ | 647 | /* Return the optimal interval in milliseconds between tox_do() calls. |
648 | void tox_do(Tox *tox); | 648 | * This function should be called after every tox_do() call for best performance. |
649 | |||
650 | /* | ||
651 | * tox_wait_data_size(): | ||
652 | * | ||
653 | * returns a size of data buffer to allocate. the size is constant. | ||
654 | * | ||
655 | * tox_wait_prepare(): function should be called under lock every time we want to call tox_wait_execute() | ||
656 | * Prepares the data required to call tox_wait_execute() asynchronously | ||
657 | * | ||
658 | * data[] should be of at least tox_wait_data_size() size and it's reserved and kept by the caller | ||
659 | * Use that data[] to call tox_wait_execute() | ||
660 | * | ||
661 | * returns 1 on success | ||
662 | * returns 0 if data was NULL | ||
663 | * | ||
664 | * | ||
665 | * tox_wait_execute(): function can be called asynchronously | ||
666 | * Waits for something to happen on the socket for up to seconds seconds and mircoseconds microseconds. | ||
667 | * mircoseconds should be between 0 and 999999. | ||
668 | * If you set either or both seconds and microseconds to negatives, it will block indefinetly until there | ||
669 | * is an activity. | ||
670 | * | ||
671 | * returns 2 if there is socket activity (i.e. tox_do() should be called) | ||
672 | * returns 1 if the timeout was reached (tox_do() should be called anyway. it's advised to call it at least | ||
673 | * once per second) | ||
674 | * returns 0 if data was NULL | ||
675 | * | ||
676 | * | ||
677 | * tox_wait_cleanup(): function should be called under lock, every time tox_wait_execute() finishes | ||
678 | * Stores results from tox_wait_execute(). | ||
679 | * | ||
680 | * returns 1 on success | ||
681 | * returns 0 if data was NULL | ||
682 | * | ||
683 | */ | 649 | */ |
684 | size_t tox_wait_data_size(); | 650 | uint32_t tox_do_run_interval(Tox *tox); |
685 | int tox_wait_prepare(Tox *tox, uint8_t *data); | ||
686 | int tox_wait_execute(uint8_t *data, long seconds, long microseconds); | ||
687 | int tox_wait_cleanup(Tox *tox, uint8_t *data); | ||
688 | 651 | ||
652 | /* The main loop that needs to be run in intervals of tox_do_run_interval() ms. */ | ||
653 | void tox_do(Tox *tox); | ||
689 | 654 | ||
690 | /* SAVING AND LOADING FUNCTIONS: */ | 655 | /* SAVING AND LOADING FUNCTIONS: */ |
691 | 656 | ||