|
23 | 23 | #define CLOUDSYNC_NETWORK_MINBUF_SIZE 512 |
24 | 24 | #define CLOUDSYNC_SESSION_TOKEN_MAXSIZE 4096 |
25 | 25 |
|
| 26 | +#define DEFAULT_SYNC_WAIT_MS 100 |
| 27 | +#define DEFAULT_SYNC_MAX_RETRIES 3 |
| 28 | + |
26 | 29 | #define CLOUDSYNC_NETWORK_OK 1 |
27 | 30 | #define CLOUDSYNC_NETWORK_ERROR 2 |
28 | 31 | #define CLOUDSYNC_NETWORK_BUFFER 3 |
@@ -627,7 +630,7 @@ void cloudsync_network_send_changes (sqlite3_context *context, int argc, sqlite3 |
627 | 630 | if (res.buffer) cloudsync_memory_free(res.buffer); |
628 | 631 | } |
629 | 632 |
|
630 | | -int cloudsync_network_check_internal(sqlite3_context *context, int argc, sqlite3_value **argv) { |
| 633 | +int cloudsync_network_check_internal(sqlite3_context *context) { |
631 | 634 | network_data *data = (network_data *)cloudsync_get_auxdata(context); |
632 | 635 | if (!data) {sqlite3_result_error(context, "Unable to retrieve CloudSync context.", -1); return -1;} |
633 | 636 |
|
@@ -655,27 +658,39 @@ int cloudsync_network_check_internal(sqlite3_context *context, int argc, sqlite3 |
655 | 658 | return rc; |
656 | 659 | } |
657 | 660 |
|
658 | | -void cloudsync_network_check_changes_sync (sqlite3_context *context, int argc, sqlite3_value **argv) { |
659 | | - DEBUG_FUNCTION("cloudsync_network_check_changes_sync"); |
660 | | - |
661 | | - int sleep_ms = sqlite3_value_int(argv[0]); |
662 | | - int max_retries = sqlite3_value_int(argv[1]); |
663 | | - |
664 | | - int nrows = 0; |
| 661 | +void cloudsync_network_sync (sqlite3_context *context, int wait_ms, int max_retries) { |
| 662 | + cloudsync_network_send_changes(context, 0, NULL); |
| 663 | + |
665 | 664 | int retries = 0; |
666 | 665 | while (retries < max_retries) { |
667 | | - nrows = cloudsync_network_check_internal(context, argc, argv); |
| 666 | + int nrows = cloudsync_network_check_internal(context); |
668 | 667 | if (nrows > 0) break; |
669 | | - else sqlite3_sleep(sleep_ms); |
| 668 | + else sqlite3_sleep(wait_ms); |
670 | 669 | retries++; |
671 | 670 | } |
672 | 671 | } |
673 | 672 |
|
| 673 | +void cloudsync_network_sync0 (sqlite3_context *context, int argc, sqlite3_value **argv) { |
| 674 | + DEBUG_FUNCTION("cloudsync_network_sync2"); |
| 675 | + |
| 676 | + cloudsync_network_sync(context, DEFAULT_SYNC_WAIT_MS, DEFAULT_SYNC_MAX_RETRIES); |
| 677 | +} |
| 678 | + |
| 679 | + |
| 680 | +void cloudsync_network_sync2 (sqlite3_context *context, int argc, sqlite3_value **argv) { |
| 681 | + DEBUG_FUNCTION("cloudsync_network_sync2"); |
| 682 | + |
| 683 | + int wait_ms = sqlite3_value_int(argv[0]); |
| 684 | + int max_retries = sqlite3_value_int(argv[1]); |
| 685 | + |
| 686 | + cloudsync_network_sync(context, wait_ms, max_retries); |
| 687 | +} |
| 688 | + |
674 | 689 |
|
675 | 690 | void cloudsync_network_check_changes (sqlite3_context *context, int argc, sqlite3_value **argv) { |
676 | 691 | DEBUG_FUNCTION("cloudsync_network_check_changes"); |
677 | 692 |
|
678 | | - cloudsync_network_check_internal(context, argc, argv); |
| 693 | + cloudsync_network_check_internal(context); |
679 | 694 | } |
680 | 695 |
|
681 | 696 | void cloudsync_network_reset_check_version (sqlite3_context *context, int argc, sqlite3_value **argv) { |
@@ -710,7 +725,10 @@ int cloudsync_network_register (sqlite3 *db, char **pzErrMsg, void *ctx) { |
710 | 725 | rc = dbutils_register_function(db, "cloudsync_network_check_changes", cloudsync_network_check_changes, 0, pzErrMsg, ctx, NULL); |
711 | 726 | if (rc != SQLITE_OK) return rc; |
712 | 727 |
|
713 | | - rc = dbutils_register_function(db, "cloudsync_network_check_changes_sync", cloudsync_network_check_changes_sync, 2, pzErrMsg, ctx, NULL); |
| 728 | + rc = dbutils_register_function(db, "cloudsync_network_sync", cloudsync_network_sync0, 0, pzErrMsg, ctx, NULL); |
| 729 | + if (rc != SQLITE_OK) return rc; |
| 730 | + |
| 731 | + rc = dbutils_register_function(db, "cloudsync_network_sync", cloudsync_network_sync2, 2, pzErrMsg, ctx, NULL); |
714 | 732 | if (rc != SQLITE_OK) return rc; |
715 | 733 |
|
716 | 734 | rc = dbutils_register_function(db, "cloudsync_network_reset_check_version", cloudsync_network_reset_check_version, 0, pzErrMsg, ctx, NULL); |
|
0 commit comments