diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -26,8 +26,10 @@ // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR // OTHER DEALINGS IN THE SOFTWARE. -#include <openssl/ssl.h> +#include <gnutls/gnutls.h> #include <string.h> +#include <stdlib.h> +#include <stdio.h> #include "network.h" #include "config.h" @@ -41,10 +43,20 @@ int main(void) { struct string full_msg = {malloc(0), 0}; while (1) { uint8_t data[512]; - uint64_t new_len = SSL_read(ssl, data, 512); + uint64_t new_len; + { + int len; + do { + len = gnutls_record_recv(session, data, 512); + } while (len == GNUTLS_E_AGAIN || len == GNUTLS_E_INTERRUPTED); + if (len < 0) + new_len = 0; + else + new_len = len; + } if (new_len == 0) { - puts("Disconnected."); + WRITES(1, STRING("Disconnected.\n")); return 0; } @@ -60,7 +72,7 @@ int main(void) { void *tmp = realloc(full_msg.data, full_msg.len+new_len); if (tmp == 0 && full_msg.len+new_len != 0) { - puts("OOM... currently just exiting bc there's no automatic reconnect in here yet, and the only sane solution to this is resyncing."); + WRITES(2, STRING("OOM... currently just exiting bc there's no automatic reconnect in here yet, and the only sane solution to this is resyncing.\n")); return 1; } full_msg.data = tmp; |